Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 02:52

    Atry on master

    Update scalafmt-core to 2.3.2 Merge pull request #230 from sc… (compare)

  • 02:52
    Atry closed #230
  • 02:50
    scala-steward opened #232
  • 02:48
    Atry closed #218
  • 02:47
    scala-steward opened #231
  • 02:47
    scala-steward opened #230
  • 02:47
    scala-steward opened #229
  • 02:46
    scala-steward opened #228
  • 02:46
    scala-steward opened #227
  • 02:46
    scala-steward opened #226
  • Dec 07 10:20
    Atry commented #175
  • Dec 07 10:02
    adrobisch commented #175
  • Dec 01 21:52
    Atry commented #175
  • Dec 01 12:39
    adrobisch commented #175
  • Nov 24 09:02
    adrobisch commented #175
  • Nov 24 05:37
    Atry commented #175
  • Nov 24 03:38
    Atry commented #175
  • Nov 23 21:44
    adrobisch commented #175
  • Nov 23 21:44
    adrobisch commented #175
  • Nov 23 21:42
    adrobisch commented #175
杨博 (Yang Bo)
@Atry
It's better to avoid watch...
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..
baank
@baank
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?