4 ms·
I think I get it. Can anyone let me know if this description of my understanding is close to correct? React lets us program reactively by rerunning the entire
by baddox 13y ago
I think I get it. Can anyone let me know if this description of my understanding is close to correct?
React lets us program reactively by rerunning the entire JavaScript description of a component every time its data changes. This lets us use "normal" JavaScript code to describe our component (as opposed to explicitly attaching Ember dependencies or using Angular ng-* attributes). This normal JavaScript code will describe the component at all points in time, not because there is two-way binding, but because any change in the state of the component will cause the entire JavaScript function to re-execute.
React's virtual DOM, then, doesn't have anything to do with reactive programming per se. It's just the way that rerunning JavaScript code for every single data change can be made performant.
- danabramov 13y agoThis sounds correct.
- skybrian 13y agoPretty much. It's similar in spirit to reactive programming if you think of a component as exposing a Signal<Virtual DOM> that the renderer subscribes to. Also, the Signal<Virtual DOM> depends on a Signal<Props> and a Signal<State>. And the Signal<Props>, in turn, depends on the component owner's Signal<Virtual DOM>. You also have control over whether the render() method is called by substituting your own diff function (shouldComponentUpdate).
- hcarvalhoalves 13y agoHave you ever programmed graphics? To make a paralell, usually in graphics your main loop reacts to events (user input) and you change some internal state in some object(s). Finally, you get all those objects that know how to render themselves, see what's relevant and render the whole scene. You don't have to care about pixels, you just react to events and blit a representation of the entire state. React.js is the same, the difference being your components "render" themselves to the DOM, and because it's a tree, it's naturally composable. It's still a pipeline taking state and outputing a representation though.
- seanmcdirmid 13y agoThat is retained rendering with scene graphs. Immediate-mode rendering is obviously very different.