Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

AMP Playground should automagically import component scripts #1457

Closed
tomayac opened this issue Aug 14, 2018 · 5 comments
Closed

AMP Playground should automagically import component scripts #1457

tomayac opened this issue Aug 14, 2018 · 5 comments

Comments

@tomayac
Copy link
Contributor

tomayac commented Aug 14, 2018

Currently it's a bit burdensome to include component scripts manually. Turns out, @garanj has built a Gulp plugin called amphtml-autoscript that does it automagically. Can we incorporate this (or its logic) into the Playground?

@sebastianbenz
Copy link
Collaborator

Yes please 😀

@garanj
Copy link
Contributor

garanj commented Sep 2, 2018

Hi @sebastianbenz ,

Thanks for your advice on start points. I had a go at building and it seems pretty straightforward (even for me!) to hook into the necessary events for a new module. Works nicely.

I've two questions, and would welcome some guidance:

  1. I was thinking of subscribing to Validator.EVENT_NEW_VALIDATION_RESULT, and making use of the fact that validation results were already available. If not, possibly Editor.EVENT_INPUT_NEW, but I think really the former.

    In either case, using editor.setSource can cause a loop, as it fires Editor. EVENT_INPUT_NEW, which triggers editorUpdateListener, validation etc.

    I've a couple of options for how to set the text of the editor without causing an event loop. Any preferences on how to do it? One might be a further method in Editor, or adding an optional parameter to setSource indicating whether or not to fire events?

  2. I've used your snippet for getting a list of components, and added in getting version numbers. Works great. However, I'm thinking that the client should really not be making this request to GitHub direct, instead either:

    1. An endpoint within Playground that provides the list (and periodically refreshes this with GH)
    2. A list formed as part of the build process

    Do you have a view on either approach? I think GH would probably limit requests, if coming from clients, and this could be a problem, and additionally, the response is needlessly large compared to the list that is created from it. I favour approach 1 above, and wonder if you have views on where this should sit?

Apologies if these seem obvious questions!

@sebastianbenz
Copy link
Collaborator

Thanks a lot for looking into this!

  1. I think it definitely makes sense to hook into validation results. The loop is tricky, as we'll have to fire a new change event to trigger validation. Do you know what's causing the loop (as it shouldn't happen)? Regarding changing the doc, I think we should introduce a new method to Editor which then delegates to codemirror's built in API: https://codemirror.net/doc/manual.html#replaceRange.
  2. I agree, it makes sense to move this server-side.
    • You could extend the current playground backend here (it's implemented in Go though). I'd suggest using a stale-while-revalidate caching strategy and store the results server-side.
    • Another option would be to store and cache the results client-side (e.g. service worker cache or IndexedDB).

sebastianbenz pushed a commit that referenced this issue Sep 25, 2018
* Added AMP component auto-import.

* Minor formatting fixes.

* Reformatted Go-style if... statements

* Format Go code

* Go formatting

* Go formatting

* Changes from review

* Changes to ComponentsProvider

* Requested changes to ComponentsProvider

* Fixed handling of GitHub errors

* Comments explaining use of API key

* Added README for Datastore configuration
@kul3r4
Copy link
Collaborator

kul3r4 commented Sep 27, 2018

@sebastianbenz can we close this?

@sebastianbenz
Copy link
Collaborator

sebastianbenz commented Sep 27, 2018 via email

@kul3r4 kul3r4 closed this as completed Sep 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants