Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer for extensions for dev mode #5459

Merged
merged 6 commits into from Oct 11, 2016

Conversation

dvoytenko
Copy link
Contributor

No description provided.

* @const
*/
global.AMP.extension = function(name, installer) {
installer.call(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the explicit no context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, why not just installer()? No reason. Will switch to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// Install the extension.
// DO NOT SUBMIT: First, we must implement compiler rewrite path to unwrap
// this code.
AMP.extension('amp-share-tracking', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be ok to wrap the whole file with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be. But I'm not a big fun of that. If someone wants to unit test a specific class - there's no reason why not allow it. All I want to make sure is that we don't just install the whole thing into global window on import - that would give us proper hermetic tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, im trying to weight if we want to add this dynamically during dev (just through the wrapper configuration) or remove it during production build time (a bit more work but also do-able)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be hard to add it dynamically, unless you want to wrap the whole thing. But that's also hard. With AMP.push we first get the complete concatenated binary before wrapping. This is not the case for development.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, i looked around. And I think we definitely canNOT roll the whole module inside AMP.extension. Besides being an anti-pattern in our world, it'd be also very hard to do this given the multi-module code in many extensions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dvoytenko do you need this ASAP? (just so i know how to prioritize)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not going to submit this particular file, hence the DO NOT SUBMIT. Let's discuss offline. I'm not seeing a better way to make our tests hermetic, but we can delay this particular change and pursue a bit more manual approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@dvoytenko
Copy link
Contributor Author

@erwinmombay PTAL

@dvoytenko
Copy link
Contributor Author

@erwinmombay Changed this PR as discussed. PTAL.

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

// Install the extension.
AMP.extension('amp-share-tracking', AMP => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that first arg new?

i would have to to do:

(function(AMP) {

}(AMP));

to mimic correctly instead of assuming global (which should also be ok)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I realized that just deferring side effects is not enough. I also need to later install them to the right space :)

@dvoytenko
Copy link
Contributor Author

@erwinmombay in the meantime, is this good to be merged?

@erwinmombay
Copy link
Member

@dvoytenko LGTM

@dvoytenko dvoytenko merged commit 553247b into ampproject:master Oct 11, 2016
@dvoytenko dvoytenko deleted the amptest1-ext branch October 11, 2016 16:51
dreamofabear pushed a commit to dreamofabear/amphtml that referenced this pull request Oct 12, 2016
* Installer for extensions for dev mode

* notes

* minor

* review fixes

* minors

* pass AMP objecy
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* Installer for extensions for dev mode

* notes

* minor

* review fixes

* minors

* pass AMP objecy
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
* Installer for extensions for dev mode

* notes

* minor

* review fixes

* minors

* pass AMP objecy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants