-
Notifications
You must be signed in to change notification settings - Fork 142
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
Relax requirement to not update state for statuses other than "success" / "error" #1
Comments
Could you give me more details? Quoting from README:
|
Ah, do you mean that this requirement should be lifted?
Thinking about it more that's probably a good idea. The consumer should be allowed to choose whether or not to respond to it. |
Yep. Lifted or somehow amended. |
One complication is that such status might need to be treated like success in some cases. No specific examples yet, but I can come up with one if needed. Possible solution is to introduce another special status for pending. |
Would it be worth considering |
@trabianmatt What would the special meaning be? How should the consumer interpret it? |
Consumer (reducer) might apply an optimistic update. Also, UI could display some visual indication (a loader or a notification). The former has been discussed elsewhere, and the latter might be a separate action. The more I think about it, the less I like an idea of the |
Both of those feel like separate action types to me. Think of an action as being a part of a stream of actions with the same type. If you think about other kinds of streams — let's use RxJS as an example — a subscriber to a stream (in this analogy, that's our store or reducer function) has
There's also So a status of Maybe we should rename |
Rx has great abstractions, I always enjoy using them. Agree with your reasoning here.
Did you consider having a falsy (or missing) |
Yes, that's actually what Flummox does, but having a single |
Let's see what others think, but now I like the |
Now that I see how |
I think part of the issue is we need a way to identify when an action has "started". @acdlite you mentioned how a flux stream never completes, which is true, but within that stream there are sequences of actions that do begin and complete. Perhaps there is a way we could identify a sequence, which would consist of a start, complete and In the case of the [
{ type: 'LOAD_MEDIA', mediaId: 42, sequence: 0 },
{ type: 'LOAD_MEDIA', mediaId: 42, sequence: 1, payload: { progress: 10 } },
{ type: 'LOAD_MEDIA', mediaId: 42, sequence: 2, payload: { progress: 67 } },
{ type: 'LOAD_MEDIA', mediaId: 42, sequence: 3, payload: { progress: 84 } },
{ type: 'LOAD_MEDIA', mediaId: 42, sequence: 4, status: 'success', payload: { id: 42, path: '...' } },
] The above example is a bit contrived since a progress action could be handled with a different |
I agree this is a common pattern, just not sure if belongs in the spec... Maybe as an extension, but not part of the core. Let's keep thinking about it. |
@tappleby each of those actions may be considered to have status "success" if we define the latter as "no error". Depending on needs and priorities of a specific project, at least a few alternative solutions are possible:
One of these, or some more specific/generic approach might become part of some spec extension, after at least 1-2 implementations are available and battle-tested in production projects. Alternatively, they may be described as recipes and simply go to the documentation. NOTE: there are many more cross-cutting concerns like this. E.g., ability to cancel a series of actions, retry failed operations, etc. |
A better name might be // Action
createAction('FETCH_THING', async id => {
const res = await api.fetchThing(id);
return res.body;
});
// Reducer
handleAction('FETCH_THING', {
begin(state, action) {
return { ...state, pending: true };
},
success(state, action) {...},
error(state, action) {...}
}); |
@trabianmatt In that example, what does the action payload look like in Another problem with that API is mixes up separate concerns: In redux-actions v0.6, the handlers were renamed to What about something like this? handleAsyncAction('FETCH_THING', {
begin(state, action) {...},
end: {
success(state, action) {...},
error(state, action) {...}
}
}); |
Closing this since the original issue was about |
Please continue any further discussion over here #7 |
I'd like to be able to handle the fact that some async action has started, and have state reflex that.
The text was updated successfully, but these errors were encountered: