Skip to content

Commit

Permalink
馃悰 Move ampDoc references into amp-story buildCallback (ampproject#30986)
Browse files Browse the repository at this point in the history
* Move methods that need ampdoc to buildCallback.

* Update types.

* Remove const

* Fix typo.

* devAssert.
  • Loading branch information
processprocess authored and ed-bird committed Dec 10, 2020
1 parent 23e59be commit af710cd
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions extensions/amp-story/1.0/amp-story.js
Expand Up @@ -327,13 +327,14 @@ export class AmpStory extends AMP.BaseElement {
/** @private @const {!../../../src/service/platform-impl.Platform} */
this.platform_ = Services.platformFor(this.win);

/** @private @const {!../../../src/service/viewer-interface.ViewerInterface} */
this.viewer_ = Services.viewerForDoc(this.element);
/** @private {?../../../src/service/viewer-interface.ViewerInterface} */
this.viewer_ = null;

/** @private @const {?AmpStoryViewerMessagingHandler} */
this.viewerMessagingHandler_ = this.viewer_.isEmbedded()
? new AmpStoryViewerMessagingHandler(this.win, this.viewer_)
: null;
/** @private {?AmpStoryViewerMessagingHandler} */
this.viewerMessagingHandler_ = null;

/** @private {?../../../src/service/localization.LocalizationService} */
this.localizationService_ = null;

/**
* Store the current paused state, to make sure the story does not play on
Expand All @@ -353,8 +354,16 @@ export class AmpStory extends AMP.BaseElement {

/** @private {?LiveStoryManager} */
this.liveStoryManager_ = null;
}

/** @override */
buildCallback() {
this.viewer_ = Services.viewerForDoc(this.element);

this.viewerMessagingHandler_ = this.viewer_.isEmbedded()
? new AmpStoryViewerMessagingHandler(this.win, this.viewer_)
: null;

/** @private @const {!../../../src/service/localization.LocalizationService} */
this.localizationService_ = getLocalizationService(this.element);

this.localizationService_
Expand Down Expand Up @@ -389,10 +398,7 @@ export class AmpStory extends AMP.BaseElement {
'en-xa',
enXaPseudoLocaleBundle
);
}

/** @override */
buildCallback() {
if (this.isStandalone_()) {
this.initializeStandaloneStory_();
}
Expand Down Expand Up @@ -1003,7 +1009,7 @@ export class AmpStory extends AMP.BaseElement {
// Preloads and prerenders the share menu.
this.shareMenu_.build();

const infoDialog = shouldShowStoryUrlInfo(this.viewer_)
const infoDialog = shouldShowStoryUrlInfo(devAssert(this.viewer_))
? new InfoDialog(this.win, this.element)
: null;
if (infoDialog) {
Expand Down

0 comments on commit af710cd

Please sign in to comment.