markdalgleish/redial

multiple dispatches inside fetch

walshe opened this issue · 6 comments

finally realised after anout 2 weeks that a return is needed on the last dispatch (if you have multiple dispatches) inside the fetch.

Why is this exactly ? might be no harm to put in the docs btw

`const redial = {

/**

  • this is triggered from server/index.js
    */
    fetch: ({ dispatch, params: {filter} }) => {

     //get filter data
     dispatch(loadFilterData())
    
     //kick off a default search
     return dispatch(loadUnlistedVins())
    

    }
    }`

hnq90 commented

@walshe You should try Promise

example ?

Had the same problem. @hnq90 just use Promise.all

const redial = {
  fetch: ({ dispatch }) => Promise.all([
    dispatch(fetchCurrentUser()),
    dispatch(fetchCategories())
  ])
}

So does this mean dispatch needs to return a Promise? Does it work with redux-api-middleware? I'm thinking about switching over to redial

Oh yes, the promise is stated in the doc. Any one having this work with redux-api-middleware?

Aryk commented

@EJIqpEP

Just curious, in your example, if fetchCurrentUser, returns a Promise, do you need special middleware so that dispatch(fetchCurrentUser()) returns a Promise or does this just work out of the box?