Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 09 04:00
    notyy commented #222
  • Oct 09 03:59
    notyy closed #222
  • Oct 09 03:59
    notyy commented #222
  • Oct 08 20:28
    Atry commented #223
  • Oct 08 20:28

    Atry on master

    docs: fix typo Merge pull request #223 from Ja… (compare)

  • Oct 08 20:28
    Atry closed #223
  • Oct 08 20:20
    Jason-Cooke opened #223
  • Oct 07 03:30
    glmars commented #222
  • Oct 06 04:05
    notyy opened #222
  • Oct 04 11:29
    datalchemist commented #217
  • Oct 04 11:02
    datalchemist commented #217
  • Oct 04 06:58

    Atry on scalafmt

    (compare)

  • Oct 04 06:46

    Atry on master

    Run scalafmt Merge branch 'master' into scal… Merge pull request #221 from Th… (compare)

  • Oct 04 06:46
    Atry closed #221
  • Oct 04 06:46
    Atry synchronize #221
  • Oct 04 06:46

    Atry on scalafmt

    Update scalafmt to 2.0.1 Update sbt to 1.3.2 Merge pull request #215 from sc… and 2 more (compare)

  • Oct 04 06:06
    Atry commented #217
  • Oct 04 05:30
    glmars commented #217
  • Oct 04 05:09
    Atry closed #191
  • Oct 04 05:09

    Atry on master

    Update scalafmt to 2.0.1 Merge pull request #203 from sc… (compare)

杨博 (Yang Bo)
@Atry

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
@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
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.
杨博 (Yang Bo)
@Atry
The for/yield expression maps some BindingSeq(including Vars and Constants) to a new BindingSeq. You can perform calculation in the yield block.
杨博 (Yang Bo)
@Atry

This kind of expression is pure because it simply create some new BindingSeq instead of affecting the real world.

However, if I understand your question correctly, you were asking how to change the real world. For Scala.js target, you invoke dom.render to mount a Binding or BindingSeq into a DOM document. For JVM target, you have to create your own SingleMountPoint or MultiMountPoint then invoke watch method on your mount points. In your mount point instance, you will implement some abstract methods to handle data changing events.

Note that these abstract methods are protected. You have to click Show all button to see them in the scaladoc.
@Jegp FYI
杨博 (Yang Bo)
@Atry
Unlike other FRP framework, Binding.scala prevents user from registering event listener for a specific Binding expression. Instead, I encourage you create different types of mount point for different types of underlying system.
SpringBean
@SpringBean
Hello everyone,
SpringBean
@SpringBean
I am new to using Binding.scala and i have just started learning. I really interested and starting to like it. I have some issues where i am stuck, i am not able to figure out about adding a css.file to the main page. I tried all the four ways of adding style/ stylesheet to the page but not able to do it. Second thing is that i have to say fastOptJS, followed by assets and then by assetsTarget everytime i want to compile and run my webpage? How can i write the index.html without the resource generator in the build.sbt. Can you please help me?
杨博 (Yang Bo)
@Atry
@SpringBean I think you can ask your question on Scala.js mail list, because this is not a Binding.scala issue per se.
@SpringBean Did the tutorial of Scala.js resolve your problem?
d065348
@d065348
@Atry thank you. yes i did try the sbt project style , but it did not work. And how do i add a style sheet to this code for example https://thoughtworksinc.github.io/Binding.scala/#0
SpringBean
@SpringBean
@Atry thank you. yes i did try the sbt project style , but it did not work. And how do i add a style sheet to this code for example https://thoughtworksinc.github.io/Binding.scala/#0
SpringBean
@SpringBean
The problem with the sbt set up of project is resolved.
SpringBean
@SpringBean
and also the issue with my css page to the binding.scala is working fine. thank you
杨博 (Yang Bo)
@Atry
@d065348 It's hard for that repository because it use sbt-site. In order to add SASS/SCSS assets, you may want to use sbt-web instead of sbt-site.
SpringBean
@SpringBean
Ok great .Thank you
Carl Porth
@badcarl

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?

杨博 (Yang Bo)
@Atry
@badcarl DOM literal is only available in @dom method or BindingSeq's mapping function. However, your inner li is in the normal mapping function that passed to normal Seq.map
杨博 (Yang Bo)
@Atry
@badcarl I suggest you convert your strings to a Constants
Bardur Arantsson
@BardurArantsson

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

(dammit, sorry, premature post. Will edit and repost :))
杨博 (Yang Bo)
@Atry
For complex computation, you can store your data into a Binding of immutable collection, then compute your accumulator via methods like foldLeft, sum or any other higher ordered functions:
val source = Var(List(1, 2, 3))
val result = source.each.sum
Bardur Arantsson
@BardurArantsson

(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.

Right, but the thing here is that the "collection" I'm working on is itself the "stream of values" that a binding takes over time, if that makes sense. So it'd be something like a streaming fold.
Bardur Arantsson
@BardurArantsson
*Dang, sorry type annotations were a bit wrong, fixed
杨博 (Yang Bo)
@Atry
This message was deleted
How about this?
Bardur Arantsson
@BardurArantsson
Ah, OK, yes, that's a bit more elegant and avoids the scary-looking circular (but not really) reference
杨博 (Yang Bo)
@Atry
Note the watcher.watch() is necessary, because the monadic block is pure functional and does not change anything until you setup a watch()
Wait
This message was deleted
This is simpler.
My original answer and you code are dangerous because of the := operator in a monadicblock.
We should always avoid := in a monadic block.
Bardur Arantsson
@BardurArantsson
Ah, OK, so self-recursion is explicitly permitted?
杨博 (Yang Bo)
@Atry
monadic block should be pure functional. No assign operator and no side-effect.
Bardur Arantsson
@BardurArantsson
That definitely makes sense, but I kind of had the impression that ":=" wasn't actually side effecting when used in a "monadic" block. I guess I was mistaken, then :)
Thanks for the help, I'll see how much further I can get.
Aside: I think the documentation could use a little more expansion on the expected semantics of the Binding/Var side of the system. (Assuming I didn't just miss it.)
杨博 (Yang Bo)
@Atry
Wait, I guess the self-recursion is not acceptable. Let me figure out another solution
I think there is no safe way to implement self-recursion in current version of Binding.scala
It requires additional API
Bardur Arantsson
@BardurArantsson
Interesting. In my exploration (just trying things out to see what works), I've found that as long as you reach some sort of steady state where things are no longer changing everything seems to work out. AFAICT this is because Var doesn't emit any change notifications when you do v := "foo" if the Var backing 'v' already has the value "foo". (Of course this was using tiny examples.)
杨博 (Yang Bo)
@Atry
I can provide a conversion def createSelfRecursiveBinding(initialState: A, nextState: A => Binding[A]): Binding[A]