x = document.createTextNode(v);
Now, consider the dependency v changes. The only option is to run the code above again, in its entirety. And thus, the DOM node corresponding to the text is new.Of course, a smart library will ensure that the amount of nodes that has to be visited is at a minimum. But that doesn't mean DOM nodes don't get rebuilt from scratch.
Not at all. The reactive pattern typically boils down to something like this:
el = document.createTextNode(initialValue);
parent.appendChild(el);
reactiveValue.onchange(v => {
el.nodeValue = v;
})
Ironically, in this specific example, vdom libs typically do this when possible: parent.textContent = v
which does in fact replace the underlying text node, but they do so for the sake of performanceIn the following example, I change the button id on click. It's still the same button element after the change:
You're absolutely right that reactive systems are not trivial to implement (let alone implement well), but inefficient DOM recreation under these systems is a symptom of poor granularity in the reactive layer (which may be a problem with the reactivity library just as well as it could be poor usage of its API), rather than a limitation of the rendering library itself.
I'm also worried about debugging accidental dependency triggers. Imagine that suddenly the scroll-state of some div is reset; how do you determine which dependency caused the DOM element to be recreated? With a vdom you avoid the whole problem.
Normally, I would toss in a throw and look at the stack trace. But yes, the stack trace gets noisy as hell.
What's tricky about reconciling app state changes and dom state is dealing with things like cursor position if e.g. the input value change comes from a socket and the user had the input focused and the cursor in the middle of the text. But this has nothing to do with vdom