3 ms·
Now we have promises, observables and signals. I would be more happy if it would be just one of those..
by andriy_koval 5mo ago
Now we have promises, observables and signals.
I would be more happy if it would be just one of those..
- halflife 5mo agoEach one of these solves a different problem. Promised - async Observables - streams Signals - reactivity
- azangru 5mo ago> Observables - streams > Signals - reactivity The r in rx stands for reactive.
- halflife 5mo agoThe react in react stands for reactivity, however it is not.
- azangru 5mo agoReact reacts to changes in state or properties by automatically updating the UI. What's not reactive about that?
- halflife 5mo agoIts entire state management is not reactive, it’s always on push, not pull. You always need to call setState to get render changes.
- azangru 5mo agoBut why is push vs pull the definition of reactivity? I suppose we can say that there are different kinds of reactivity. Signals is one kind. Observables à la rxjs is a different kind (the whole model of programming with rxjs was referred to as "functional reactive programming"). Observables are push-based. Signals, as I heard, are a more complex primitive, which, under the hood, is push-pull. React's reactivity model may be crap; but this doesn't make it non-existent.
- halflife 5mo agoMaybe push pull wasn’t the best metaphor, but the point is that everything can be reactive, it only depends on how much boilerplate you need to write to achieve the desired result. Since react doesn’t have a true reactive model, you need to subscribe to changes manually (use effect) to create computations, while in signals it’s a primitive (computed). I actually created a lib that operates signals over reacts state management (https://roypeled.github.io/react-logic/ https://roypeled.github.io/react-logic/), so I removed the boilerplate to create a true reactive system. If you want, you can create reactive system just from JS primitives, using callbacks. But that doesn’t make JS reactive by nature.
- azangru 5mo ago> you need to subscribe to changes manually (use effect) to create computations How do you mean? Since the render function reruns during every update to state/props, derived/computed values can be calculated from the updated state/props during rendering.
- halflife 5mo agoWhen all you need is a synchronous operations, yes. When it involves async, batching, buffering, and user input, it becomes much more complicated, and every step needs to be setup manually.
- zigzag312 5mo agoUI is reactive, not state. You push changes to state and UI reacts to it.
- halflife 5mo agoA derived state is certainly reactive.
- zigzag312 5mo agoOf course you can have reactive state, your complaint however was: "The react in react stands for reactivity, however it is not." [because] "Its entire state management is not reactive" React is primarily an UI library, not full state management library. And its UI is reactive.
- wartijn_ 5mo agoIn theory that’s true (although observables are for reactivity too), but Angular uses observables for its http library and http requests are very much not streams. It’s one of the main downsides of working with Angular, the http library is mediocre and does come with the added overhead and complexity that rxjs brings. Until this release (if you only use stable features) using forms meant dealing with observables too, even if you just want to read data when submitting a form and validating some data on change/blur. And often you’ll find that your data from promises, observables and signals need to interact with each other, which can be annoying. Fortunately the situation with signals and their async usage is improving, and iirc the Angular team wants to make rxjs optional, but until it is Angular can be a confusing mess on some points.
- halflife 5mo agoI partially agree, there is an overlap between signals and rxjs, however the core business is different- observables are about data manipulation, while signals are about efficient state management. Regarding angular I agree, rxjs was a bad choice for data management, and before signals arrived I abandoned rxjs in favor of mobx in my angular projects. However you could roll your own http client, we used axios, and using DI it’s a drop in replacement.
- deleted 5mo ago[deleted]