1.2.3 • Published 6 years ago
redux-soldier v1.2.3
Getting started
npm install redux-soldierThen, to enable redux-soldier, use applyMiddleware():
import { createStore, applyMiddleware } from 'redux'
import { reduxSoldierMiddleware } from 'redux-soldier'
import rootReducer from './reducers'
const store = createStore(rootReducer, applyMiddleware(reduxSoldierMiddleware))What can redux-soldier
It can dispatch thunk actions, if provided argument is a function. In this case works same as redux-thunk
dispatch(fetchUser()) // thunk action
// also it can dispatch multiple thunk actions
dispatch([
fetchUser(), // thunk action
fetchUserWishList(), // thunk action
])It can dispatch multiple actions, if provided argument is an array of actions.
dispatch([
addToDo('Learn how to use redux-soldier 👨🏼✈️'), // traditional action creator
{ type: 'INCREMENT' }, // traditional action
])It can dispatch multiple mixed actions, if provided argument is an array of actions.
dispatch([
fetchUser(), // thunk action
addToDo('Learn how to use redux-soldier 👨🏼✈️'), // traditional action creator
{ type: 'INCREMENT' }, // traditional action
])It can return a promise or array of promises if provided argument is a async thunk action or an array of thunk actions.
Note: if is provided an array of mixed actions it returns only an array of thunk actions promises
dispatch(fetchUser()).then(response => {
/* do stuff */
})
// or multiple thunc actions
dispatch([
fetchUser(), // thunk action
fetchUserWishList(), // thunk action
]).forEach(promise => {
promise.then(response => {
// do stuff
})
})Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
Or you can sponsor via Open Collective
Author
@Gherciu/redux-soldier © GHERCIU, Released under the MIT License. Authored and maintained by GHERCIU with help from contributors (list).