Recently 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.
Recently
effects
andreducers
got merged intoactions
. 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 whereactions
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: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 assetState: (_, data) => data
.