data-cursor.js
npm install --save data-cursor
What is it?
This library is for traversing and modifying nested data structures, without mutating original objects.
It was originally developed as react-addons-update
replacement for me, because only declarative method of describing state transitions is hard. Especially when you need conditions for certain operations, need to create your own operations or massivly change big structures, without creating too many intermidiate values.
This library is like Immutable.js
, but for any data types, not just that provided by Immutable.js
.
Features
- You can effectively update complex structures
- You can track changes, where and when they're occured
- You can add your own operations on any data type (DOCS MISSING, HELP WANTED).
Also, you can track changes, where and when it occured, if you use this library for data manipulation.
Simple API documentation to start with
Example with react-addons-update
:
; const state = nested: object: withArray: value: 'value' ; const updateCommand = newPlainKey: $set: 'value in plain key' nested: object: oneMoreKey: $set: 'oneMoreValue' ; if Math > 05 updateCommandnestedobjectoneMoreKey2 = 'oneMoreValue2'; const newState = ;
Turn's into this with data-cursor:
; const state = nested: object: withArray: value: 'value' ; const cursor = ; // cursor.get('nested').get('object').get('withArray').get(0).get('value').value()) === 'value' // (cursor.value() === state) === true const originalNestedObjectValue = cursorvalue; cursor; // (cursor.value() === state) === false // (cursor.get('nested').get('object').value() === originalNestedObjectValue) === true cursor; // (cursor.get('nested').get('object').value() === originalNestedObjectValue) === false // cursor.get('newPlainKey').value() === 'value in plain key' if Math > 05 cursor; const newState = cursorvalue;
API Documentation
import {getCursor} from 'data-cursor'
TODO (Help wanted!)
- Simplify API for
Operations
descriptors - Changes on
defaultOperations
must be forbidden - More examples with other libraries (like: how to use it with redux)
- Split up tests
- Write tests on
Operations
- Create build scripts for all popular formats, like ES6 for rollup, UMD for everyone else, etc.
- Use
Object.freeze
inprocess.env.NODE_ENV === 'development'
for incoming data structures. - More documentation and usage examples on advanced getCursor arguments
- Documentation on
Operations
. (How to add your own types and operations on them, why it's addobject
operations to everyinstanceof Object
, etc). - More docs!