These are chat archives for ThoughtWorksInc/Binding.scala

22nd
Aug 2016
Philip Stutz
@pstutz
Aug 22 2016 09:50
hey atry, really cool tool, this is by far the most convenient way of writing the client side of a web app.
杨博 (Yang Bo)
@Atry
Aug 22 2016 09:51
:smile:
Philip Stutz
@pstutz
Aug 22 2016 09:51
i'm currently struggling with debugging code that is modified by the @dom macro and get errors like this one:
"each instructions must be inside a SDE block"
i encounter this error often in simple examples that are superficially like the table on the example page, but i don't know how to figure out what's wrong. do you have suggestions?
杨博 (Yang Bo)
@Atry
Aug 22 2016 09:52
Which version are you using?
Philip Stutz
@pstutz
Aug 22 2016 09:53
8.0.0
杨博 (Yang Bo)
@Atry
Aug 22 2016 09:55
Have you put your .bind expression into @dom methods?
Philip Stutz
@pstutz
Aug 22 2016 09:55
yes.
杨博 (Yang Bo)
@Atry
Aug 22 2016 09:55
Is it in a closure?
Philip Stutz
@pstutz
Aug 22 2016 09:55
happens in blocks like this:
"""
@dom def tableOrNothing: Binding[Node] = {
val categoryOption: Option[Category] = selectedCategory.bind
val categoryTableOption = categoryOption.map(new CategoryView().table)
val tableOption: Option[Node] = categoryTableOption.map(
.bind)
tableOption.getOrElse(<div/>)
}
"""
杨博 (Yang Bo)
@Atry
Aug 22 2016 09:56
You created a closure for categoryTableOption.map
Philip Stutz
@pstutz
Aug 22 2016 09:57
how do i enable the macro in a closure?
杨博 (Yang Bo)
@Atry
Aug 22 2016 09:58
You can create nested @doms in any closure.
Then, val tableOption: Option[Node] should be changed to val tableOption: Option[Binding[Node]]
@dom val i: Binding[Int] = 1
val myOption: Option[Binding[Int]] = Some(10).map { v => Binding { i.bind + v }} // Result is: Some(Binding(11))
Binding is like @dom, with some minor differences.
Philip Stutz
@pstutz
Aug 22 2016 10:04
thank you very much.
杨博 (Yang Bo)
@Atry
Aug 22 2016 10:07
Have fun with Binding.scala! :smile:
Philip Stutz
@pstutz
Aug 22 2016 10:11
using Binding { ... } blocks to enable the macros works well, thanks. :D
sorry for the newbie question: how do i create an empty node binding? Binding { <div/> } is ugly, but i cannot leave it empty or put in unit.
杨博 (Yang Bo)
@Atry
Aug 22 2016 10:13
Try this: Binding { <!-- Render nothing because ... --> }
Philip Stutz
@pstutz
Aug 22 2016 10:15
thanks a lot. would you appreciate it if i sent pull requests with documentation for these features? they're really useful and to the best of my knowledge they're not documented yet.
杨博 (Yang Bo)
@Atry
Aug 22 2016 10:16
Yes, please!
Philip Stutz
@pstutz
Aug 22 2016 10:16
i guess there are more backend newbs who struggle with just putting an html comment in. :P
杨博 (Yang Bo)
@Atry
Aug 22 2016 10:17
Could you create a FAQ page on wiki? I will create a link to there.
Philip Stutz
@pstutz
Aug 22 2016 11:16
wikis don't have good support for pull requests. forked and put it here: https://github.com/pstutz/Binding.scala/wiki/FAQ
feel free to just copy & paste.
杨博 (Yang Bo)
@Atry
Aug 22 2016 15:03
I have merge your changes. Thank you @pstutz !