Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine personalization display notifications together #1025

Closed
wants to merge 12 commits into from
Closed
1 change: 1 addition & 0 deletions rollup.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if (argv.reporters && argv.reporters.split(",").includes("coverage")) {

module.exports = {
output: {
sourcemap: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes debugging tests a lot easier. I'm not sure why we didn't have it included before.

format: "iife",
// Allow non-IE browsers and IE11
// document.documentMode was added in IE8, and is specific to IE.
Expand Down
28 changes: 13 additions & 15 deletions src/components/Personalization/createApplyPropositions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import composePersonalizationResultingObject from "./utils/composePersonalizationResultingObject";
import { isNonEmptyArray, isObject } from "../../utils";
import { DOM_ACTION, HTML_CONTENT_ITEM } from "./constants/schema";
import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
import { EMPTY_PROPOSITIONS } from "./validateApplyPropositionsOptions";
import {
buildReturnedPropositions,
createProposition
} from "./handlers/proposition";

export const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];
const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];

export default ({ executeDecisions }) => {
export default ({ render }) => {
const filterItemsPredicate = item =>
SUPPORTED_SCHEMAS.indexOf(item.schema) > -1;

Expand Down Expand Up @@ -71,20 +73,16 @@ export default ({ executeDecisions }) => {
.filter(proposition => isNonEmptyArray(proposition.items));
};

const applyPropositions = ({ propositions, metadata }) => {
return ({ propositions, metadata = {} }) => {
const propositionsToExecute = preparePropositions({
propositions,
metadata
});
return executeDecisions(propositionsToExecute).then(() => {
return composePersonalizationResultingObject(propositionsToExecute, true);
});
};
}).map(proposition => createProposition(proposition, true));

return ({ propositions, metadata = {} }) => {
if (isNonEmptyArray(propositions)) {
return applyPropositions({ propositions, metadata });
}
return Promise.resolve(EMPTY_PROPOSITIONS);
render(propositionsToExecute);

return {
propositions: buildReturnedPropositions(propositionsToExecute)
};
};
};
77 changes: 0 additions & 77 deletions src/components/Personalization/createAutoRenderingHandler.js

This file was deleted.

13 changes: 7 additions & 6 deletions src/components/Personalization/createComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import { noop, defer } from "../../utils";
import { noop } from "../../utils";
import createPersonalizationDetails from "./createPersonalizationDetails";
import { AUTHORING_ENABLED } from "./constants/loggerMessage";
import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions";
Expand Down Expand Up @@ -60,17 +60,18 @@ export default ({
decisionScopes,
personalization,
event,
viewCache,
isCacheInitialized: viewCache.isInitialized(),
logger
});

if (personalizationDetails.shouldFetchData()) {
const decisionsDeferred = defer();
const cacheUpdate = viewCache.createCacheUpdate(
personalizationDetails.getViewName()
);
onRequestFailure(() => cacheUpdate.cancel());

viewCache.storeViews(decisionsDeferred.promise);
onRequestFailure(() => decisionsDeferred.reject());
fetchDataHandler({
decisionsDeferred,
cacheUpdate,
personalizationDetails,
event,
onResponse
Expand Down
82 changes: 0 additions & 82 deletions src/components/Personalization/createExecuteDecisions.js

This file was deleted.

39 changes: 32 additions & 7 deletions src/components/Personalization/createFetchDataHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Adobe. All rights reserved.
Copyright 2023 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -9,21 +9,46 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import {
buildReturnedPropositions,
buildReturnedDecisions
} from "./handlers/proposition";

const DECISIONS_HANDLE = "personalization:decisions";

export default ({
prehidingStyle,
responseHandler,
showContainers,
hideContainers,
mergeQuery
mergeQuery,
collect,
render
}) => {
return ({ decisionsDeferred, personalizationDetails, event, onResponse }) => {
return ({ cacheUpdate, personalizationDetails, event, onResponse }) => {
if (personalizationDetails.isRenderDecisions()) {
hideContainers(prehidingStyle);
}
mergeQuery(event, personalizationDetails.createQueryDetails());

onResponse(({ response }) =>
responseHandler({ decisionsDeferred, personalizationDetails, response })
);
onResponse(({ response }) => {
const handles = response.getPayloadsByType(DECISIONS_HANDLE);
const propositions = cacheUpdate.update(handles);
if (personalizationDetails.isRenderDecisions()) {
render(propositions).then(decisionsMeta => {
showContainers();
if (decisionsMeta.length > 0) {
collect({
decisionsMeta,
viewName: personalizationDetails.getViewName()
});
}
});
}

return {
propositions: buildReturnedPropositions(propositions),
decisions: buildReturnedDecisions(propositions)
};
});
};
};
54 changes: 0 additions & 54 deletions src/components/Personalization/createNonRenderingHandler.js

This file was deleted.

Loading