3 ms·
To better explain myself: VDOM takes two versions of the element tree, makes a diff and patches the DOM accordingly. Why not take two versions of the state tree
by janci 4y ago
To better explain myself: VDOM takes two versions of the element tree, makes a diff and patches the DOM accordingly.
Why not take two versions of the state tree, diff that and patch DOM directly? What benefit the VDOM brings?
- ivanvanderbyl 4y agoWhat you are describing sounds closer to how Svelte works.
- eldenring 4y agowriting to the DOM is slow, you use VDOM to batch updates and other optimizations
- megous 4y agoNo it's not. It's pretty close to browser's native HTML parsing speed. And VDOM just writes to the DOM in addition to doing a lot of other throwaway work and allocations. Reading from DOM may be slow, if you read one of the properties that would trigger layout/style calculactions.
- franciscop 4y agoWhat do you mean by "state tree" here? And how do you go from the state tree diff to the required dom diff?
- speedgoose 4y agoI remember that historically DOM used to be very slow on some browsers and virtual DOM was a huge performance boost. You could compute very quickly the difference in JavaScript and minimise the calls to the slow DOM browser API. Now that Internet Explorer is really deprecated and DOM are fast enough in every browser, VDOM is not necessary.
- naniwaduni 4y agoWhy diff trees at all when you can record a changeset and patch DOM based on that?
- isbvhodnvemrwvn 4y agoHow do you get the changeset?
- hajile 4y agoPreact does this and is also small and react compatible.