Re: [w3c/webcomponents] [templates] Ensure that template instantiation actually improves the platform (#704)

I spent last week implementing a polyfill for a [syntax variation of the template instantiation proposal](https://github.com/componentkitchen/template-instantiation), and also ported a number of web components from the Elix library over to that polyfill to see whether template instantiation would make creating such components easier.

Upon reflection, it does not appear that template instantiation really helps us.

The web components we create are typically more complex than can be addressed with mustache syntax. We use a mixin architecture to create our components; e.g., a complex carousel component of ours is currently built from ~20 different mixins, each contributing some aspect of programmatic or interaction behavior to the component class.

Significantly, in this mixin architecture, the component class that defines the template _doesn't know_ what properties of sub-elements within that template will need to be modified by the mixins. Instead, a component asks itself (and therefore the mixins along its prototype chain) to build up a dictionary of all the updates that should be applied to the elements in its shadow tree. Then the component applies those updates.

Such separation of concerns means we cannot use the mustache syntax proposal, because that requires the complete set of attributes that will be modified to be expressed directly in the template. 

One thing that might help would be a way for a component class to indicate that a collection of property updates be applied to a given element. Perhaps this would be something along the lines of React's spread syntax:

```jsx
<div {...props}/>
```

We'd want to avoid introducing new syntax, so maybe we'd have a special property?

```html
<div properties="{{props}}"></div>
```

I had a chance to talk about these experiments with @rniwa at Apple last week. During our conversation, I proposed adding something like the `properties=` idea above to Ryosuke. He suggested that, given our existing mixin architecture, what we'd really benefit from is something that lets us apply a collection of property updates to a _tree_ of elements.

I've gone ahead and written up that idea as a proposal for bulk property updates. (Filed as a separate [issue](https://github.com/w3c/webcomponents/issues/718).) That includes a hypothetical `applyPropertiesById` method that would achieve what Ryosuke suggested. With something like that, we wouldn't need the template instantiation proposal.

In any event, for the time being, we don't see template instantiation helping our web components library.

-- 
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/704#issuecomment-352496219

Received on Monday, 18 December 2017 17:27:40 UTC