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

Rename fetch flags #1063

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/DataCollector/validateApplyResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default ({ options }) => {
).required()
}).required(),
personalization: objectOf({
sendDisplayNotifications: boolean().default(true)
}).default({ sendDisplayNotifications: true })
sendDisplayEvent: boolean().default(true)
}).default({ sendDisplayEvent: true })
}).noUnknownFields();

return validator(options);
Expand Down
6 changes: 3 additions & 3 deletions src/components/DataCollector/validateUserEventOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export default ({ options }) => {
personalization: objectOf({
decisionScopes: arrayOf(string()).uniqueItems(),
surfaces: arrayOf(string()).uniqueItems(),
sendDisplayNotifications: boolean().default(true),
includePendingDisplayNotifications: boolean().default(false)
}).default({ sendDisplayNotifications: true }),
sendDisplayEvent: boolean().default(true),
includeRenderedPropositions: boolean().default(false)
}).default({ sendDisplayEvent: true }),
datasetId: string(),
mergeId: string(),
edgeConfigOverrides: validateConfigOverride
Expand Down
8 changes: 4 additions & 4 deletions src/components/Personalization/createApplyPropositions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];
export default ({
processPropositions,
createProposition,
pendingDisplayNotifications,
renderedPropositions,
viewCache
}) => {
const filterItemsPredicate = item =>
Expand Down Expand Up @@ -77,8 +77,8 @@ export default ({
return ({ propositions = [], metadata = {}, viewName }) => {
// We need to immediately call concat so that subsequent sendEvent
// calls will wait for applyPropositions to complete before executing.
const displayNotificationsDeferred = defer();
pendingDisplayNotifications.concat(displayNotificationsDeferred.promise);
const renderedPropositionsDeferred = defer();
renderedPropositions.concat(renderedPropositionsDeferred.promise);

const propositionsToExecute = preparePropositions({
propositions,
Expand All @@ -98,7 +98,7 @@ export default ({
...additionalPropositions
]);

render().then(displayNotificationsDeferred.resolve);
render().then(renderedPropositionsDeferred.resolve);

return {
propositions: returnedPropositions
Expand Down
6 changes: 3 additions & 3 deletions src/components/Personalization/createComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default ({
applyPropositions,
setTargetMigration,
mergeDecisionsMeta,
pendingDisplayNotifications
renderedPropositions
}) => {
return {
lifecycle: {
Expand Down Expand Up @@ -68,8 +68,8 @@ export default ({
});

const decisionsMetaPromises = [];
if (personalizationDetails.shouldAddPendingDisplayNotifications()) {
decisionsMetaPromises.push(pendingDisplayNotifications.clear());
if (personalizationDetails.shouldIncludeRenderedPropositions()) {
decisionsMetaPromises.push(renderedPropositions.clear());
}

if (personalizationDetails.shouldFetchData()) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/Personalization/createFetchDataHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default ({
collect,
processPropositions,
createProposition,
pendingDisplayNotifications
renderedPropositions
}) => {
return ({ cacheUpdate, personalizationDetails, event, onResponse }) => {
if (personalizationDetails.isRenderDecisions()) {
Expand All @@ -32,7 +32,7 @@ export default ({
mergeQuery(event, personalizationDetails.createQueryDetails());

let handleNotifications;
if (personalizationDetails.isSendDisplayNotifications()) {
if (personalizationDetails.isSendDisplayEvent()) {
handleNotifications = decisionsMeta => {
if (decisionsMeta.length > 0) {
collect({
Expand All @@ -42,9 +42,9 @@ export default ({
}
};
} else {
const displayNotificationsDeferred = defer();
pendingDisplayNotifications.concat(displayNotificationsDeferred.promise);
handleNotifications = displayNotificationsDeferred.resolve;
const renderedPropositionsDeferred = defer();
renderedPropositions.concat(renderedPropositionsDeferred.promise);
handleNotifications = renderedPropositionsDeferred.resolve;
}

onResponse(({ response }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export default ({
isRenderDecisions() {
return renderDecisions;
},
isSendDisplayNotifications() {
return !!personalization.sendDisplayNotifications;
isSendDisplayEvent() {
return !!personalization.sendDisplayEvent;
},
shouldAddPendingDisplayNotifications() {
return !!personalization.includePendingDisplayNotifications;
shouldIncludeRenderedPropositions() {
return !!personalization.includeRenderedPropositions;
},
getViewName() {
return viewName;
Expand Down
8 changes: 4 additions & 4 deletions src/components/Personalization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const createPersonalization = ({ config, logger, eventManager }) => {
logger
});

const pendingDisplayNotifications = createAsyncArray();
const renderedPropositions = createAsyncArray();
const fetchDataHandler = createFetchDataHandler({
prehidingStyle,
showContainers,
Expand All @@ -89,7 +89,7 @@ const createPersonalization = ({ config, logger, eventManager }) => {
collect,
processPropositions,
createProposition,
pendingDisplayNotifications
renderedPropositions
});
const onClickHandler = createOnClickHandler({
mergeDecisionsMeta,
Expand All @@ -104,7 +104,7 @@ const createPersonalization = ({ config, logger, eventManager }) => {
const applyPropositions = createApplyPropositions({
processPropositions,
createProposition,
pendingDisplayNotifications,
renderedPropositions,
viewCache
});
const setTargetMigration = createSetTargetMigration({
Expand All @@ -123,7 +123,7 @@ const createPersonalization = ({ config, logger, eventManager }) => {
applyPropositions,
setTargetMigration,
mergeDecisionsMeta,
pendingDisplayNotifications
renderedPropositions
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const METADATA = {
describe("Personalization::createApplyPropositions", () => {
let processPropositions;
let createProposition;
let pendingDisplayNotifications;
let renderedPropositions;
let viewCache;
let applyPropositions;
let render;
Expand All @@ -49,16 +49,15 @@ describe("Personalization::createApplyPropositions", () => {
isPageWideSurface: () => false
});

pendingDisplayNotifications = jasmine.createSpyObj(
"pendingDisplayNotifications",
["concat"]
);
renderedPropositions = jasmine.createSpyObj("renderedPropositions", [
"concat"
]);
viewCache = jasmine.createSpyObj("viewCache", ["getView"]);
viewCache.getView.and.returnValue(Promise.resolve([]));
applyPropositions = createApplyPropositions({
processPropositions,
createProposition,
pendingDisplayNotifications,
renderedPropositions,
viewCache
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Personalization", () => {
let personalizationComponent;
let setTargetMigration;
let mergeDecisionsMeta;
let pendingDisplayNotifications;
let renderedPropositions;
let cacheUpdate;

const build = () => {
Expand All @@ -40,7 +40,7 @@ describe("Personalization", () => {
showContainers,
setTargetMigration,
mergeDecisionsMeta,
pendingDisplayNotifications
renderedPropositions
});
};

Expand All @@ -67,10 +67,9 @@ describe("Personalization", () => {
viewCache.createCacheUpdate.and.returnValue(cacheUpdate);
setTargetMigration = jasmine.createSpy("setTargetMigration");
mergeDecisionsMeta = jasmine.createSpy("mergeDecisionsMeta");
pendingDisplayNotifications = jasmine.createSpyObj(
"pendingDisplayNotifications",
["clear"]
);
renderedPropositions = jasmine.createSpyObj("renderedPropositions", [
"clear"
]);

build();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("Personalization::createFetchDataHandler", () => {
let collect;
let processPropositions;
let createProposition;
let pendingDisplayNotifications;
let renderedPropositions;

let cacheUpdate;
let personalizationDetails;
Expand All @@ -43,20 +43,19 @@ describe("Personalization::createFetchDataHandler", () => {
preprocess: data => data,
isPageWideSurface: () => false
});
pendingDisplayNotifications = jasmine.createSpyObj(
"pendingDisplayNotifications",
["concat"]
);
renderedPropositions = jasmine.createSpyObj("renderedPropositions", [
"concat"
]);

cacheUpdate = jasmine.createSpyObj("cacheUpdate", ["update"]);
personalizationDetails = jasmine.createSpyObj("personalizationDetails", [
"isRenderDecisions",
"createQueryDetails",
"getViewName",
"isSendDisplayNotifications"
"isSendDisplayEvent"
]);
personalizationDetails.createQueryDetails.and.returnValue("myquerydetails");
personalizationDetails.isSendDisplayNotifications.and.returnValue(true);
personalizationDetails.isSendDisplayEvent.and.returnValue(true);
event = "myevent";
onResponse = jasmine.createSpy();
response = jasmine.createSpyObj("response", ["getPayloadsByType"]);
Expand All @@ -71,7 +70,7 @@ describe("Personalization::createFetchDataHandler", () => {
collect,
processPropositions,
createProposition,
pendingDisplayNotifications
renderedPropositions
});
fetchDataHandler({
cacheUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const buildComponent = ({
logger
});

const pendingDisplayNotifications = createAsyncArray();
const renderedPropositions = createAsyncArray();
const fetchDataHandler = createFetchDataHandler({
prehidingStyle,
showContainers,
Expand All @@ -122,7 +122,7 @@ const buildComponent = ({
collect,
processPropositions,
createProposition,
pendingDisplayNotifications
renderedPropositions
});
const onClickHandler = createOnClickHandler({
mergeDecisionsMeta,
Expand All @@ -137,7 +137,7 @@ const buildComponent = ({
const applyPropositions = createApplyPropositions({
processPropositions,
createProposition,
pendingDisplayNotifications,
renderedPropositions,
viewCache
});
const setTargetMigration = createSetTargetMigration({
Expand All @@ -156,7 +156,7 @@ const buildComponent = ({
applyPropositions,
setTargetMigration,
mergeDecisionsMeta,
pendingDisplayNotifications
renderedPropositions
});
};

Expand All @@ -179,7 +179,7 @@ export default mocks => {
event,
renderDecisions,
decisionScopes,
personalization: personalization || { sendDisplayNotifications: true },
personalization: personalization || { sendDisplayEvent: true },
onResponse: callbacks.add
});
const results = await callbacks.call({ response });
Expand Down
Loading