Binding.scala 11.0 API changes

265 views
Skip to first unread message

杨博

unread,
Jan 15, 2017, 2:00:19 AM1/15/17
to Scala.js

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:

  1. val i = Var(100)
  2. i := i.get + 1
  3. println(i.get) // output: 101
  4. val s = Vars(1, 2)
  5. s.get ++= 42
  6. 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:

  1. val i = Var(100)
  2. i.value += 1
  3. println(i.get) // output: 101
  4. val s = Vars(1, 2)
  5. s.value ++= 42
  6. println(s.get) // output: Buffer(1, 2, 42)

How do you guys think about new value API? Do you think it worth changing APIs?

杨博

unread,
Jan 15, 2017, 5:19:54 AM1/15/17
to Scala.js
Sorry the original code example in println is wrong. It should be println(i.value)

    1. val i = Var(100)
    2. i.value += 1
    1. println(i.value) // output: 101
    1. val s = Vars(1, 2)
    2. s.value ++= 42
    1. println(s.value) // output: Buffer(1, 2, 42)

    Michele Sciabarra

    unread,
    Jan 18, 2017, 1:18:49 AM1/18/17
    to scal...@googlegroups.com

    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.


    Il 15/01/17 08:00, 杨博 ha scritto:
    --
    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

    杨博

    unread,
    Jan 18, 2017, 11:16:23 PM1/18/17
    to Scala.js, mic...@sent.as
    Of course, I tend to not remove deprecated methods until it blocks new features or new designs. I guess I will deprecate and keep old get and := .

    One more thing... I am considering deprecating @dom, as mentioned in Desktop GUI and custom tags in Binding.scala. How do you think of that?

    在 2017年1月18日星期三 UTC+8下午2:18:49,Michele Sciabarra写道:

    杨博

    unread,
    Jan 18, 2017, 11:22:51 PM1/18/17
    to Scala.js, mic...@sent.as
    Old @dom annotation:
    @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
    }


    New proposed @html annotation:
    @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 }

    在 2017年1月19日星期四 UTC+8下午12:16:23,杨博写道:
    Reply all
    Reply to author
    Forward
    0 new messages