Hacker News new | ask | show | jobs
by bleuarff 42 days ago
Reactivity is updating the DOM whenever the underlying data is updated. That's one of the most basic reason for existence of all js frameworks. There's TC39 Signals proposal to bring that natively, but for now as said above the choice is either use a framework or recreate one. It's surprisingly easy nowadays using Proxy.
3 comments

It’s always been easy to reactively update the DOM. I was doing that in vanilla JS before HTML5 had been formalised.

What the frameworks do is take this concept one step further to create a SPA (single page application) but I honestly think they’re an antipattern that needs to die.

The problems are ownership and provenance mainly, and that all DOM access is slow and requires syncing code internally.

Anyone can write code that tweaks nodes or uses templating, but doing it in a consistent way on a project with hundreds of thousands linea of code is challenging, especially if you also need performance and everyone's least favourite child: accessibility.

Sure you don't get some of this with frameworks, but they help a lot.

Well yeah, obviously frameworks are intended to provide a standard interface for projects that scale. But you’re describing a different problem to the one originally argued.
> Reactivity is updating the DOM whenever the underlying data is updated. That's one of the most basic reason for existence of all js frameworks.

Most web apps and websites do not have that much state variables (even though it may be a lot of data). So while React may offer a small dev speed boost, it’s consumed by the need to build stuff and a whole deploy pipeline to nurse.

Libraries like HTMX and Alpine can take care of most the boilerplate for old style imperative patterns. And backend frameworks like Rails, Phoenix, Laravel donhave their own implementation for data updates.

How I've done it is to use some kind of observer pattern, where you register listeners to state changes.

Whenever state is updated, the listeners are all called with the updated state and can update the UI and what not based on the new state.

I haven't profiled this and compared it to frameworks, but feels adequate for the relatively simple UIs I've done.

In a way that's where all frameworks start.