by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 29 06:09
    Atry closed #262
  • May 29 06:09
    Atry commented #262
  • May 29 06:01

    Atry on v12.0.0

    (compare)

  • May 29 05:37

    Atry on master

    Update README.md (compare)

  • May 29 05:27

    Atry on master

    Update README.md (compare)

  • May 28 23:52

    Atry on master

    Update scalatest to 3.1.2 Merge pull request #272 from sc… (compare)

  • May 28 23:52
    Atry closed #272
  • May 28 23:52
    Atry closed #271
  • May 28 23:52
    Atry closed #270
  • May 28 23:52

    Atry on master

    Update scalafmt-core to 2.5.3 Merge pull request #274 from sc… (compare)

  • May 28 23:52
    Atry closed #274
  • May 28 23:52

    Atry on master

    Update sbt-scalajs, scalajs-com… Merge pull request #273 from sc… (compare)

  • May 28 23:52
    Atry closed #273
  • May 26 03:48
    scala-steward opened #274
  • May 15 23:08
    scala-steward opened #273
  • May 10 16:30
    scala-steward opened #272
  • May 10 16:30
    scala-steward opened #271
  • May 04 13:50
    scala-steward opened #270
  • Apr 26 06:52
    Atry closed #71
  • Apr 26 06:52
    Atry commented #71
Kahli Burke
@kahliburke
Yeah it's not my go to approach but I'm trying to figure out how to write a generic input component with Var for its internal state in a way that it can also respond to some external change... seems tricky to do it without var, and how else do I hook up external.bind -> inputelem.value? The other thing I thought of was to completely recreate my input component in response to external change but I was trying to avoid that.
Yang, Bo
@Atry
You can create another Binding that merges internal Var and external changes together.
Thinking about the dependency graph. A Var is always the source of the onchange event, not a intermediate node.
Kahli Burke
@kahliburke
Yes the graph makes sense. So my takeaway is that the warning about @dom applies to Binding {} as well, correct? Is the issue around circularity causing 'cycles' where dirty values cause other things to become dirty and we miss rendering properties (like digest cycles in the Angular world), or circularity causing stack overflow or other endless loop problems?
Yang, Bo
@Atry
It will never cause stack overflow in Binding.scala. But it will cause some reentry, which Binding.scala did not mean to support.
Kahli Burke
@kahliburke
The idea in putting value set into a Future was to get out of the graph and schedule a new change event to occur in the future.
Yang, Bo
@Atry
Creating a Future or a timer is also side effect. Don't do it in Binding block.
Kahli Burke
@kahliburke
Danger of reentry would be missing some change propagation?
Yang, Bo
@Atry
If you really want to trigger side effect, you can use MountPoint.
MountPoint has more control to life cycle of event handlers than Binding blocks.
Yang, Bo
@Atry
Still, MountPoint is an utility to trigger external side effect, not an approach to change Vars.
Kahli Burke
@kahliburke
Yes, I have read this and it makes sense for that use case, it's not immediately clear to me how I'd apply it in this situation.
Yang, Bo
@Atry
Though it is acceptable to use MountPoint to create a timer to change Vars.
You can create animations in that way.
If you want to change Var directly, then it's not your solution.
Kahli Burke
@kahliburke
Thanks for the information, I'll need to experiment a little bit to find a path I think. I think the main issue is around writing generic components (like a self contained class representing a select input) that can respond to both direct user input on that control, but also from changes that propagate from other controls in the system.
In this case, I actually want to respond to changes in the window.location history
Which propagate down through other structures, like a router
Yang, Bo
@Atry
You can create a Route.Href, similar to the existing Route.Hash.
Kahli Burke
@kahliburke
I have a location based router that watches the href, which seems to work properly
Yang, Bo
@Atry
For create generic components, have you tried to add an intermediate Binding that merges the internal Var and external changes together?
Kahli Burke
@kahliburke
I haven't, it may be a good approach but I'll have to spend some time investigating how to incorporate that, as right now the select input is nicely encapsulated, it renders out its DOM based on its internal structure, so to modify it to also accept some additional Binding that controls it for some less common cases seems dirty. What I have working now is that when the location changes, the select box object itself gets recreated, this instantiates a new Var but doesn't manipulate an existing one.
Yang, Bo
@Atry
Your approach looks good to me.
Kahli Burke
@kahliburke
Ok, one thing that I might have right! :)
Yang, Bo
@Atry
If what you want to recreate is just the Var, you can avoid recreating the HTML elements by use a Binding[Var[State]]as your internal state holder inside YourComponent, instead of Binding[YourComponent].
Kahli Burke
@kahliburke
Why the double wrapping of Var in Binding?
Yang, Bo
@Atry
val bvs: Binding[Var[State]] = Binding {
  Var(externalState.bind)
}
Also your xxxHandler should change to Binding[Event => Unit] types as well.
Yang, Bo
@Atry
def changeHandler = Binding {
  val vs = bvs.bind;
  { event: Event =>
    vs.value = event.currentTarget.asInstanceOf[Input].value
  }
}

@dom def renderComponent = {
  <input value={bvs.bind.bind} onchange={changeHandler.bind} />
}
Basim Khajwal
@basimkhajwal
Hi, I was wondering if it is ever bad practice to be using a lazy val instead of a def when creating a Binding ?
Yang, Bo
@Atry
No difference if you carefully avoid recursive dependencies.
Mustafa Kuscu
@mcku
Hi @Atry, i have started using your library. I think some helpers like this may be useful for beginners. I am kind of observing that dealing with futures and bindings add up extra lines of code..
 // some helpers for binding.scala
  @dom def futureBindingToBinding[T](futureBinding: Binding[Option[Try[T]]], emptyVal: T): Binding[T] = futureBinding.bind
    .map((y:Try[T]) => y.get)
    .getOrElse(emptyVal)

  @dom def futureBindingToBindingSeq[T](futureBindingSeq: Binding[Option[Try[Seq[T]]]], emptyVal: Seq[T]): Binding[BindingSeq[T]] = {
    val tmpSeq: Seq[T] = futureBindingSeq.bind
      .map((y: Try[Seq[T]]) => y.get)
      .getOrElse(emptyVal)
    val x: BindingSeq[T] = Vars(tmpSeq: _*)
    x
  }
Yang, Bo
@Atry
You can create your own library of these helpers. People will use your library as long as they feel useful.
Mustafa Kuscu
@mcku
It is amazing to see that yet Binding.scala is a client side JS what is executing, it is some order of magnitude faster than some of the competition.. It is type safe and no buggling with webpack and similar. Wow. I remember doing some logic from within componentDidMount (because that was the only straightforward/feasible way to do it), sometimes within seconds.. Binding scala.. same thing is done within milliseconds. Man, that is awesome..
Yang, Bo
@Atry
Have fun!
林煒清(Lin Wei-Ching)
@superChing
Hi, this code return error, but if I put the v2 binding val into render function it works. I do not understand where's problem?
val v1:Any = 1 
@dom
val v2 = Binding {
    v1 match {
      case x:String => <p>str</p>
      case x:Int => <p>int</p>
    }
}
@dom 
def render = { <p>{v2.bind}</p> }
dom.render(document.body, render)
林煒清(Lin Wei-Ching)
@superChing
need help. thank you.
Yang, Bo
@Atry
StackOverflow seems like a better place to ask questions like this
Kahli Burke
@kahliburke
@superChing Remove Binding from v2, it's already annotated with
@dom
林煒清(Lin Wei-Ching)
@superChing
thanks
Mustafa Kuscu
@mcku
Hi, consider an ajax method that most of the time returns the same value. Whenever that result is bound to a dom component, during the ajax call it disappears and gets re-rendered with the same value. I would like to avoid this behavior by declaring that binding to be a constant, with no success. The ajax result is a future binding which does not map into a constant. Or am i missing something here?
is it possible to have a forced constant futurebinding output?
i hope i am missing something otherwise it will eventually become seeking cumbersome ways to do kind of like 'diffing' and batched rendering?
Yang, Bo
@Atry
@mcku The built-in FutureBinding implementation only has 79 lines of code. Feel free to copy and create your own variant of FutureBinding.
Mustafa Kuscu
@mcku
thanks, i will try that..
Harana
@nadenf
Anyway know why this doesn't work ? https://scalafiddle.io/sf/EHdex4U/2
Binh Nguyen
@ngbinh
alpaka 0.17 has been tagged and updated on the website but looks like no maven artifact yet https://mvnrepository.com/artifact/com.lightbend.akka/akka-stream-alpakka-s3_2.12 . Anyone know how low will it take?
Sandro Gržičić
@SandroGrzicic
hi guys, I am new to Binding.scala, but I like using it so far; I have created a simple scala.js app with two pages and am trying now to "link" the Binding router to the dom.render method. However everything I try gives me a compile time error.