Skip to content

Clarify semantics of set/modState #410

Closed
@tgiddings

Description

@tgiddings

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 $.modstates are not seen by $.state (but $.modstates effects are seen by eachother, meaning this can be worked around by replacing $.state with $.modstate)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions