These are chat archives for ThoughtWorksInc/Binding.scala

16th
Apr 2018
Kahli Burke
@kahliburke
Apr 16 2018 05:41
Seung-Zin Nam
@zy4
Apr 16 2018 07:14
@kahliburke , nice would you mind, adding this to the stackoverflow post?
and thanks!
Chris Camel
@ccamel
Apr 16 2018 12:24
@Atry Is there any reason why the value is not accessible from the trait Binding ? I mean, the following is not compiling:
  def myBinding = Binding {
   // ... other instructions before
    println(myVar.value) // -> not compiling
  }
杨博 (Yang Bo)
@Atry
Apr 16 2018 12:41
This message was deleted
Sorry I didn't understand your question. @ccamel
Do you expect it compile or not?
Chris Camel
@ccamel
Apr 16 2018 12:45
It is currently not compiling: method value in trait Binding cannot be accessed in com.thoughtworks.binding.Binding.F[...
I would happy to make it compile.
杨博 (Yang Bo)
@Atry
Apr 16 2018 12:46
Is myVar a Var?
Chris Camel
@ccamel
Apr 16 2018 12:46
Yes it is.
By replacing .value by .bind it works, as expected.
Oups, it's not. It's a Binding instead.
Don't known if it makes a difference.
杨博 (Yang Bo)
@Atry
Apr 16 2018 12:49
That's good
Chris Camel
@ccamel
Apr 16 2018 12:50
More complete minimal sample:
def aBinding = Binding {
   ... // depends on other Var
}

def myBinding = Binding {
  aBinding.value // -> not compiling
}
杨博 (Yang Bo)
@Atry
Apr 16 2018 12:50
What's the problem?
Chris Camel
@ccamel
Apr 16 2018 12:54
value is private in Binding, but is public in Var. That's why my example was not compiling.
杨博 (Yang Bo)
@Atry
Apr 16 2018 12:56
Yes
Pascal Mengelt
@pme123
Apr 16 2018 12:58
@ccamel I added a scalafiddle: https://scalafiddle.io/sf/7MjSZyS/0 - why not switch Binding to Var?
杨博 (Yang Bo)
@Atry
Apr 16 2018 13:01
@pme123 don't do that. Both the getter and setter of value are impure. It's better to keep Binding block pure.
Chris Camel
@ccamel
Apr 16 2018 13:02
@pme123 Because the binding is read-only (var is not). I just want to wrap a var with a custom behaviour and make it bindable (a kind of composition of binds).