DEV Community

Discussion on: React vs Signals: 10 Years Later

Collapse
 
mfp22 profile image
Mike Pearson • Edited

This might irritate React developers, but it's obvious you're right. The benefit of React was completely about sane code structure, and in the end that structure became identical to reactivity under certain rules. So... How about just reactivity with those rules? But I guess we'll watch as the industry debates whether React was 90% right or 100% right. Kind of boring tbh.

But it seems to me like the emphasis on unidirectionality is about making it easy to answer the question, "Why did this value change?" This is why I have stopped caring about read/write segregation as an RxJS user. In actually fully reactive programming, the answer is that the value changed because the stream it directly referenced emitted a new value. There's nothing to " track down". In CycleJS this extends all the way up to event sources. But even in a Flux-like architecture where user events result in initial callback functions but those functions only contain a single imperative command (dispatch or next for RxJS), it's also not hard at all to find the source of changes. It's only when you mix reactivity with MVC that things become extremely chaotic.

By MVC I mean MV-Controller, where controllers are functions that control state as side-effects. So basically 90% of React components. So do we secretly love MVC? I don't, but devs with strong imperative habits may prefer an "imperative feel" for updating state. But it's not clear to me that it's actually easier. When updating a counter, why should the first instinct be to write a callback function to imperatively update count state that lives elsewhere? Why isn't it to update the count state to react to the click event?

If you listen carefully to the original Flux presentation, the point of unidirectionality was to avoid infinite loops, but more importantly colocate control logic and the state it's defining. Declarative code. Reactive code.

So if you have actual full reactivity, unidirectionality is a strange and redundant goal.

Collapse
 
ryansolid profile image
Ryan Carniato

Agreed. Signals systems even are generally a DAG. In Hindsight, I probably should have put that in the article. Maybe it isn't too late.

Collapse
 
redbar0n profile image
Magne

This reminds me of React's relation to MVC. stackoverflow.com/a/65969849/380607

Here's the gist of the headlines from that answer:

React is not considered to be MVC. Since Facebook inaccurately contrasted Flux with MVC.

Flux is not in direct opposition to MVC per se, but in opposition to mutability and two-way data-binding, something which MVC does not specify (but which people typically allowed when using MVC).

Stateless MVC also didn't fit on the client-side.

But React is MVC, in some sense. Components are ViewControllers, typically. Components as Views, Hooks as Controllers.

Alternatively, you could treat Components as pure Views (as originally intended?), and have a separate Model-Controller:
github.com/statelyai/xstate/discus...

Collapse
 
mfp22 profile image
Mike Pearson

Sounds like you're copying my own writing back to me but with strange twists
Image description

Controllers "control" things, so it's the event handlers with imperative state-controlling statements that are the controllers.

Thread Thread
 
redbar0n profile image
Magne

Indeed, and the event handlers could be modeled in XState, like in my gist. It’s basically vertically sliced MVC-widgets, instead of having MVC as a horizontal layer based on technology.