Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

bjornua/coldstorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coldstorage

NPM version build status Downloads

Immutable dispatcher for the flux architecture.

Features

  • Fully immutable API. dispatcher.dispatch returns a new state.
  • Returns immutable facebook/immutable-js objects.
  • Changes can only be initiated by actions
  • Stores can listen to stores
  • Stores can listen to actions
  • Stores can listen to many stores/actions at once

Installing

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).

Example Usage

Creating actions

You create actions by passing an array of strings into coldstorage.createActions:

var actions = coldstorage.createActions(['login', 'logout']);

##Creating the stores

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');
});

Initializing the dispatcher

var dispatcher = coldstorage.fromStores([
    userStore,
    alertStore
]);

Dispatching actions

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

Contribution

Requests and discussion are very welcomed in github issues

Use github pull requests to contribute patches.

License

coldstorage is MIT-licensed.

About

Immutable dispatcher for the flux architecture

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published