fix(sections): Section option pref change should re-initialize feeds
This commit is contained in:
Родитель
302a419fa8
Коммит
9bbf3b5ba7
|
@ -59,6 +59,7 @@ for (const type of [
|
|||
"SECTION_DEREGISTER",
|
||||
"SECTION_DISABLE",
|
||||
"SECTION_ENABLE",
|
||||
"SECTION_OPTIONS_CHANGED",
|
||||
"SECTION_REGISTER",
|
||||
"SECTION_UPDATE",
|
||||
"SECTION_UPDATE_CARD",
|
||||
|
|
|
@ -278,11 +278,16 @@ class SectionsFeed {
|
|||
case at.PREFS_INITIAL_VALUES:
|
||||
SectionsManager.init(action.data);
|
||||
break;
|
||||
case at.PREF_CHANGED:
|
||||
if (action.data && action.data.name.match(/^feeds.section.(\S+).options$/i)) {
|
||||
SectionsManager.addBuiltInSection(action.data.name.slice(0, -8), action.data.value);
|
||||
case at.PREF_CHANGED: {
|
||||
if (action.data) {
|
||||
const matched = action.data.name.match(/^(feeds.section.(\S+)).options$/i);
|
||||
if (matched) {
|
||||
SectionsManager.addBuiltInSection(matched[1], action.data.value);
|
||||
this.store.dispatch({type: at.SECTION_OPTIONS_CHANGED, data: matched[2]});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case at.SECTION_DISABLE:
|
||||
SectionsManager.disableSection(action.data);
|
||||
break;
|
||||
|
|
|
@ -25,9 +25,6 @@ const SECTION_ID = "topstories";
|
|||
|
||||
this.TopStoriesFeed = class TopStoriesFeed {
|
||||
constructor() {
|
||||
this.storiesLastUpdated = 0;
|
||||
this.topicsLastUpdated = 0;
|
||||
this.affinityLastUpdated = 0;
|
||||
this.spocsPerNewTabs = 0;
|
||||
this.newTabsSinceSpoc = 0;
|
||||
this.contentUpdateQueue = [];
|
||||
|
@ -46,6 +43,9 @@ this.TopStoriesFeed = class TopStoriesFeed {
|
|||
this.personalized = options.personalized;
|
||||
this.show_spocs = options.show_spocs;
|
||||
this.maxHistoryQueryResults = options.maxHistoryQueryResults;
|
||||
this.storiesLastUpdated = 0;
|
||||
this.topicsLastUpdated = 0;
|
||||
this.affinityLastUpdated = 0;
|
||||
|
||||
this.fetchStories();
|
||||
this.fetchTopics();
|
||||
|
@ -272,6 +272,12 @@ this.TopStoriesFeed = class TopStoriesFeed {
|
|||
case at.NEW_TAB_REHYDRATED:
|
||||
this.maybeAddSpoc(action.meta.fromTarget);
|
||||
break;
|
||||
case at.SECTION_OPTIONS_CHANGED:
|
||||
if (action.data === SECTION_ID) {
|
||||
this.uninit();
|
||||
this.init();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -376,6 +376,13 @@ describe("SectionsFeed", () => {
|
|||
assert.calledOnce(SectionsManager.addBuiltInSection);
|
||||
assert.calledWith(SectionsManager.addBuiltInSection, "feeds.section.topstories", "foo");
|
||||
});
|
||||
it("should fire SECTION_OPTIONS_UPDATED on suitable PREF_CHANGED events", () => {
|
||||
feed.onAction({type: "PREF_CHANGED", data: {name: "feeds.section.topstories.options", value: "foo"}});
|
||||
assert.calledOnce(feed.store.dispatch);
|
||||
const action = feed.store.dispatch.firstCall.args[0];
|
||||
assert.equal(action.type, "SECTION_OPTIONS_CHANGED");
|
||||
assert.equal(action.data, "topstories");
|
||||
});
|
||||
it("should call SectionsManager.disableSection on SECTION_DISABLE", () => {
|
||||
sinon.spy(SectionsManager, "disableSection");
|
||||
feed.onAction({type: "SECTION_DISABLE", data: 1234});
|
||||
|
|
|
@ -519,5 +519,24 @@ describe("Top Stories Feed", () => {
|
|||
assert.equal(action.type, at.TELEMETRY_PERFORMANCE_EVENT);
|
||||
assert.equal(action.data.event, "topstories.domain.affinity.calculation.ms");
|
||||
});
|
||||
it("should re-init on options change", () => {
|
||||
instance.storiesLastUpdated = 1;
|
||||
instance.topicsLastUpdated = 1;
|
||||
instance.affinityLastUpdated = 1;
|
||||
|
||||
instance.onAction({type: at.SECTION_OPTIONS_CHANGED, data: "foo"});
|
||||
assert.notCalled(sectionsManagerStub.disableSection);
|
||||
assert.notCalled(sectionsManagerStub.enableSection);
|
||||
assert.equal(instance.storiesLastUpdated, 1);
|
||||
assert.equal(instance.topicsLastUpdated, 1);
|
||||
assert.equal(instance.affinityLastUpdated, 1);
|
||||
|
||||
instance.onAction({type: at.SECTION_OPTIONS_CHANGED, data: "topstories"});
|
||||
assert.calledOnce(sectionsManagerStub.disableSection);
|
||||
assert.calledOnce(sectionsManagerStub.enableSection);
|
||||
assert.equal(instance.storiesLastUpdated, 0);
|
||||
assert.equal(instance.topicsLastUpdated, 0);
|
||||
assert.equal(instance.affinityLastUpdated, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче