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)
Hi, could someone point out what the cause of this error is in the following import com.thoughtworks.binding.Binding.{ Var, Vars }
import com.thoughtworks.binding.dom
import org.scalajs.dom.document
case class Model(name: String, contents: Vars[Double])
@dom
def render = {
val models = Vars(
Model("A Model", VarsDouble)
)
<div>
{
for (model <- models) yield {
<h3>{model.name}</h3>
<ul>
{
for (i <- model.contents) yield {
<li>{i.toString}</li>
}
}
</ul>
}
}
</div>
}
dom.render(document.body, render)
The following code is what I'm trying to achieve in my own project (with a more complicated interface but the same error is what I am finding difficult to overcome).
import com.thoughtworks.binding.Binding.{ Var, Vars }
import com.thoughtworks.binding.dom
import org.scalajs.dom.document
case class Model(name: String, contents: Vars[Double])
@dom
def render = {
val models = Vars(
Model("A Model", Vars[Double](1,2,3))
)
<div>
{
for (model <- models) yield {
<h3>{model.name}</h3>
<ul>
{
for (i <- model.contents) yield {
<li>{i.toString}</li>
}
}
</ul>
}
}
</div>
}
dom.render(document.body, render)
Running this (https://scalafiddle.io/sf/9eib3hm/0) gives the following error:
ScalaFiddle.scala:16: error: overloaded method value domBindingSeq with alternatives:
( text: String )binding.this.Binding.Constants[raw.this.Text]
( node: raw.this.Node )binding.this.Binding.Constants[raw.this.Node]
( seq: Seq[raw.this.Node] )binding.this.Binding.Constants[raw.this.Node]
( bindingSeq: .this.com.thoughtworks.binding.Binding.BindingSeq[raw.this.Node] ).this.com.thoughtworks.binding.Binding.BindingSeq[raw.this.Node]
cannot be applied to (.this.com.thoughtworks.binding.Binding.BindingSeq[.this.com.thoughtworks.binding.Binding.BindingSeq[raw.this.Node]])
for (model <- models) yield {
^
}
Any help would be appreciated
models flatMap { model =>
<h3>
{model.name}
</h3>
<ul>
{for (i <- model.contents) yield {
<li>
{i.toString}
</li>
}}
</ul>
}
@dom
macro or does that extend to setting Var.value
inside a Binding{ .. }
block?
.value
and .value_=
are side effects.
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.