ForbesLindesay/redux-optimist

How to use this together with redux-promise-middleware?

ir-fuel opened this issue · 1 comments

This react/redux stuff is getting pretty complicated I must say, when looking at dependencies to solve different issues ( react-router, redux-router, redux-thunk ...) and making them play together is quite a challenge, so here is another one:

I currently use redux-promise-middleware to do promise based async actions. For each action this middleware automatically generates _BEGIN, _SUCCESS, _ERROR actions that are dispatched to the reducer.

A promise based action looks like this:

export function createPromiseAction(type, promise, metaData = {}, promiseTypeSuffixes = ['BEGIN','SUCCESS','ERROR']) {
  return {
    type,
    payload: {promise},
    meta: {promiseTypeSuffixes, metaData}
  }
}

Is there a way to combine this with this library so the _ERROR ones do the revert, and the _SUCCESSones do the commit?

Hey @ir-fuel, you should check redux-optimist-promise package. It is a combination of redux-optimist and redux-promise-middleware.

https://www.npmjs.com/package/redux-optimist-promise