-
Notifications
You must be signed in to change notification settings - Fork 46
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
Swap promises for ES6 generators and ES7 async await #37
Comments
That api would require end users to use babel though, correct? |
We would just need to use babel in the build process I think? I'm not sure how well it would play with people using McFly in their browserify/webpack/POJ workflow. |
What do you think about somehow exposing an async prop on an action creator that will allow users to explicitly dispatch? |
Pseudo code an example? |
|
With the above example, MyActions.getPost(param) would still work, async being a special property that doesn't call dispatch implicitly. |
Have been using async await in action creators anyway and it works nicely |
Can I see how you're doing that? |
Just compiling with babel, runtime and experimental set, here's an example I've just poached and simplified from our src: let ItemActions = flux.createActions({
async createItem(item){
try {
let { id, parentId } = item
, newItem = await itemGateway.createItem(item)
, page = await fetchPage(id, parentId, ItemsStore.getPage())
, selectedItem = await selectItem(newItem);
return {
actionType : ItemConstants.CREATE_ITEM,
item : newItem,
items : page.items,
page : page.page,
selectedItem : selectedItem.item,
}
} catch(e) {
return {
actionType: AppConstants.NOOP
}
}
}, |
Holy shit, that's phenomenal |
This all works as we wrap action creators in promises :) Tempted to enable babel playground too.. would allow working with memo functions, and static properties for React 0.13 class propTypes and defaults. Lots of goodies! |
I feel this would greatly improve the API usage and also improve error handling - making the code much clear to avoid things like the dirty
reThrow
function that lives inside Action.This would require using the babel compiler (6to5) which also supports JSX if mcfly ever goes the route of involving any JSX.
e.g. Currently:
Would become, something like this (maybe?):
Which reads much nicer imo and is forward thinking.
It would also help with #36
The text was updated successfully, but these errors were encountered: