- Notifications
You must be signed in to change notification settings - Fork27
support payload-less async action creator#15
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Looks good. Please fix linter error and I'll merge it. |
024cd7d to45490d7CompareThanks! |
lauritzsh commentedMay 13, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I could use this in my application as well. Are there any scheduled plans for an update to npm so we can use this? It seems really useful. Just to be sure; this let us skip the typeIPost={title:string};typeErrorMessage=string;constfetchPosts=actionCreator.async<IPost[],ErrorMessage>('FETCH_POSTS');fetchPosts.started();fetchPosts.done([{title:'Hello'},{title:'World'}]);fetchPosts.failed('Could not retrieve posts!'); Would it also make this possible? typePostId=number;typeIPost={title:string};typeErrorMessage=string;constfetchPosts=actionCreator.async<PostId,IPost[],ErrorMessage>('FETCH_POSTS');fetchPost.started(23);fetchPost.done([{title:'Hello'},{title:'World'}]);fetchPost.failed('Could not retrieve posts!'); I have a hard time seeing where you would use the same Thanks for helping me type checking my actions more easily with this library! |
I'll make a release to NPM in a few moments. Async action creators are intended to wrap some async process, like a promise. The This PR makes it possible for constemptyAsync=actionCreator.async<undefined,{foo:string},{bar:string}>('EMPTY_ASYNC');conststarted=emptyAsync.started();constdone=emptyAsync.done({result:{foo:'foo'}});constfailed=emptyAsync.failed({error:{bar:'bar'}}); Without this PR you'd had to write conststarted=emptyAsync.started(undefined);constdone=emptyAsync.done({params:undefined,result:{foo:'foo'}});constfailed=emptyAsync.failed({params:undefined,error:{bar:'bar'}}); |
Released as |
lauritzsh commentedMay 14, 2017
Perfect, thank you so much! I initially read moment as months and got worried for a second. :-) I will update my code now to use this async action creator that will cut down some of my boilerplate. I am just curious that if we can skip I don't know if it possible to express but if the first type is I guess this won't matter now anyway since it would result in breaking changes and thus require 3.0.0 which is not worth it. I am just curious to learn more really. |
Unfortunately, in TS So, for now, the best we can do is Also, in my experience, there aren't many cases for calling async action creators manually. Async processes are usually expressed as functions returning promises (or generators in case of |
I'm sorry, but I have to revert this. For some reason, after this change, we can't instantiate async action creators with payload, i.e. TypeScript always chooses the first signature of these two: async<undefined,S,E>(type:string,commonMeta?:Object|null,):EmptyAsyncActionCreators<S,E>;async<P,S,E>(type:string,commonMeta?:Object|null,):AsyncActionCreators<P,S,E>; even if we call I couldn't quickly find a way to make it work, so we have to fall back to the old typings. |
lauritzsh commentedMay 22, 2017
That is understandable if it breaks code. Would it make sense to just rename How about usinggeneric parameter defaults in TypeScript 2.3 or is it still a problem? |
@lauritzsh I don't really like adding another method, I prefer to keep API surface as small as possible. Also if we add another method for empty I'm not sure how generic defaults would solve this, but if you find a working solution, please let me know. |
Fixed in3.0.0-beta-1. |
I guess
typescript-fsacan't create no argument AsyncActionCreators now.I don't know what style is good, however I want it.
#14