- Source:
Methods
-
createAsyncActionHandler(asyncConfig)
-
Creates an async action handler with a signature as used in redux-actions: (state, action) => newState It will respond to different async states of the action, based on the passed configuration object.
Parameters:
Name Type Description asyncConfigObject The async configuration object
Properties
Name Type Argument Description pendingfunction <optional>
The action handler to be called when the action is a pending (not resolved or rejected) action
rejectedfunction <optional>
The action handler to be called when the action is a rejected action
resolvedfunction <optional>
The action handler to be called when the action is a resolved action
- Source:
Returns:
The action handler
- Type
- function
-
handleActionsAsync(reducerMap, defaultState)
-
Enhanced version of the redux-actions handleActions utility. It has the same API as the handleActions function, but allows for async action handlers in the reducerMap parameter. Instead of passing a callback function for a specific action type, an object can be passed with callback functions for each stage of an asynchronous action. For more info, see
createAsyncActionHandleror the example below.Parameters:
Name Type Description reducerMapobject The reducer map config
defaultStateThe default state for the reducer. See the redux-actions handleActions docs for more info.
- Source:
Returns:
The resulting reducer function
- Type
- function
Example
handleActionsAsync({ // regular handleActions syntax is still supported INCREMENT: (state, action) => ({ counter: state.counter + action.payload }), // asynchronous action GET_ARTICLES: { pending: (state) => ({ ...state, articlesLoading: true }), resolved: (state) => ({ ...state, articlesLoading: false, articles: action.payload.articles, }), }, }, { counter: 0, articlesLoading: false, articles: []});