gravplats / redux-batch-middleware

[unmaintained] Batch Redux actions
MIT License
22 stars 2 forks source link

Thunk support #1

Open dpwrussell opened 8 years ago

dpwrussell commented 8 years ago

Any idea if you will extend this with thunk support?

I gave it a try and dispatching an array with a thunk in it, the thunk was not executed.

One plus over redux-batched-actions is that at least when dispatching a thunk as normal in redux, this middleware does not swallow it. I was looking for something to batch thunks however.

Cheers

otakustay commented 7 years ago

In my point of view redux-batch-middleware doesn't need to be such complicated, it doesn't require a wrap to reducer, just receive arrays and dispatch them one by one is enough:

export const batch = ({ dispatch }) => {
    return (next) => (action) => {
        return Array.isArray(action)
            ? action.forEach(dispatch)
            : next(action);
    };
};

And in the way any thunk or other type of actions are allowed natively

ppoliani commented 7 years ago

Ideally, that should be the responsibility of another middleware; e.g redux-thunk

I have created a PR that will deal with non-FSA actions in the array. The idea is that if there is an action that some other middleware can process then we just dispatch them one by one.