Bug 1521836 - Add component refinement, context sources and bug fixes to Activity Stream r=k88hudson
Differential Revision: https://phabricator.services.mozilla.com/D17328
This commit is contained in:
@@ -14,17 +14,25 @@ export const selectLayoutRender = createSelector(
|
||||
function layoutRender(layout, feeds, spocs) {
|
||||
let spocIndex = 0;
|
||||
|
||||
function calculateSpocs(component) {
|
||||
return component.spocs.positions.map(position => {
|
||||
const rickRoll = Math.random();
|
||||
if (spocs.data.spocs[spocIndex] && rickRoll <= component.spocs.probability) {
|
||||
return {
|
||||
...position,
|
||||
result: spocs.data.spocs[spocIndex++],
|
||||
};
|
||||
function maybeInjectSpocs(data, spocsConfig) {
|
||||
if (data &&
|
||||
spocsConfig && spocsConfig.positions && spocsConfig.positions.length &&
|
||||
spocs.data.spocs && spocs.data.spocs.length) {
|
||||
const recommendations = [...data.recommendations];
|
||||
for (let position of spocsConfig.positions) {
|
||||
let rickRoll = Math.random();
|
||||
if (spocs.data.spocs[spocIndex] && rickRoll <= spocsConfig.probability) {
|
||||
recommendations.splice(position.index, 0, spocs.data.spocs[spocIndex++]);
|
||||
}
|
||||
}
|
||||
return position;
|
||||
});
|
||||
|
||||
return {
|
||||
...data,
|
||||
recommendations,
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
return layout.map(row => ({
|
||||
@@ -37,15 +45,7 @@ export const selectLayoutRender = createSelector(
|
||||
return component;
|
||||
}
|
||||
|
||||
// Calculate if we should display a spoc or not.
|
||||
if (component.spocs && spocs.data.spocs && spocs.data.spocs.length) {
|
||||
component.spocs = {
|
||||
...component.spocs,
|
||||
positions: calculateSpocs(component),
|
||||
};
|
||||
}
|
||||
|
||||
return {...component, data: feeds[component.feed.url].data};
|
||||
return {...component, data: maybeInjectSpocs(feeds[component.feed.url].data, component.spocs)};
|
||||
}),
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user