Immutable dispatcher for the flux architecture.
dispatcher.dispatch
returns a new state.Coldstorage is implemented using CommonJS. Currently coldstorage is distributed using npm
. It can be installed by running
npm install coldstorage
in your project.
Coldstorage runs both in Node and the browser via browserify (or the like).
You create actions by passing an array of strings into coldstorage.createActions
:
var actions = coldstorage.createActions(['login', 'logout']);
var userStore = coldstorage.createStore('user');
userStore = userStore.on([actions.login], function (login) {
var authed = login.get('username') === 'admin' && login.get('password') === '1234';
return this.set('authed', authed);
});
userStore = userStore.on([actions.logout], function () {
return this.set('authed', false);
});
var alertStore = coldstorage.createStore('alert');
alertStore = alertStore.on([userStore], function (user) {
var authed = user.get('authed');
if (authed === true) {
return this.set('message', 'You were logged in');
}
return this.set('message', 'You were logged out');
});
var dispatcher = coldstorage.fromStores([
userStore,
alertStore
]);
var dispatcher = dispatcher.dispatch(actions.login, {'username': 'admin', 'password': '1234'});
var userstore = dispatcher.stores.get('user');
// Prints true
console.log(userstore.get('authed'));
// Prints admin
console.log(userstore.get('username'));
Requests and discussion are very welcomed in github issues
Use github pull requests to contribute patches.
coldstorage
is MIT-licensed.