Redux Combine Actions
This is a Redux middleware that allows you to easy combine actions and dispatch them sequentially.
Installation
npm install --save redux-combine-actions
Usage
Manual TBD
import combineActionsMiddleware from 'redux-combine-actions';
Simple usage
export function addTodo(text) {
return { type: types.ADD_TODO, text };
}
export function increment() {
return { type: INCREMENT_COUNTER };
}
export function addTodoAndIncrement({text}) {
return {
types: [
'COMBINED_ACTION_START',
'COMBINED ACTION_SUCCESS',
'COMBINED ACTION_ERROR'
],
payload: [addTodo.bind(text), increment]
};
}
Using in combination with redux-promise-middleware.
export function getProviders() {
return {
types: [
'PROVIDERS_GET_PENDING',
'PROVIDERS_GET_SUCCESS',
'PROVIDERS_GET_ERROR'
],
payload: api.getProvidersAsync()
};
}
export function getSubscribers() {
return {
types: [
'SUBSCRIBER_GET_PENDING',
'SUBSCRIBER_GET_SUCCESS',
'SUBSCRIBER_GET_ERROR'
],
payload: api.getSubscribersAsync()
};
}
export function fetchData() {
return {
types: [
'DATABASE_FETCH_PENDING',
'DATABASE_FETCH_SUCCESS',
'DATABASE_FETCH_ERROR'
],
sequence: true,
payload: [getProviders, getSubscribers]
};
}
License
MIT