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
Currently, it is not possible to compose actions.
The input type emitter and the pass in type emit does not match.
Also, the action needs to be able to return value, e.g. a Return generic may be needed.
To do this, may need to go back to redux or flux structure, where there is a separate dispatch function from the store.
In this case, it means the emitter needs to be able to produce a detached emit method, scoped with the right Payload dynamically, per composition down the chain.
constadd=createEventAction<{a: number,b: number},{a: number,b: number,result: number}>('add',({ a, b })=>emit=>{emit({ a, b,result: a+b})returna+b})constmultiply=createEventAction<{a: number,b: number},{a: number,b: number,result: number}>('multiply',({ a, b })=>emit=>{lettotal=0for(leti=0;i<a,i++){total+=add(emitter,{0, b },undefined)// missing emitter in this context}emit({ a, b,result: total})returntotal})constemitter=newEmitter()multiply(emitter,{a: 3,b: 3},undefined)// returns 9
If we try to do the same without EventAction, we need to work on the Event.type without scoping support and we missed the auto handling of isError.
One idea is to make the emitter.emit binded to begin with, and pass in emit only:
constadd=createEventAction<{a: number,b: number},{a: number,b: number,result: number}>('add',({ a, b })=>emit=>{emit({ a, b,result: a+b})returna+b})constmultiply=createEventAction<{a: number,b: number},{a: number,b: number,result: number}>('multiply',({ a, b })=>emit=>{lettotal=0for(leti=0;i<a,i++){total+=add(emit,{0, b },undefined)}emit({ a, b,result: total})returntotal})constemitter=newEmitter()multiply(emitter.emit,{a: 3,b: 3},undefined)// returns 9
Currently, it is not possible to compose actions.
The input type
emitter
and the pass in typeemit
does not match.Also, the action needs to be able to return value, e.g. a
Return
generic may be needed.To do this, may need to go back to
redux
orflux
structure, where there is a separatedispatch
function from thestore
.In this case, it means the
emitter
needs to be able to produce a detachedemit
method, scoped with the rightPayload
dynamically, per composition down the chain.If we try to do the same without
EventAction
, we need to work on theEvent.type
without scoping support and we missed the auto handling of isError.The text was updated successfully, but these errors were encountered: