Skip to content

Commit

Permalink
Remove access of ampdoc in AmpLinkRewriter's constructor. (ampproject…
Browse files Browse the repository at this point in the history
  • Loading branch information
lannka authored Nov 2, 2019
1 parent 1c03e8f commit 9d75c26
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions extensions/amp-link-rewriter/0.1/amp-link-rewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,22 @@ export class AmpLinkRewriter extends AMP.BaseElement {
constructor(element) {
super(element);

/** @private {!../../../src/service/ampdoc-impl.AmpDoc} */
this.ampDoc_ = this.getAmpDoc();

/** @private {?./link-rewriter.LinkRewriter} */
this.rewriter_ = null;

/** @private {string} */
this.referrer_ = '';

this.navigation_ = Services.navigationForDoc(this.ampDoc_);
}

/** @override */
buildCallback() {
const viewer = Services.viewerForDoc(this.ampDoc_);
const viewer = Services.viewerForDoc(this.getAmpDoc());

/**
* We had to get referrerUrl here because when we use expandUrlSync()
* inside LinkRewriter it doesn't retrieve the referrerUrl
*/
return this.ampDoc_
return this.getAmpDoc()
.whenReady()
.then(() => viewer.getReferrerUrl())
.then(referrer => (this.referrer_ = referrer))
Expand All @@ -58,7 +53,7 @@ export class AmpLinkRewriter extends AMP.BaseElement {
this.rewriter_ = new LinkRewriter(
this.referrer_,
this.element,
this.ampDoc_
this.getAmpDoc()
);

this.attachClickEvent_();
Expand All @@ -69,7 +64,8 @@ export class AmpLinkRewriter extends AMP.BaseElement {
* @return {*} TODO(#23582): Specify return type
*/
attachClickEvent_() {
this.navigation_.registerAnchorMutator(anchor => {
const nav = Services.navigationForDoc(this.getAmpDoc());
nav.registerAnchorMutator(anchor => {
this.rewriter_.handleClick(anchor);
}, Priority.LINK_REWRITER_MANAGER);

Expand Down

0 comments on commit 9d75c26

Please sign in to comment.