statestore

0.2.1 • Public • Published

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();

Example

a simple todo example

Package Sidebar

Install

npm i statestore

Weekly Downloads

11

Version

0.2.1

License

MIT

Last publish

Collaborators

  • iralph