Hi all,
I am considering API changes in next version of Binding.scala.
In Binding.scala 10.0, you can get the current value of a Var
via get
method, and set the value via :=
method, and you can both get or change a Vars
via get
method. For example:
val i = Var(100)
i := i.get + 1
println(i.get) // output: 101
val s = Vars(1, 2)
s.get ++= 42
println(s.get) // output: Buffer(1, 2, 42)
This is not consistent.
If we rename get
to value
, and rename :=
to value_=
, then we can perform get/set/modify operations on Var
/Vars
in the same value
method:
val i = Var(100)
i.value += 1
println(i.get) // output: 101
val s = Vars(1, 2)
s.value ++= 42
println(s.get) // output: Buffer(1, 2, 42)
How do you guys think about new value
API? Do you think it worth changing APIs?
val i = Var(100)
i.value += 1
println(i.value) // output: 101
val s = Vars(1, 2)
s.value ++= 42
println(s.value) // output: Buffer(1, 2, 42)
The new syntax is more natural. Actually I attempted to do
something like this before checking documentation :). Of course I
would keep the old methods around even deprecated.
--
You received this message because you are subscribed to the Google Groups "Scala.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-js+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-js/ca71eac0-0aab-4329-9d75-9265c0386d24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- Michele Sciabarra Sciabarra.com ltd
@dom val i: Binding[Int] = 1 @dom def plusI(n: Binding[Int]): Binding[Int] = n.bind + i.bind @dom val myDiv: Binding[HTMLDivElement] = { val node: HTMLDivElement = <div></div> myDiv } @dom val myDivs: Binding[BindingSeq[HTMLDivElement]] = { val nodes: BindingSeq[HTMLDivElement] = <div></div><div></div>
nodes }
@html val i: Int = 1 // No magic here. i is not bindable.
@html def plusI(n: Binding[Int]): Int = n.bind + i // does not compile because `n.bind` must inside a data-binding block
@html def plusI(n: Binding[Int]): Binding[Int] = Binding { n.bind + i } // OK @html val myDiv: Binding[HTMLDivElement] = { val node: Binding[HTMLDivElement] = <div></div> myDiv } @html val myDivs: BindingSeq[HTMLDivElement] = { val nodes: BindingSeq[HTMLDivElement] = <div></div><div></div>
nodes }