smallorange-unistore-batch-reducers

Simple batch reducers for https://github.com/developit/unistore

Usage no npm install needed!

<script type="module">
  import smallorangeUnistoreBatchReducers from 'https://cdn.skypack.dev/smallorange-unistore-batch-reducers';
</script>

README

CircleCI

Simple batch reducers for https://github.com/developit/unistore

Sample

    const store = unistore.createStore({
        a: 1,
        b: 2
    });

    const reducers = {
        one: (state, add = 1) => ({
            a: state.a + add,
            b: state.b + add
        }),
        two: (state, add = 1) => Promise.resolve({
            a: state.a + add,
            b: state.b + add
        }),
        three: () => null,
        four: () => Promise.resolve(null),
    };

    batchReducers(store, [
            reducers.one, 2
        ], [
            reducers.two, 2
        ],
        reducers.three,
        reducers.four
    )
    .then(state => {
        // state === {a: 5, b: 6}
    });