WICG / webcomponents

Web Components specifications
Other
4.39k stars 376 forks source link

[templates] What is declareCallback? #693

Open domenic opened 7 years ago

domenic commented 7 years ago

This was used in the declarative shadow root example, but doesn't seem to appear elsewhere.

rniwa commented 7 years ago

It's not spec'ed anywhere. It's sort of a suggestion that shadowroot element could be implemented that way if we had such a callback which gets called for a template "declaration".

domenic commented 7 years ago

@rniwa what is template "declaration" and do you think we should include it in v1? I don't really have a sense of whether it's an easy addition or a hard one.

justinfagnani commented 6 years ago

We recently needed to add a callback to lit-html with the same timing as declareCallback to modify the template for various polyfills. Seems really useful in a number of other scenarios too, especially for custom template processors to do one-time work.

cdata commented 6 years ago

To offer an example related to what @justinfagnani suggested about one-time work:

Many types of template expressions will need to be parsed before they can be used in the template processor. It will be ideal if each expression is only parsed once per part per unique template. A declareCallback would be a nice spot to do this kind of thing.