在scalajs-react中使用带有后端的StateSnapshots

时间:2017-08-02 15:09:59

标签: scalajs-react

StateSnapshot example中的主要组件不使用后端,但我需要一个。我的尝试:

class MainBackend($ : BackendScope[Unit, Name]) {
  def render(name: Name) = {
    val firstNameV = StateSnapshot.zoomL(Name.firstName).of(name)
    val surnameV = StateSnapshot.zoomL(Name.surname).of(name)
    <.div(
      <.label("First name:", NameChanger(firstNameV)),
      <.label("Surname:", NameChanger(surnameV)),
      <.p(s"My name is ${name.surname}, ${name.firstName} ${name.surname}.")
    )
  }
}

val Main = ScalaComponent
  .builder[Unit]("StateSnapshot example")
  .initialState(Name("John", "Wick"))
  .renderBackend[MainBackend]
  .build

我在行value firstName is not a member of object app.TreeView.Name中收到编译错误val surnameV = StateSnapshot.zoomL(Name.surname).of(name)

1 个答案:

答案 0 :(得分:0)

使用.setStateVia($)代替.of($)解决GitHub问题。