4 ms·
React's rendering looks really awesome, but I'm missing the bit that binds application data to views. e.g. in KnockoutJS I can just use observable arrays and p
by pornel 13y ago
React's rendering looks really awesome, but I'm missing the bit that binds application data to views.
e.g. in KnockoutJS I can just use observable arrays and properties and never have to call `setState()` on anything. What's the equivalent for React?
- Touche 13y agosetState is equivalent to an observable. The only problem is that it's specific to the component you're working in, you have to get that information to others manually.
- mega_malo 13y agommm
- peterhunt 13y agoYou can very easily do this by combining Object.observe() (or a polyfill) and calling forceUpdate(). However we've found that this sort of data binding is suboptimal since it encourages mutation which forces you out of some great perf optimizations (like the Om stuff, and Object.observe() has its own performance penalties). And thinking about your data flow a little more explicitly makes it easy to follow where updates are being triggered from (so a mutation in one part of your app doesn't accidentally trigger updates all over the place). Most of the time doing this explicitly is a little more typing up front but is worth it for larger apps from a performance and maintenance perspective. If you start building with React you'll find that your data model flattens out as you go down the view hierarchy so this becomes less of an issue.
- juliangamble 13y agoYou can read more about how React combined with immutable data structures provides great performance in this blog post by David Nolen http://swannodette.github.io/2013/12/17/the-future-of-javascript-mvcs/ http://swannodette.github.io/2013/12/17/the-future-of-javasc...
- vjeux 13y agoIf your model is managed by a lib that provides callbacks when a piece of your model is updated you can make a mixin like it has been done for Meteor and Backbone integrations: https://github.com/benjamn/meteor-react#how-it-works https://github.com/benjamn/meteor-react#how-it-works http://eldar.djafarov.com/2013/11/reactjs-mixing-with-backbone/ http://eldar.djafarov.com/2013/11/reactjs-mixing-with-backbo...