statestore
v0.2.1
Published
a simple state manager for mvc or flux
Downloads
3
Readme
StateStore
a simple state manager for mvc or flux
Installation
$ npm install statestore
Usage
var StateStore = require('statestore');
var store = new StateStore({
a: 'aaa',
b: {
name: 'bbb',
child: {
name: 'ccc',
arr: [1, 2, 3]
}
}
});
var unsubscribe = store.subscribe('b.child', function handler(path, value, oldValue) {
console.log(handler.sPath);
console.log(store.getState('b.child'));
});
store.setState('b.child.name', 'c');
store.setState({
a: '123',
b: {
name: 'bbb'
}
});
unsubscribe();
store.subscribe('b.child.arr', function() {
console.log(store.getState('b.child.arr'));
});
store.subscribe('b', function() {
console.log(store.getState('b.child.arr'));
});
store.setState('b.child.arr', [1, 2, 3]);
store.setState('b.child.arr', [4, 2, 3]);
store.unsubscribeAll();