source: node_modules/immutable/contrib/cursor/README.md

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1004 bytes
RevLine 
[d24f17c]1Cursors
2-------
3
4Cursors allow you to hold a reference to a path in a nested immutable data
5structure, allowing you to pass smaller sections of a larger nested
6collection to portions of your application while maintaining a central point
7aware of changes to the entire data structure: an `onChange` function which is
8called whenever a cursor or sub-cursor calls `update`.
9
10This is particularly useful when used in conjuction with component-based UI
11libraries like [React](http://facebook.github.io/react/) or to simulate
12"state" throughout an application while maintaining a single flow of logic.
13
14
15```javascript
16var Immutable = require('immutable');
17var Cursor = require('immutable/contrib/cursor');
18
19var data = Immutable.fromJS({ a: { b: { c: 1 } } });
20var cursor = Cursor.from(data, ['a', 'b'], newData => {
21 data = newData;
22});
23
24// ... elsewhere ...
25
26cursor.get('c'); // 1
27cursor = cursor.update('c', x => x + 1);
28cursor.get('c'); // 2
29
30// ... back to data ...
31
32data.getIn(['a', 'b', 'c']); // 2
33```
Note: See TracBrowser for help on using the repository browser.