在 scalajs-react 中将 StateSnapshots 与后端一起使用
Use StateSnapshots with a Backend in 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
我在行 val surnameV = StateSnapshot.zoomL(Name.surname).of(name)
中得到编译错误 value firstName is not a member of object app.TreeView.Name
。
通过使用 .setStateVia($)
而不是 .of($)
解决了 GitHub 问题。
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
我在行 val surnameV = StateSnapshot.zoomL(Name.surname).of(name)
中得到编译错误 value firstName is not a member of object app.TreeView.Name
。
通过使用 .setStateVia($)
而不是 .of($)
解决了 GitHub 问题。