Skip to content

Commit

Permalink
Installer for extensions for dev mode (ampproject#5459)
Browse files Browse the repository at this point in the history
* Installer for extensions for dev mode

* notes

* minor

* review fixes

* minors

* pass AMP objecy
  • Loading branch information
Dima Voytenko authored and Vanessa Pasque committed Dec 22, 2016
1 parent f085b10 commit c4feeec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion extensions/amp-share-tracking/0.1/amp-share-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,8 @@ export class AmpShareTracking extends AMP.BaseElement {
}
}

AMP.registerElement('amp-share-tracking', AmpShareTracking);

// Install the extension.
AMP.extension('amp-share-tracking', AMP => {
AMP.registerElement('amp-share-tracking', AmpShareTracking);
});
15 changes: 15 additions & 0 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ function adoptShared(global, opts, callback) {
win: global,
};

// `AMP.extension()` function is only installed in a non-minified mode.
// This function is meant to play the same role for development and testing
// as `AMP.push()` in production.
// TODO(dvoytenko, #5507): Only expose this method for `!getMode().minified`
// once the compile-time inlining is done.
/**
* @param {string} unusedName
* @param {function(!Object)} installer
* @const
*/
global.AMP.extension = function(unusedName, installer) {
installer(global.AMP);
};

/** @const */
global.AMP.config = config;

global.AMP.BaseElement = BaseElement;
Expand Down

0 comments on commit c4feeec

Please sign in to comment.