These are chat archives for ThoughtWorksInc/Binding.scala

28th
Sep 2016
Michele Sciabarra
@sciabarra
Sep 28 2016 14:14
can I make a Var depends on another Var?
It should be obvious but I have not found a single example where a Var is recalculated when another Var is assigned
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:16
No
Michele Sciabarra
@sciabarra
Sep 28 2016 14:16
oh
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:20

You may try some code like this:

val a = Var(0)
val b = Var(0)
@dom def autoBindA = { a := b.bind * 2 }
@dom def autoBindB = { b := a.bind * 2 }
autoBindA.watch()
autoBindB.watch()

a := 1

Though I will never recommend that

Michele Sciabarra
@sciabarra
Sep 28 2016 14:20
I want simply to display a div when a a value is changed
presenting
val presenting = Var(true)
then
<div style={if(presenting.get) "" else "display: none" }>
should this work?
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:22
No
Try bind instead of get
I guess You may want to have a look at the API reference first
Michele Sciabarra
@sciabarra
Sep 28 2016 14:24
I did
it is open in front of me
anyway I try with bind
last question: is
<div style={displayStyle(presenting.bind)}> going to work?
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:26
Yes.
Michele Sciabarra
@sciabarra
Sep 28 2016 14:27
Phew! :)
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:27
You can try it on ScalaFiddle
Michele Sciabarra
@sciabarra
Sep 28 2016 14:27
I have also an event that is not coming from the dom
will this trigger an update?
it is coming from a click in a threejs event handler
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:28
Depends on how you create your @dom methods. I guess you can try it and you will find out the answer.
Michele Sciabarra
@sciabarra
Sep 28 2016 14:29
I will try
let's see what happens
thank you a lot
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:29
Never mind.
Michele Sciabarra
@sciabarra
Sep 28 2016 14:36
works! :)
杨博 (Yang Bo)
@Atry
Sep 28 2016 14:39
Have fun!