Option to send full response to custom action handlers
We need some way of passing the full API response through to the action creator method. E.g., In the following example I want to be able to set pagination detail returned by the API about the total number of records available.
However, the createFetchAction
factory makes an action creator which only passes the response.data
property through to the async action creator I've defined.
It would also be nice to have whatever is returned from the async action creator passed through as the promise argument down the chain, so I can access this value directly in my React component, but this part isn't necessarily required.
import Blog from 'api/Blog'
import { createFetchAction, createUpdateAction } from 'cd-redux-helpers/dist/actions'
export const updateArticles = createUpdateAction('articles')
export const fetchArticles = createFetchAction(
[Blog.getWhere, { status: 'published' }, '-published'],
(response) => async (dispatch, getState) => {
dispatch(updateArticlesCount(response.pagination.count))
dispatch(updateArticles(response.data))
return response
}
)
export const updateArticlesCount = (count) => ({
type: 'SET_ARTICLE_COUNT',
count
})