Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Support returning multiple actions from mapPropsToAction and mapPropsToRequest #6

Open
simenbrekken opened this issue Mar 6, 2017 · 0 comments

Comments

@simenbrekken
Copy link
Contributor

As of now the following doesn't work:

// Fetch both a product and a page
connectFetchData({
  mapPropsToAction: ({ productId, parentPath }) => (
    Promise.all([
      actions.getProductById(productId),  
      actions.getPageByPath(parentPath)
    ])
  ),
  mapStateToProps: (state, { productId, parentPath }) => ({
    product: state.products.byId[productId],
    page: state.pages.byPath[parentPath],
  }),
})

It's easy to work around this by chaining multiple connectFetchData, but this prevents the actions from being fired in parallel. Ideally one would be allowed to return a Promise, but since we're using mapPropsToRequest to determine loading state this isn't trivial.

I suggest being able to return an array from mapPropsToAction that is dispatched in parallel in the middleware. To compute loading and error state something like this would probably be sufficient:

const loading = requests.some(request => request.loading)
const error = requests.find(request => request.error)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant