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

[templates] Is a global registry of template processors the right idea? #681

Open
domenic opened this issue Nov 2, 2017 · 5 comments
Open
Assignees

Comments

@domenic
Copy link
Collaborator

domenic commented Nov 2, 2017

The alternative, in my view, is requiring imperative code to instantiate templates given processors, as in the API at https://github.com/domenic/template-parts#the-templateinstantiate-method or similar. (Inspired by our previous discussions.)

This would require libraries and frameworks to come up with their own, possibly fragmented syntax for doing declarative templating. But it seems harsh to force another global registry on people given how much complaining we get around the global registry of element names in custom elements. There it was unavoidable, but here it seems pretty avoidable.

Maybe we should have both, i.e. have an underlying imperative API and then if you want to use a global registry that the browser provides, you can? The idea being that more advanced frameworks would then be able to take advantage of the functionality here without necessarily locking themselves into the browser-supplied global registry.

@rniwa
Copy link
Collaborator

rniwa commented Nov 2, 2017

We think the ability to specify a template type declaratively in HTML is important so that the user of a template library doesn't need to specify it every time creating a template instance.

Supporting the both is fine. Alternatively, we can support a scope at a shadow tree level.

@Jamesernator
Copy link

Why was the global registry of Custom Elements unavoidable? The fact it exists is one of the reasons I still avoid custom elements for the most part. I can't see why it wouldn't be possible to have shadowRoot.customElements in addition to window.customElements.

Regardless I think template types shouldn't make the same mistake as otherwise there's going to be an even higher chance of namespace collisions for distributed templates given names like for-each/if/etc will almost certainly be commonplace.

@rniwa
Copy link
Collaborator

rniwa commented Nov 4, 2017

Yeah, I think having a template type registry at a shadow root level is highly desirable.

@domenic
Copy link
Collaborator Author

domenic commented Nov 14, 2017

At TPAC, we decided that for v1, there would be no global registry, so if you want to use purely declarative syntax, you'll need to accept the default processor. Assigning to @rniwa to update the proposal in that direction (perhaps by pulling some stuff out into a separate v2 document).

@cdata
Copy link
Contributor

cdata commented Feb 27, 2018

In experimenting with polyfills for this feature, I found it most convenient to specify the template processor when HTMLTemplateElement.prototype.createInstance is invoked, similarly to what @domenic demonstrated in his Template Parts proposal. E.g., template.createInstance(myProcessor, optionalValues).

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

No branches or pull requests

4 participants