[w3c/webcomponents] Discussion: Templates that Don't Destroy Element References (#777)

In the same manner that tagged template literals allow the embedding of interpolated JavaScript expressions, I think it would be awesome if HTML <template> tags (or some new tag type) allowed ${variableName} expressions also. Then, instead of cloning a template, you could just instantiate it in the same manner you would an object from a class (without losing your element references), and when you do this the interpolated values could be based on the original context from where the instantiation occurs (or through .bind to specify an alternative context), kind of like arrow function scoping but with bindablity. 

Also, I think if an interpolations output is anything other than an element, the instantiation should covert that output to a static string that cannot be modified. There's no need to update the template if you can instead update the dynamic elements that were place into it. Cloning <template> destroys your element references. Template instantiation should **keep** those element references! This way, at the custom class level, you'll always be able to modify the vary same elements you created before injecting it into the template.

If we had a <template> tag like this; it would be all I'd ever need.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/777

Received on Tuesday, 4 December 2018 19:58:05 UTC