These are chat archives for ThoughtWorksInc/Binding.scala

9th
Feb 2017
杨博 (Yang Bo)
@Atry
Feb 09 2017 00:22
Change hello to a def @a-reisberg
杨博 (Yang Bo)
@Atry
Feb 09 2017 01:22
This is a limitation of DOM API, since a HTML node only has one parent
Alex Reisberg
@a-reisberg
Feb 09 2017 02:24
@Atry Thanks!
so when I do .bind, hello is mutated under the hood?
Alex Reisberg
@a-reisberg
Feb 09 2017 02:26
maybe it's good to have Binding[_] lazy by default
杨博 (Yang Bo)
@Atry
Feb 09 2017 02:27
I did not get what does "lazy" mean
Alex Reisberg
@a-reisberg
Feb 09 2017 02:27
Binding[Node] would then be approximately () => Binding[Node] in the current incarnation
杨博 (Yang Bo)
@Atry
Feb 09 2017 02:28
Then you should use def by default
Alex Reisberg
@a-reisberg
Feb 09 2017 02:28
yeah :)
Thanks!
杨博 (Yang Bo)
@Atry
Feb 09 2017 02:29
A Binding is a container that continuously maintain its element according to upstream changes.
Alex Reisberg
@a-reisberg
Feb 09 2017 02:29
Right
杨博 (Yang Bo)
@Atry
Feb 09 2017 02:29
if you need two different values, you need two containers
Alex Reisberg
@a-reisberg
Feb 09 2017 02:29
btw, when I have
@dom def hello: Binding[Node] = <p>Hello from Binding.scala</p>
intellij complains about type issues. Is it possible to make it go away?
Found Elem, required Binding[Node]
杨博 (Yang Bo)
@Atry
Feb 09 2017 02:30
You can create an implicit view to make IntelliJ happy
Alex Reisberg
@a-reisberg
Feb 09 2017 02:31
Ah, thanks.
I'm gonna keep playing with it. It seems quite nice!
杨博 (Yang Bo)
@Atry
Feb 09 2017 02:35
@a-reisberg Would you mind editing FAQ to include this workaround for IntelliJ?
Alex Reisberg
@a-reisberg
Feb 09 2017 04:25
Will do!
Alex Reisberg
@a-reisberg
Feb 09 2017 05:16
Hi again, quick question: how do you make the following work:
@dom def hello: Binding[Node] = <p>Hello from Binding.scala</p>

@dom def helloTwice: Binding[Node] =
  <div>
    {
      (1 to 10).map(_ => Binding{hello.bind})
    }
  </div>
杨博 (Yang Bo)
@Atry
Feb 09 2017 05:16
See FAQ
Alex Reisberg
@a-reisberg
Feb 09 2017 05:17
I did, that's how I added the Binding
FAQ says:
someCollection.map(item => Binding { renderItem(item.bind) } )
杨博 (Yang Bo)
@Atry
Feb 09 2017 05:19
(1 to 10).map(_ => Binding{hello.bind}) should compile
Alex Reisberg
@a-reisberg
Feb 09 2017 05:19
that's exactly the same as what I wrote above right?
杨博 (Yang Bo)
@Atry
Feb 09 2017 05:19
However, the type is Seq[Binding[Node]], which is unable to be inserted into DOM.
Alex Reisberg
@a-reisberg
Feb 09 2017 05:20
oh, so I should remove the { ...}
杨博 (Yang Bo)
@Atry
Feb 09 2017 05:20
You need a Seq[Node] or BindingSeq[Node] in order to insert to the DOM
So you may look at the other solutions
Alex Reisberg
@a-reisberg
Feb 09 2017 05:21
Ok, I got the Constants one to work
but since this one was mentioned as one of the solutions
I thought that it might work as well
杨博 (Yang Bo)
@Atry
Feb 09 2017 05:22
It does compile
Alex Reisberg
@a-reisberg
Feb 09 2017 05:22
the one I copied above didn't compile
杨博 (Yang Bo)
@Atry
Feb 09 2017 05:23
I mean the expression itself compiles
Anyway, I will delete the solution, since it is not useful
Alex Reisberg
@a-reisberg
Feb 09 2017 05:24
ok sure, the expression itself compiles, but not for macro expansion
Thanks
杨博 (Yang Bo)
@Atry
Feb 09 2017 05:26

For expression <div>{ x }</div>, x should be a Seq[Node] or BindingSeq[Node] or Node.

(1 to 10).map(_ => Binding{hello.bind}) is a Seq[Binding[Node]]

Alex Reisberg
@a-reisberg
Feb 09 2017 13:46
Thanks!
According to what you said then the following should work
  @dom def helloTwice: Binding[Node] =
    <div>
        {(1 to 10).map(_ => hello.bind)}
    </div>
but it doesn't
hello.bind now has the correct type Seq[Node], but macro expansion still complains about
`each` instructions must be inside a SDE block
杨博 (Yang Bo)
@Atry
Feb 09 2017 23:13
_ => hello.bind is an ordinary function. .bind is not allowed in it.