0.1.0 • Published 7 years ago

iterux v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Iterux

State container, for JavaScript applications, using arrays as a source of sequential updates.

Inspired by Redux and Redux Zero.

todo

  • Live example
  • React bindings
  • Iterux Cookbook

Installation

npm

npm install --save iterux

yarn

yarn add iterux

Example usage

import { storeFactory } from 'iterux';

const store = storeFactory({ counter: 0 });

store.registerOnStateChangeCallback(state => console.log(state));

function increment(state) {
    return { counter: state.counter + 1 };
}

function decrement(state) {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve({ counter: state.counter - 1 });
        }, 1000);
    });
}

function alterState() {
    return { altered: 'state' };
}

store.update([ increment ]);
// state becomes: { counter: 1 }

store.update([ increment, increment, decrement, decrement, increment ]); 
// state becomes: { counter: 2 }, { counter: 3 } ..., { counter: 2 }

store.update([ alterState ]); 
// state becomes: { altered: 'state' } - every value returned overwrites the state!