-
Notifications
You must be signed in to change notification settings - Fork 370
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
[dom-parts] HTMLTemplateElement.fromStrings() API #1019
Comments
My first impressions of this are positive. It's an interesting way to sidestep the syntax question and still potentially get a lot from the platform. |
I needed almost this exact API to add DOM Parts support to our template system workbench: rictic/web-template-workbench#1 As part of writing up a polyfill, I had to make some choices around representing bindings inside an element tag. Code like: html`<div ${x}></div>` The user intent here is clearly for a NodePart. The template system needs a reference to the But for code like: html`<img src="https://example.com/${name}.png?size=${size}px">` We need to communicate that we've got bindings into the <?node-part attr src "https://example.com/" ".png?size=" "px" ?> This worked well. Though looking forward towards template instantiation, I think we will want an actual AttributePart and the |
Another thing that came up: this could use an option to parse the template in an |
This is an API for template instantiation / DOM Parts suggested recently by Google's security team (edit: by @engelsdamien specifically) that caught my eye.
Essentially it's a imperative way to create a template and a list of parts from template strings, but without having to specify a syntax for expressions.
fromStrings()
would be a static method that takes an array of strings (security wants this to be a TemplateStrings array to be unforgeable developer-controlled value) and create DOM parts between each string.A template system can be built with this quite easily:
Where template strings are allowed to break and what type of parts those break create would have to be figured out, which is the same for a syntax. It could be that the syntax is the easier piece of the puzzle once that is done, but if syntax were a roadblock, this approach could side-step it for a bit.
The text was updated successfully, but these errors were encountered: