Re: [w3c/webcomponents] [templates] API for updating (#685)

I've spent the last few days pondering @domenic's comments. Component Kitchen is excited by this proposal, and share some of Domenic's concerns, so we wanted to take up @rniwa's invitation to think about the top-level API for template instantiation.

I thought live code experiments might be the best way to explore alternatives, and have put together some suggestions in the ReadMe at https://github.com/ComponentKitchen/template-instantiation.

At this point, the main suggestions are to consider separating template and parsing concerns, and to have the result of instantiation be two objects: a new instance and an updater.

```js
// Parse a template with mustache syntax to obtain an element factory.
const factory = new ElementFactory(template);
// Use the factory to obtain both an instance and an updater.
const { instance, updater } = factory.instantiate({ name: 'world' });
// Add the instance to the document.
document.body.appendChild(instance);
// Later on, update.
updater.update({ name: 'Jane' });
```

[Live demo](https://rawgit.com/ComponentKitchen/template-instantiation/master/demos/hello.html) ([Source](./demos/hello.html))

The repo's ReadMe goes into more detail. Among other thing, it explores use in web components, and how this approach could allow libraries like @justinfagnani's lit-html to efficiently participate in the new browser facility for element instantiation.

Coding with this feels fairly good. If this feels interesting, we're happy to develop this further, try out suggestions for changes, and see where it goes.

-- 
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/685#issuecomment-350794478

Received on Monday, 11 December 2017 17:24:17 UTC