You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 8, 2020. It is now read-only.
/** * Process and persist an entity * @param request * @param response */
@Route('PUT','/:id')publicputOne(request: Request,response: Response): Promise<Response>{returnrequest.getPayload().then((data:any)=>this.modelStore.hydrate(data)).then((model:M)=>this.modelStore.validate(model)).then((model:M)=>this.modelStore.saveOne(model)).then((model:M)=>response.data(model));}
to this:
/** * Process and persist an entity * @param request * @param response */
@Route('PUT','/:id')public*putOne(request: Request,response: Response): IterableIterator<any>{const payload =yieldrequest.getPayload();constmodel=yieldthis.modelStore.validate(payload);yieldthis.modelStore.validate(payload);constsavedModel=yieldthis.modelStore.saveOne(model);returnyieldresponse.data(savedModel);}
dummy POC impl:
classFooControllerextendsResourceController<any>{}letc=newFooController(null,null,null);constiterator=c.putNOne(null,null);varvalue:any;do{var{value, done}=iterator.next(value);}while(!done);constresponse:Response=value;//not sure yet how to actually resolve the async data out - check if thenable, or thunk?
Pro/Con:
👍 Simpler async expressions
👎 Less familiar syntax for those used to promises
👎 Needs refactor
👍 Exceptions are easier to handle, but having both supported may mean two exception handling strategies
👍 Iterators/Generators are all the rage
👎 Typescript can't declare the final yielded type so every method will have signature *method():IterableIterator<any> unless I'm missing something?
Additional Comment from zakhenry
Holding off on this, as despite being super cute, not being able to strictly define the final yield type is a bit of a deal breaker
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It changes
this
to this:
dummy POC impl:
Pro/Con:
yield
ed type so every method will have signature*method():IterableIterator<any>
unless I'm missing something?Additional Comment from zakhenry
Holding off on this, as despite being super cute, not being able to strictly define the final yield type is a bit of a deal breaker
The text was updated successfully, but these errors were encountered: