3 ms·
> The DOM is neither stateful or stateless, but rather that describes the implementation of your application logic. One of the bizarre realities with those for
by Jasper_ 8y ago
> The DOM is neither stateful or stateless, but rather that describes the implementation of your application logic.
One of the bizarre realities with those forced to write their own "virtual DOM" library, as I have done, is to deal with all the so-called hidden state. Form field values, the user's current text selection, scrolling position. Without a virtual DOM, simply replacing existing nodes with innerHTML or replaceChild will stomp this away. I'm not of the opinion that you need a full framework to handle this state (I wrote my own 10-line helper function which works in most cases I care about [0]), but you do need something more structured than just replacing nodes wholesale.
[0] https://github.com/magcius/noclip.website/blob/master/src/ui.ts#L24-L49 https://github.com/magcius/noclip.website/blob/master/src/ui...
- austincheney 8y agoWhat about with using appendChild or insertBefore instead of innerHTML?
- deleted 8y ago[deleted]
- EGreg 8y agoIs that really valid ES6? Or are you using typescript