Re: [w3c/webcomponents] Bulk property updates (#718)

@annevk Our interest in not necessarily perf, but primarily to recognize that devs today who are updating DOM often do so by generating internal data structures. They then have to apply those data structures to the DOM by interpreting the data and making atomic DOM manipulations.

Example: to set an element's children to an array of nodes, you must loop to `removeChild()` old nodes and `appendChild()` new nodes:

```js
// Set the given array of elements as children of the indicated node.
function setChildNodes(node, elements) {
  while (node.childNodes.length > 0) {
    node.removeChild(node.childNodes[0]);
  }
  elements.forEach(element => node.appendChild(element));
}
```

I'm constantly writing code like that. Being able to do something like:

```js
node.applyProperties({ childNodes: elements });
```

would be so much nicer. I'd assumed that the browser could do a faster job at that task than my naive loops above. But even if the performance was the same, the `applyProperties` version better expresses the developer's intention.

We began exploring this area because we tried using (a polyfill for) the proposed HTML template instantiation proposal. That proposal isn't about performance either; it's about improving dev ergonomics. As it turns out, the template instantiation proposal doesn't help us. Fundamentally, what we're really after is a more natural way to express the generation and updating of DOM nodes and trees in JavaScript.

-- 
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/718#issuecomment-352596945

Received on Tuesday, 19 December 2017 00:02:34 UTC