Skip to content

Commit f7d720a

Browse files
authored
Store story page IDs from the buildCallback. (ampproject#24764)
* Cache the page ids from the buildCallback. * Creating the story with its pages.
1 parent 9b967ef commit f7d720a

File tree

2 files changed

+108
-114
lines changed

2 files changed

+108
-114
lines changed

extensions/amp-story/1.0/amp-story.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ export class AmpStory extends AMP.BaseElement {
542542
pageEls[i].id = newId;
543543
pageIds[i] = newId;
544544
}
545+
this.storeService_.dispatch(Action.SET_PAGE_IDS, pageIds);
545546
}
546547

547548
/**
@@ -630,18 +631,6 @@ export class AmpStory extends AMP.BaseElement {
630631
*/
631632
buildSystemLayer_(initialPageId) {
632633
this.updateAudioIcon_();
633-
634-
// TODO(gmajoulet): cache the page ids in the store from the
635-
// initializePageIds_ method to remove this block. Requires refactoring in
636-
// test-amp-story to avoid console.errors.
637-
let pageIds;
638-
if (this.pages_.length) {
639-
pageIds = this.pages_.map(page => page.element.id);
640-
} else {
641-
const pages = this.element.querySelectorAll('amp-story-page');
642-
pageIds = Array.prototype.map.call(pages, el => el.id);
643-
}
644-
this.storeService_.dispatch(Action.SET_PAGE_IDS, pageIds);
645634
this.element.appendChild(this.systemLayer_.build(initialPageId));
646635
}
647636

0 commit comments

Comments
 (0)