-
Notifications
You must be signed in to change notification settings - Fork 28
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
Async actions should return the same type differentiated by an error object #38
Comments
To be honest, I just didn't know that. One reason to have separate action types is that you can distinguish between success and failure in DevTools without having to look inside the action. On the other hand, I kinda like this: // somewhere in reducer
if (isType(action, myAction.finished)) {
if (action.error) {
// error handling
} else {
// success handling
}
} instead of this: if (isType(action, myAction.done)) {
// success handling
}
if (isType(action, myAction.failed)) {
// error handling
} because in the former case the type of Still, inability to see whether an action succeeded in DevTools is a major drawback for me. There's probably a way to have separate action types via single action creator What do you think? |
The DevTools are a valid concern however I think that is small patch away from highlighting actions with certain properties, i.e. if error is true then display action as red. By making errors tied to the same action you will force your reducers to handle it in every instance rather than letting them slip through unhandled. I would rather my code crash hard instead of letting a few unhandled errors pile up and cause a much harder to debug issue. Another benefit is that actions may share cleanup style operations regardless of whether they are successes or errors. And finally, by having a standard action we allow other middleware to operate well. As an example, you may have a generic middleware that captures errors and displays a message to the user so that they may be able to help themselves. |
I started experimenting with discriminating between success and error actions by |
Hi @aikoven, is there any update on this issue? Maybe typescript 3 supports it. I have a javascript app I'm migrating to typescript and uses FSA as defined in the repo, and would love to use typescript-fsa |
Unfortunately not. I've implemented this feature but the compiler still behaves the same way. https://github.com/aikoven/typescript-fsa/compare/error-discriminator-experiment |
From the
flux-standard-action
repo:Was there a particular reasoning to do it with
*_DONE
/*_FAILED
?The text was updated successfully, but these errors were encountered: