What about setState?
See original GitHub issueRecently effects
and reducers
got merged into actions
. Now the way to set the state is by just retuning an object.
What about exposing a actions.setState
function which can be called from everywhere where actions
are available instead? This way an effect could still return whatever it wants when called by a different action (I actually used that a lot) and code like this becomes easier to do:
function example () {
actions.room.set(room) // reducer
actions.room.socket.join() // effect
// the key here is that socket.join depends on model.room
}
function example () {
actions.setState({room})
actions.room.socket.join()
}
This would also fix use-cases where big actions need to be split into multiple actions, but need to return data that is not a promise. Hard to describe, but I actually also used that for WebRTC SDP patching. I worked around this, but overall I think that this might make hyperapp easier to use for more advanced apps.
And yes, I’m aware that setState()
would basically be implemented as setState: (_, data) => data
.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:51 (30 by maintainers)
Sorry, I don’t understand. There is only one way to update the model.
Yeah, now I finally understand what we are talking about.