These are chat archives for ThoughtWorksInc/Binding.scala

31st
Aug 2016
杨博 (Yang Bo)
@Atry
Aug 31 2016 02:03
@soulmachine We, ThoughtWorks, uses Binding.scala in some web applications. Though I don't know the usage of outside would.
@soulmachine Would you mind if you tell the production name if you switch it to Binding.scala ?
Chris Camel
@ccamel
Aug 31 2016 08:08

@soulmachine I have the same profile than you. I'm currently assessing some frontend technologies far from the javascript stacks. I've already assessed ELM and scalajs+diode and I'm POC-ing scalajs+Binding.scala to build a pure and full reactive GUI.

Now I've come to a stage where I've made successful exchanges between the GUI and a backend (rabbitMQ + stomp through websockets). Surprisingly, it works extraordinarily well. Binding.scala is a really nice piece of code.

Of course there is some improvements that could be considered.
杨博 (Yang Bo)
@Atry
Aug 31 2016 08:14
@chris-tek For backend access, you may want to have a look at https://thoughtworksinc.github.io/Binding.scala/#9
Ólafur Páll Geirsson
@olafurpg
Aug 31 2016 08:28

@chris-tek Agreed. I considered several alternatives and found Binding.scala to work best for me. Also, the designer I'm working with is enjoying Binding.scala since it looks so similar to html.

There are some rooms for improvements, however. Most importantly, the instructions must be inside a SDE block error message was completely cryptic at first. I couldn't find any reference to that error in the binding source code since it's in the sde dependency, but in the context of Binding.scala I have no idea whan an sde block is. The second workaround in the wiki didn't work for me either, I've been most successful with using Constants(collection:_*) which I picked up from the TODO MVC.

杨博 (Yang Bo)
@Atry
Aug 31 2016 08:36
Thank you for your feedback. I have updated the FAQ https://github.com/ThoughtWorksInc/Binding.scala/wiki/FAQ
Ólafur Páll Geirsson
@olafurpg
Aug 31 2016 08:36
@Atry It would be nice to lower the barrier of entry to contribute to the wiki. I would suggest to move the FAQ to the Readme or a FAQ.md in the top level dir of the main repo. This would mean that code search queries yield results from the FAQ. Currently, you need to press "Wiki" after searching and I think many people (including myself) may not figure that out immediately. Maybe I'm stupid, but I'm not really sure how forking the wiki works. .
杨博 (Yang Bo)
@Atry
Aug 31 2016 08:40
OK. I have grant the edit permission of wiki to everyone. Feel free to add content you encountered.
Ólafur Páll Geirsson
@olafurpg
Aug 31 2016 08:48

@Atry The second workaround somehow doesn't work for me, if I do

someCollection.map(item => Binding { <div>item.bind</div> } )

I get the error

[error] : overloaded method value domBindingSeq with alternatives:
[error]   (text: String)com.thoughtworks.binding.Binding.Constants[org.scalajs.dom.raw.Text] <and>
[error]   (node: org.scalajs.dom.raw.Node)com.thoughtworks.binding.Binding.Constants[org.scalajs.dom.raw.Node] <and>
[error]   (seq: Seq[org.scalajs.dom.raw.Node])com.thoughtworks.binding.Binding.Constants[org.scalajs.dom.raw.Node] <and>
[error]   (bindingSeq: com.thoughtworks.binding.Binding.BindingSeq[org.scalajs.dom.raw.Node])com.thoughtworks.binding.Binding.BindingSeq[org.scalajs.dom.raw.Node]
[error]  cannot be applied to (Seq[com.thoughtworks.binding.Binding.F[org.scalajs.dom.html.LI]])
[error]         lst.map( i => Binding {

If I put .bind on each binding inside the map I get the following error:

: `each` instructions must be inside a SDE block
[error]         }.bind)
[error]           ^
[error] one error found
杨博 (Yang Bo)
@Atry
Aug 31 2016 08:51
The expression lst.map( i => Binding { xxx.bind } ) itself compiles. Unfortunately the return type is not able to render into DOM.
You got a Seq[com.thoughtworks.binding.Binding[org.scalajs.dom.html.LI]], which is simply a sequence of bindable expressions(Seq[Binding[LI]]), not a bindable sequence (BindingSeq[LI]).
Ólafur Páll Geirsson
@olafurpg
Aug 31 2016 08:54
Which makes sense, but it would be nice if it easier to do something fairly common like this
<ul>
  {someCollection.map(item => <li>item.name</li>)
</ul>
My current approach is to wrap the seq into Constants and it works great so far.
杨博 (Yang Bo)
@Atry
Aug 31 2016 08:55
That's good.
Ólafur Páll Geirsson
@olafurpg
Aug 31 2016 08:56
Alternatively, a clearer error message would be gold. Something like quill does for captured variables: https://pbs.twimg.com/media/CqySnwrXgAArWDZ.jpg:large
杨博 (Yang Bo)
@Atry
Aug 31 2016 09:02
Would you like to create a Pull Request for the error message? Somewhere around https://github.com/ThoughtWorksInc/sde/blob/3.0.x/core/src/main/scala/com/thoughtworks/sde/core/MonadicFactory.scala#L641
I feel it is hard to me because the error message is not only for Binding.scala, but also for other monadic DSLs.
Ólafur Páll Geirsson
@olafurpg
Aug 31 2016 09:25
I see the issue. I am not sure if I can to come up with a clear but generic enough error message for sde. To start with, it might be easier to populate the Wiki with more noob explanations why things work the way they work in Binding.scala. Thanks for opening up the edit access, I'll try to put something together when I find the time : )
杨博 (Yang Bo)
@Atry
Aug 31 2016 09:26
:smile: