React on actions [possible improvement suggestion]
ssijak opened this issue · 4 comments
ssijak commented
Is it possible to react to actions? Something like
reaction(
(actions) => actions.uberAction,
(state, actions, actionParams) => {
//do something after the action was called?
},
)
abalmos commented
@ssijak You could just make a new action that calls both
export const newAction = ({actions}) => {
actions.uberAction();
// do something after the action was called.
}
// Call the new action rather then actions.uberAction
actions.newAction();
or if you always want the extra work, just add it to uberAction
directly
ssijak commented
Yeah. I was just thinking that I could have some general utility actions, like log functions which would log action calls somewhere, and then I would not need to change the other actions code and could just add reactions to ones I am interested to "decorate".
lavir commented
For that, you can try to use events
christianalfoni commented
All good suggestions here, you could also just use functional patterns, like factory
:
const log = (context, action) => {
console.log('Calling ', action.name)
return action(context)
}
const uberAction = log(() => {
})
Or even just Overminds own functional API:
const ubAction = pipe(
log('uberAction'),
() => { /* uberAction */}
)
NOTE! Shown with next
API, coming soon