4 ms·
I'm kinda out of the loop with Javascript nowdays, but how would one react to changing data on some input element and receive it in Javascript, integrating eleg
by gima 10y ago
I'm kinda out of the loop with Javascript nowdays, but how would one react to changing data on some input element and receive it in Javascript, integrating elegantly with this library?
- wrong_variable 10y agoeasy, using vanilla.js ! you attach event-handlers to each virtual-dom the same way you would do with a normal-dom. and those event-handlers can react to change the way you want. If you mean how to do auto-data binding oldDom = patch (document.body,newDom) newDom = h ('div','hello world') patch (oldDom,newDom) patch is the function that does the dom diffing. The amazing thing is most web components do not need auto-diffing. Sometimes you want fine grained control where you write your own update functions - making imperative changes to the dom based on your needs. And for other web components where you want more auto-updates you can patch accordingly. The thing that is amazing is that you can dial it up and down based on your individual needs. A good example is table components with a lot of data. You really do not want to incrementally update the table. So for the divs with the data you patch but other components that have a lot of interactivity you can simply not patch and do updates by hand.
- tobr 10y agoThere's an event module built into snabbdom, so you can add a handler for `input` events, change whatever state you want, then create a new vnode and patch the dom. The architecture is very much up to you, snabbdom just updates the dom.