/iterux

Store for JavaScript applications using collections to update the state.

Primary LanguageTypeScriptMIT LicenseMIT

Iterux

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

Inspired by Redux and Redux Zero.

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, increment, decrement, decrement, increment, alterState ]); 
// state becomes: { counter: 2 }, { counter: 3 } ..., { counter: 2 }, { state: 'altered' } - every update overwrites the state!