These are chat archives for ThoughtWorksInc/Binding.scala

16th
Mar 2016
杨博 (Yang Bo)
@Atry
Mar 16 2016 03:34
@Jegp BindingInstances is an internal data structure. I did not expect it being used by manually written code.
This message was deleted
杨博 (Yang Bo)
@Atry
Mar 16 2016 03:40

I think you can simply use for/yield on Vars.

val prefix = new Var("ForYield")
val source = Vars(1, 2, 3)
val mapped = (for {
  sourceElement <- source
  i <- Constants((0 until sourceElement): _*)
} yield {
  raw"""${prefix.each} $i/$sourceElement"""
})

mapped.watch()

See https://github.com/ThoughtWorksInc/Binding.scala/blob/master/core/src/test/scala/com/thoughtworks/binding/BindingTest.scala#L211

Note that data-binding is disabled by default. You must call watch() after you setup all binding expressions.
Jens Egholm
@Jegp
Mar 16 2016 07:10
@Atry Thanks mate. That makes much more sense. I just skimmed the documentation for something that could map the structure. But this makes much more sense
Hey, and thanks for all the great work. I really like your library as an alternative to all the other reactive frameworks
Jens Egholm
@Jegp
Mar 16 2016 16:22
Just one short question. Since your aggregating into constants, is it possible to map further from here on? Or would the changes not be registered in the binding?
Hrm.. I really need to read up on my monads.
So a more specific question could be; if I'd like to extract the sequence to perform some calculation on it reactively, how would you do this within your framework? I assume a for..yield isn't going to cut it because there's no way to escape from the monad scope.