State container, for JavaScript applications, using arrays as a source of sequential updates.
Inspired by Redux and Redux Zero.
npm install --save iterux
yarn add iterux
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!