Closed
Description
Was: BackendScope's state callback returns state from when callback is constructed rather than from when it's executed
BackendScope
has a state
function that returns a callback. However, it returns the state as of callback construction rather than callback execution. This breaks the callback's composability. e.g.
case class Backend($: BackendScope[Unit, State]) {
def submit = $.modState(s => if(s.username=="") s.copy(usernameMissing = true) else s.copy(usernameMissing = false)) >>
$.modState(s => if(s.password=="") s.copy(passwordMissing = true) else s.copy(passwordMissing = false)) >>
$.state.map{
state =>
if(!state.usernameMissing && !state.passwordMissing) dom.window.alert("Submitted")
}
will popup "Submitted" even if username
and password
are ""
if usernameMissing
and passwordMissing
hadn't already been set. The effects of the $.modstate
s are not seen by $.state
(but $.modstate
s effects are seen by eachother, meaning this can be worked around by replacing $.state
with $.modstate
)