Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject after dispatching error action. #13

Merged
merged 1 commit into from May 12, 2016

Conversation

tappleby
Copy link
Contributor

The current behaviour might be intentional but I ran into an issue this evening where calling then on a dispatched promise would always result in being fulfilled:

dispatch({
  type: 'ACTION_TYPE',
  payload: Promise.reject(err)
}).then(() => console.log('fulfilled'));

// Output: fulfilled

This PR will reject the error after dispatching the action.

@olimsaidov
Copy link

Is this going to be merged?

timdorr added a commit to showcaseidx/redux-promise that referenced this pull request Dec 9, 2015
error => {
dispatch({ ...action, payload: error, error: true });
return Promise.reject(error);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's one simpler way that is returning the original promise (action.payload) instead of returning the result of action.payload.then()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't that result in a race condition where the user-attached .then can run before the dispatch call?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kovensky No, javascript is single threaded. Promise handlers are executed in the order they are added.

@npbee
Copy link

npbee commented Jan 15, 2016

I agree with @Qrysto that I think we need to branch off the original promise to dispatch the actions, but ultimately return the original promise from action.payload.

I think what's happening here is that the middleware is essentially inserting a .catch into the promise chain, which causes the chain to "recover" and carry on with the chain. A .then after a .catch will receive the return value from the .catch. You can see an example here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch#Examples

There's a related issue here: #23

@gregmuellegger
Copy link

I also stumbled upon this issue, and would really appreciate to see this resolved. Any plans on merging this?

@bartvanandel
Copy link

Is @acdlite monitoring this pull request? We are running into the same issues the OP has and this would definitely solve those issues.

@dreampulse
Copy link

Please create a new npm version with this code! :-)

@wwalser wwalser mentioned this pull request Jun 20, 2016
@dreampulse dreampulse mentioned this pull request Jun 27, 2016
benmosher added a commit to answerrocket/redux-promise that referenced this pull request Jul 29, 2016
benmosher added a commit to answerrocket/redux-promise that referenced this pull request Jul 29, 2016
@itaysabato
Copy link

This is a big breaking change and I'm not sure why it was needed - the reducer or next middleware in the chain can easily throw back all error-actions.

With this change code that relies on rejections being transformed to error-actions and dispatched onward is broken and needs to add an additional handler for the new rejection in addition to the error-action handling.

It also takes away from the next middleware the ability to affect the return value of the dispatch.

Is it possible to at least add a configuration option to keep it the way it was?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants