General questions should be asked on StackOverflow, not here. This room focuses on development of Binding.scala.
Atry on Atry-patch-1
Atry on master
Upgrade Scala version Merge pull request #224 from Th… (compare)
Atry on Atry-patch-1
Upgrade Scala version (compare)
Atry on master
Update sbt-scalajs, scalajs-com… Merge pull request #213 from sc… (compare)
Hi there,
I'm looking into using Binding.scala and am unable to render a Seq[String]
via for
/yield
. The Seq
is in a nested case class and doesn't need to be a BindingSeq
. For example:
import com.thoughtworks.binding.dom
object BindingExample {
@dom
def template(strings: Seq[String]) =
<ul>
{
for (s ← strings) yield <li>{ s }</li>
}
</ul>
}
I get the error:
BindingExample.scala:8: each
must be inside monadic
, throwableMonadic
, or catchIoMonadic
.
Am I missing something?
Hi there, I'm playing around a bit with Binding.scala (mostly the data-binding stuff not the DOM bits), but I'm a bit stuck on how to achieve a rather simple effect.
What I need is to sort of do a fold over all the values in a Binding as they come in and accumulate some state while doing that. (My case is a bit more complicated, but this'll do for a start :))
What I have so far is to have a Var[T] which is set up with the initial accumulator state and to then have a
```scala
(Sorry, this is the full question:)
Hi there, I'm playing around a bit with Binding.scala (mostly the data-binding stuff not the DOM bits), but I'm a bit stuck on how to achieve a rather simple effect.
What I need is to sort of do a fold over all the values in a Binding as they come in and accumulate some state while doing that. (My case is a bit more complicated, but this'll do for a start :smile:)
What I have so far is to have a Var[T] which is set up with the initial accumulator state and to then have a
var externalValue$ = Var[T](...)
var currentState$ = Var[S](...)
val accumulatedState$: Binding[S] = monadic[Binding] {
val nextState: S = (externalValue$.each, currentState$.get) match {
// Choose a new state, S, based on the two values in the pattern match
}
currentState$ := nextState
nextState
}
but seems to be quite cumbersome and I'm sure how/if it can abstracted away into some reusable
building block. (I think I'd have to be able to pass a Monadic block into my abstraction if I want to do
anything other than just a simple (A, S) => S state transition function, perhaps using other variables, etc.
Maybe passing in the Var[T] would be sufficient, but it'd require tupling up the inputs explicitly.)
First of all: Is the above guaranteed to work per the expected semantics of the library? From my little experimentation it seems to, but it's ... inelegant.
:=
operator in a monadic
block.
:=
in a monadic
block.
Binding
is not an event stream.
createSelfRecursiveBinding
, you can have:val event: Var[E] = ...
val state: Binding[S] = createSelfRecursiveBinding(initialState, state => monadic[Binding] {
(event.each, state) match {
// Choose a new state, S, based on the two values in the pattern match
}
})
E
is a case class, it may accidentially skip computation because of it detects no change.
createSelfRecursiveBinding
?
currentState
variable. Could you refactor your code to avoid explicit state?