1.0.4 • Published 3 years ago

redux-batched-actions-thunk v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Usage

This library is a frankenstein from redux-auto-batched-actions, redux-batched-action and redux-thunk

import { createStore, applyMiddleware } from 'redux';
import { enableBatching } from 'redux-batched-actions';
import { autoBatchingMiddleware } from 'redux-auto-batched-actions';

const setA = payload => ({type: 'SET_A', payload});
const setB = payload => ({type: 'SET_B', payload});

const reducer = (state={a:0, b:0}, action) => {
    switch (action.type) {
        case 'SET_A': return {...state, a: action.payload}
        case 'SET_B': return {...state, b: action.payload}
        default: return state
    }
}

const saySmthGreat() => console.log('great!')

// Handle bundled actions in reducer
const store = createStore(
    enableBatching(reducer),
    applyMiddleware(autoBatchingMiddleware(
        // thunkExtraArgs
        { saySmthGreat }
    ))
);

store.dispatch([setA(1), setA(2), setB(5)]);

store.getState();
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago