Binding.scala
Binding.scala copied to clipboard
Inconsistent behaviour with Vars.value
If you look at the Todo example there is frequent use of the value attribute of a Vars for example:
allTodos.value += Todo(title, completed = false)
for ((todo, i) <- allTodos.value.zipWithIndex)
So as someone new to the framework I assumed that I could use value within a for comprehension in combination with the scalaz workaround i.e.
import com.thoughtworks.binding.Binding.{Var, Vars}
import com.thoughtworks.binding.dom
case class SelectOption(label: Var[String], value: Var[String])
val options = Vars.empty[SelectOption]
@dom def render(): Unit = {
import scalaz.std.list._
<select> {
for (option <- options.value) yield {
<option value={option.value.bind}>{option.label.bind}</option>
}
}
</select>
}
However this causes the option.value and option.label bindings to fail with the "each instructions must be inside a SDE block" error. Changing the for loop to the following fixes the issue:
for (option <- options)
This is extremely confusing and inconsistent since you can use the value attribute for adding, deleting and some iterating (?) but not within a for comprehension.
So what's your proposal?