Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 17 02:41
    scala-steward opened #296
  • Oct 06 19:15
    scala-steward opened #295
  • Oct 04 09:58
    romansky commented #294
  • Oct 04 09:02
    Atry closed #294
  • Oct 04 09:02
    Atry commented #294
  • Oct 01 15:27

    Atry on master

    Update the link (compare)

  • Oct 01 15:17
    romansky opened #294
  • Sep 29 23:57
    scala-steward opened #293
  • Sep 18 21:04
    scala-steward opened #292
  • Sep 14 19:28
    scala-steward opened #291
  • Sep 08 17:57
    scala-steward opened #290
  • Aug 31 04:42
    scala-steward opened #289
  • Aug 11 03:17
    scala-steward opened #288
  • Aug 07 06:53
    scala-steward opened #287
  • Jul 27 16:34
    scala-steward opened #286
  • Jul 20 19:58
    scala-steward opened #285
  • Jul 11 00:24
    scala-steward opened #284
  • Jun 30 21:04
    scala-steward opened #281
  • Jun 29 15:04
    scala-steward opened #280
  • Jun 28 01:13
    scala-steward opened #279
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.
the code is really basic so I will try to experiment further, but I really don't understand the compile error:

in my main method: dom.render(document.body, router.currentRoute)

in my router: @dom def currentRoute: Binding[_ <: Node] = router.state.bind.view.bind
where view is: view: Binding[_ <: Node]

I also tried removing the .bind, removing the @dom, etc. - nothing works; if I replace the .bind with .value (and remove @dom) then it compiles but as expected, doesn't change the view when the hash changes (it only correctly loads the initial view when I reload the page)
Sandro Gržičić
@SandroGrzicic
and my error is usually something like:
[error]  found   : _$2(in method currentRoute) => _$2(in method currentRoute) where type _$2(in method currentRoute) <: org.scalajs.dom.raw.Node
[error]  required: _$2(in value $anonfun) => _$2(in method currentRoute) where type _$2(in method currentRoute) <: org.scalajs.dom.raw.Node, type _$2(in value $anonfun) <: org.scalajs.dom.raw.Node
I'll continue trying but I would appreciate any help; it seems like such a simple thing to do and I am failing at it.
I'm using scala.js 0.6.22 and Binding.scala 11.0.1 (dom, futurebinding, route)
Sandro Gržičić
@SandroGrzicic
Interesting. The exact some code now works. I first put in some HTML inside the method, and put the router.state.bind.view.bind inside some curly braces, and that worked, then I reverted all the changes and now that works too. Weird
[edit] Just ran the code and it works beautifully. When I change the URL hash (#) by clicking on a nav link, the view re-renders. Awesome.
Seung-Zin Nam
@zy4
Hi, is there a way to render raw unsanitized html like using raw() from scalatags?
Kahli Burke
@kahliburke
@zy4 You can use the innerHTML attribute on a containing tag
Seung-Zin Nam
@zy4
@kahliburke that's what I did in the end but I don't like this as a solution because I need to wait for the dom element to be rendered
so I had to wait via setTimeout for this to happen :(
So I actually would like to insert raw strings before rendering happens
Seung-Zin Nam
@zy4
@glmars the only way I could use this would be to have nested rendering. Who else would find it useful to have a native way of just embedding raw html as strings?