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

Support returning multiple actions from mapPropsToAction and mapPropsToRequest #6

Description

@simenbrekken

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions