behave-immutable
An immutable data store that keeps state history
In most cases when you want to update a model/store, you will also want access to it's previous states, in a lot of frameworks this is something you have to design on your own even though this is how a model should behave.
behave-immutable
depends on Facebook's Immutable library under the hood, when you pull state from the stack it will return you an instance of Immutable.
Install
npm install --save behave-immutable
Usage
// anything passed to constructor will be set as first stateconst immutable = some: 'value' ; // setting stateimmutable;immutable; // => { some: 'value', another: 'value' }immutable; // => { some: 'value' } // resetting stateimmutable;immutable; // => { another: 'value' }immutable; // => { some: 'value' } // replacing stateimmutable;immutable; // => { another: 'value' }immutable; // => undefinedimmutable; // => 1 // working with state from the stacklet currentState = immutable; // => latest state let removeLastState = immutable; // => latest state, removing from stack let removeFirstState = immutable; // => first state, removing from stack let atIndex = immutable; // => copy of state at index, non-destructive let range = immutable; // => array of states in range (including end index) immutable; // => empties the stack // sugar methods to transform latest stateimmutable; // => { some: 'value', another: 'value' } immutable; // => { "some": "value", "another": "value" } immutable; // => "some=value&another=value"
Testing
To run the tests for behave-immutable
simply run npm test
Release History
- 0.1.0 Initial release
- 0.1.1 Fixed improper encoding on serialize
- 0.1.2 Added test instructions to readme
- 0.1.3 Minor refactoring
- 0.1.4 Fixed incorrect main file in package.json
- 0.1.5 Added build badge
- 0.1.6 More descriptive examples in readme
- 0.1.7 Fixed errors in examples
- 0.1.8 Fixed error when setting initial state
- 0.1.9 Updated build to latest code