These are chat archives for ThoughtWorksInc/Binding.scala

10th
Apr 2018
杨博 (Yang Bo)
@Atry
Apr 10 2018 02:39
@asoltysik Feel free to create new wiki pages for motive examples.
Aslo you can edit the ScalaDoc for basic concept and simple independent examples.
Ankit Soni
@ankitson
Apr 10 2018 12:52

hi guys, im trying a very simple example and i dont understand why it doesnt work -

  val squareValues:List[Var[Any]] = List(
    Var(0),Var(1),Var(2)
  )

  @tdom
  def square(id: Int): Binding[Node] = {
    def clickHandler() = { (_:MouseEvent) =>
      println(f"click $id");
      squareValues(id).value="X"
    }

    <button class="square" onclick={clickHandler}>{squareValues(id).value.toString}</button>
}
   ….
    tdom.render(appRoot, square(0))

now clicking the square doesnt change whats displayed.

nvm i got it working… i mixed up bind and value
Andrzej Sołtysik
@asoltysik
Apr 10 2018 14:39
You shouldn't use value inside the dom method
replace this: {squareValues(id).value.toString} with this: {squareValues(id).bind.toString}
Andrzej Sołtysik
@asoltysik
Apr 10 2018 14:44
@ankitson bind is the method that does actual binding to a var and registers your square method to change when the var changes
Ankit Soni
@ankitson
Apr 10 2018 17:32
@asoltysik yep, i got it working.. thanks!
im still having trouble getting this working if anyone can take a look - https://scalafiddle.io/sf/RcuzfDO/3. its asimple tic tac toe game, from the React tutorial. the status is a binding, but it does not update when squares change
but i did bind not value..