DEV Community

Discussion on: JavaScript vs JavaScript. Fight!

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️ • Edited

I've always found the various approaches to reacting to data/state changes in JS frameworks rather over-engineered.

To me the ideal solution would be a MutationObserver for plain JS objects. Something that tells me (via callback) when, for example, an element was pushed on an array.

Built-in reactivity on a data-level seems like a much more straight-forward (and probably easier to optimise) solution than a full re-render with subsequent DOM-diffing or Svelte's broken update = () => state=state™ hack


EDIT: To some extent, it is possible to approximate this behaviour in JavaScript using Proxy objects, which works just fine but comes with the downside of having to use Proxies of everything, because the plain object could still be changed without the proxy knowing.

Even with this limitation though, I've found that this way of reacting to data changes is much easier to handle in plain JS and leads to way less weird shenanigans to convince a framework to really update.

Collapse
 
ryansolid profile image
Ryan Carniato

Have you seen my library SolidJS? It's what I'm hinting at in the end about being more granular and diffing less. But it works as you mentioned more or less. I just don't want to always come in with the strong hand. But performance wise it is reasonably impressive.

Collapse
 
miketalbot profile image
Mike Talbot ⭐

Just wanted to say I think that SolidJS is fantastic work.