-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Flux Standard Action #205
Comments
I like the idea. So basically like a "json-schema", only for actions, right? |
Interface instead of assumptions? The overall idea is great, but there are lots of options how to achieve it. One of possibilities is to define an "interface" (a set of functions that a user can provide) which would give users full control. This might work best if I have no specific suggestions yet, because for making them it would be better to examine several popular action "schemas" first. For example, current FSA version would require a change to a popular pattern of Drawback of using |
@emmenko Pretty much, except much more limited in scope.
This is the point of defining a standard, right? To agree on some basic conventions so we can build tools around it.
Yes, this is a popular pattern today, but it can easily be expressed using FSA's
You wouldn't have to use isSuccess / isError. The code for both is very simple. It's mostly just there as a reference implementation. |
Take a look at the source of redux-promise as an example: https://github.com/acdlite/redux-promise/blob/master/src/index.js#L15-L20 |
Exactly. My point is that it might (but might not) be better to give users control and give middleware some "interface".
What I meant was that for Another point was that not all actions are either success or error. "Something has been requested" may have impact on state as well. |
You can still have separate reducers. The reducer just needs to check the status. See redux-fsa's |
What I suggest is to discuss a few popular alternative action schemas somewhere, then think about best way to standardise. |
Adding some boilerplate.
This looks very nice to me. |
@clearjs Sure, of course, this standard isn't set in stone by any means. This initial version is based on my specific experiences with Flummox, but I'm totally open to changing and evolving it. The most important thing is that it's something the community can agree upon. |
How to organise this discussion best? Maybe create one issue in the FSA repo per a schema that somebody uses in real life? UPDATE: thinking more about this, the |
Another thing to note is that a middleware like redux-promise simply doesn't work with the @clearjs Yeah, for in depth discussion of this it's probably best to open issues in the FSA repo. |
@gaearon I know you're busy this week but I'd love to hear your thoughts, as well! |
EDIT: @acdlite I was still thinking in general, but now see that your remark is specific to |
@acdlite, when you said:
Could you briefly state how that would be structured? I'm having a little bit of a hard time understanding how the order of middlewares would affect a thunk-dispatching-a-promise verses a promise-returning-a-thunk. Also if I'm programming with promises having to fall back to a hand-written thunk rather than just using the ES7 async functionality wouldn't be my first choice. But like I said I'm not completely clear on what's going on here, so it may make perfect sense. |
(Also, is it legal to dispatch multiple times from a thunk-handled action? Glancing at the code I'd say yes, but...) |
@bdowning Yes, it is legal :) The reason for not dispatching at the beginning is because usually when doing optimistic updates, you need to dispatch certain information like an id or a timestamp. Since there's no obvious pattern for how to do this, for now I'm suggesting that redux-promise users just use the thunk middleware. Basic example: // Relies on both thunk and promise middleware
createAction('FETCH_SOMETHING', id => {
// Thunk will be handled by thunk middleware
return dispatch => {
// Trigger optimistic update
dispatch({ type: 'FETCH_SOMETHING_BEGIN', body: { id } });
// Promise will be handled by promise middleware
return api.fetch(id);
}
}); We're considering adding another status type besides |
@acdlite And just to check, for your example to work is there a specific ordering of thunk and promise middleware that has to be installed, or would any order work? -bcd |
I'll take a look soon. Too tired :-) |
The main problem with this standardization process is I think that this kind of "actions" should be generic and this question shouldn't be exists at all. Also I found that other aspects Flux architecture itself is unnecessary overcomplicated in general. |
@acdlite I really like this FSA idea 👍 in fact I use this But I'm not sure about the I mean, this switch (action.type) {
case FETCH_DATA:
// ..
break
case FETCH_DATA_SUCCESS:
// ..
break
case FETCH_DATA_ERROR:
// ..
break
} is much more simpler than this switch (action.type) {
case FETCH_DATA:
if (action.status === 'success') {
// ..
} else if (action.status === 'error') {
// ..
} else {
// ..
}
break
} Don't you think? That's my 2c |
@acstll There is an interesting discussion on this topic here: redux-utilities/flux-standard-action#1, and apparently in the #redux Slack channel as well. |
@acstll The reason for a handleAction('FETCH_DATA', {
success(state, action) {...}
error(state, action) {...}
}); https://github.com/acdlite/redux-fsa#handleactiontype-reducer--reducermap |
I'm closing, as it's not a Redux issue, and it has been dormant for a while. |
I whipped together this minimal standard for Flux actions. Quoting from the README:
I came up with these initial specs based on my experience with Flummox, which internally uses a similar pattern for action handling. The key difference is that with Flummox, the implementation was baked into the core, whereas Redux allows us to take a much more modular, flexible approach.
I absolutely don't think this should be part of the Redux core, but it'd be nice to encourage middleware/extension users support this standard (or something like it) so that they're all interoperable.
To see an example of how FAS is useful, see this section of redux-promise.
Thoughts? Would love to receive feedback.
EDIT: Forgot to mention that I created some tools for creating and handling FSA actions in Redux. Look at
handleActions()
in particular for an example of how to create a reducer that handle multiple actions https://github.com/acdlite/redux-fsa#handleactionsreducermap-defaultstate.The text was updated successfully, but these errors were encountered: