4 ms·
you are right, this is a sticky spot when using immutability from javascript - you can clone-and-mutate (I started here, but it quickly became a bottleneck in
by dustingetz 12y ago
you are right, this is a sticky spot when using immutability from javascript
- you can clone-and-mutate (I started here, but it quickly became a bottleneck in my app, and jr developers forget a lot leading to hard to find bugs)
- you can use real persistent datastructures (Mori), but now you have added a cross cutting concern - which type of array is the one i'm working with right now?
- you can use React.addons.update (I use this successfully, but you need to get used to a weird syntax)
Om provides an abstraction over React state called Cursors which provides immutable updates to react state at any point in a state subtree. I ported this concept to javascript (implemented in terms of React.addons.update) and have used this successfully in two large scale enterprise applications for regulated industries and I know of one other company using this. This provides a very clean and elegant programming model for immutable updates to react state.
https://github.com/dustingetz/react-cursor/ https://github.com/dustingetz/react-cursor/
https://github.com/dustingetz/react-cursor/blob/master/examples/helloworld/webapp/js/Page.js https://github.com/dustingetz/react-cursor/blob/master/examp...
- cnp 12y agoDo you plan and providing a write-up for this repo? I'd love to dive in but don't quite know where to start.
- dustingetz 12y agoi gave a livecoding talk that builds up to cursors at QCon NYC 2014 - it is not yet public but i can send you a private link if you email me
- dustingetz 12y agoIt is written up now