Let effects return the `actions` object
See original GitHub issueActions are functions you call like actions.myAction(data)
. When you call an action, HyperApp checks if it belongs to effects
or reducers
, then:
- for
reducers
- applies the reducer to update the model,
newModel = reducer(oldModel, data)
- applies the reducer to update the model,
- for
effects
- calls the effect
effect(data)
- calls the effect
Finally, the action function returns (undefined).
The proposal is, amend the previously described behavior, and return the actions
object instead.
This would allow chaining effects / reducers.
Effects
Effects, can be asynchronous, so we must return a Promise to make sure they are executed in order.
actions.myReducer1().myReducer2().myEffect1().then(actions.myEffect2).then(actions.myEffect3)
app({
effects: {
bigEffect: async (model, actions, data) => {
actions.myReducer1().myReducer2()
await actions.myEffect1()
await actions.myEffect2()
actions.myReducer3().myReducer4()
}
}
})
Reducers
Reducers are sync, so there’s no need to return a promise in this case.
actions.myReducer1().myReducer2()
Notes
- Chaining reducers should be limited to reducers, otherwise you’d end up using them like an effect which is wrong. Why? Because reducers cause the view to be re-rendered.
- There’s no need to re-render after each reducer, so this mechanism should try to be efficient. Also related: https://github.com/hyperapp/hyperapp/issues/90
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:11 (6 by maintainers)
Top Results From Across the Web
let - JavaScript - MDN Web Docs
The let declaration declares a block-scoped local variable, optionally initializing it to a value.
Read more >React useReducer Hook ultimate guide - LogRocket Blog
An action: An object that tells the reducer how to change the state. It must contain a type property and can contain an...
Read more >Side-effects in Compose - Android Developers
A side-effect is a change to the state of the app that happens outside the scope of a composable function. Due to composables'...
Read more >Apply multiple animation effects to one object - Microsoft Support
Open the Animation Pane. Select the object on the slide that you want to animate. On the Animations tab, click Animation Pane. Open...
Read more >API Reference - Redux-Saga
Creates an Effect description that instructs the middleware to wait for a specified action on the Store. The Generator is suspended until an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think sticking as closely as possible to the Elm Architecture is the biggest selling point, otherwise it will become like CycleJS.
It shouldn’t if we’re using requestAnimationFrame, but TBH I don’t know if I’d like to proceed with this feature, it seems it creates more of an anti-pattern than anything else.
The thing, sometimes you’d like to run several reducers, so instead of:
you could do:
Effect actions, return what your effect function returns, so you can return a promise which is fine.