General questions should be asked on StackOverflow, not here. This room focuses on development of Binding.scala.
Atry on master
Update scalafmt-core to 2.3.2 Merge pull request #230 from sc… (compare)
Binding { val store = binding.bind; Future { var.value = store} }.watch
to break out of Binding context
Var
for its internal state in a way that it can also respond to some external change... seems tricky to do it without var, and how else do I hook up external.bind -> inputelem.value
? The other thing I thought of was to completely recreate my input component in response to external change but I was trying to avoid that.
Var
is always the source of the onchange event, not a intermediate node.
MountPoint
has more control to life cycle of event handlers than Binding
blocks.
Var
directly, then it's not your solution.
Binding
that controls it for some less common cases seems dirty. What I have working now is that when the location changes, the select box object itself gets recreated, this instantiates a new Var
but doesn't manipulate an existing one.
Binding[Event => Unit]
types as well.
// some helpers for binding.scala
@dom def futureBindingToBinding[T](futureBinding: Binding[Option[Try[T]]], emptyVal: T): Binding[T] = futureBinding.bind
.map((y:Try[T]) => y.get)
.getOrElse(emptyVal)
@dom def futureBindingToBindingSeq[T](futureBindingSeq: Binding[Option[Try[Seq[T]]]], emptyVal: Seq[T]): Binding[BindingSeq[T]] = {
val tmpSeq: Seq[T] = futureBindingSeq.bind
.map((y: Try[Seq[T]]) => y.get)
.getOrElse(emptyVal)
val x: BindingSeq[T] = Vars(tmpSeq: _*)
x
}
val v1:Any = 1
@dom
val v2 = Binding {
v1 match {
case x:String => <p>str</p>
case x:Int => <p>int</p>
}
}
@dom
def render = { <p>{v2.bind}</p> }
dom.render(document.body, render)