Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • May 18 01:57
    fdietze edited #549
  • May 16 14:44
    cornerman commented #49
  • May 13 07:43

    mergify[bot] on master

    Update scalajs-dom to 2.2.0 (#6… (compare)

  • May 13 07:43
    mergify[bot] closed #616
  • May 13 07:38
    mergify[bot] labeled #616
  • May 13 07:37
    scala-steward opened #616
  • May 12 23:22
    busti commented #49
  • May 12 23:20
    busti commented #49
  • May 01 00:41
    fdietze synchronize #549
  • May 01 00:41

    fdietze on scala3

    Improve workaround comment (compare)

  • May 01 00:32
    fdietze synchronize #549
  • May 01 00:32

    fdietze on scala3

    Move UndefinedModifier into low… Almost fix the last compile err… (compare)

  • Apr 30 23:11
    cornerman synchronize #549
  • Apr 30 23:11

    cornerman on scala3

    potential fix (compare)

  • Apr 28 16:45
    fdietze synchronize #549
  • Apr 28 16:45

    fdietze on scala3

    Scala 3 (compare)

  • Apr 28 15:27
    fdietze synchronize #552
  • Apr 28 15:27

    fdietze on explicit-dependencies

    Add sbt-explicit-dependencies p… (compare)

  • Apr 27 18:29
    cornerman synchronize #549
  • Apr 27 18:29

    cornerman on scala3

    fix compile errors (compare)

johannes karoff
@cornerman
Awesome!
We should start cross-compiling for scala 3 i guess :)
1 reply
bblfish
@bblfish:matrix.org
[m]
I found a nice intro to fs2 and cats effects for UI development. https://twitter.com/bblfish/status/1457992937804124166
That one writes directly to the dom interestingly enough, but is otherwise very FP. Is there any larger project one can look at with a lot of IO that uses OutWatch?
bblfish
@bblfish:matrix.org
[m]
Actually I went off to study cats-effect and co, but I am not sure if you work with cats-effect, and so http4s.
At least I could not find any references in the build file.
bblfish
@bblfish:matrix.org
[m]
(well it says you use cats-effect on the front page, but I guess it must be imported into the project in some indirect way)
bblfish
@bblfish:matrix.org
[m]
Ah cool the sbt dependencyTree tells me it is colibri that colibri that imports it.... (nice tool)
bblfish
@bblfish:matrix.org
[m]
ok, so I guess the latest http4s-dom uses cats-effects 3.x whereas colibri is using 2.6.1
moritz bust
@busti

@bblfish:matrix.org afaik technically projects that directly use a library should define it in their sbt file rather than relying on it through other dependencies. We should probably do that.

http4s-dom looks nice. I was wondering when they would ship their http client to js.

bblfish
@bblfish:matrix.org
[m]
they just release http4s-dom 1.0.0-M29 btw.
moritz bust
@busti
Studying cat's effect is a nice idea in general. The typelevel style in general is used in a big portion of scala libs and it's good to know what you're looking at when encountering libraries or code using the style.
I personally only use a single websocket connection in my project, but if I ever need to talk to a rest api it's probably a good choice
bblfish
@bblfish:matrix.org
[m]
For The Solid Project we write apps for the web thought of as one giant hyper-data RESTful system. Clients follow links from one server (Pod) to another to build up UI elements. So even though websockets are also used, we really need streaming http libraries.
bblfish
@bblfish:matrix.org
[m]
I have written my server in Akka but I think having akka on the client would be a bit heavy on the client. So that means I need to learn another set of libraries on this. Cats-effect seemed indeed like a good thing to try out, and as you say it is widely used...
elyphas
@elyphas
I have some kind of problem when I use onInput the focus on element input is loss more or less, because the element is showing is focused but the cursor is loss.
this happens on chrome but not on firefox.
I was searching for some solutions on google but I have some Observer connecting on this element so I don't quite get the solution.
Any idea please. :-)
this my code:
  val onChangingValueTxt =
        SyncIO(
          onInput
             .value
             .transformLifted( (e: Observable[String]) =>
               e
               .distinctUntilChanged
               .withLatestFrom(hdlFieldActive){ case (txt: String, (field: String, currentValue: JsonValue)) =>
                    val currentValue2: JsonValue = Try {
                            wrapValue(txt, currentValue)
                    } match {
                            case Success(value) => value
                            case Failure(exception) => JsonNull
                    }

                  (field, currentValue2)
                }
             ) --> hdlChangingValue
        )
elyphas
@elyphas
making a filter( x => x.length > 5) loses the cursor after 5 keys
elyphas
@elyphas
I found the problem all of that is inside the Try block:
    val mountCellFocusSelectContent = Observer.create[(dom.Element, String, String)] { case (elem, inputType, idTxt) =>
        if (idTxt == elem.id) {
                val txt = if ( inputType == "input" ) elem.asInstanceOf[html.Input] else elem.asInstanceOf[html.TextArea]
                Try {
                    val range = dom.document.createRange
                    val sel = scalajs.dom.window.getSelection
                    sel.removeAllRanges
                    range.selectNodeContents(txt)
                    sel.addRange(range)
                } match {
                    case Success(value) =>
                        txt.focus
                    case Failure(exception) => alert("Hubo un error al convertir el valor del componente: line:102 from Grid3 " + exception.getMessage())
                }
        }
    }
the solution seems is this:
$('#Search').focus(function() {
    setTimeout((function(el) {
        var strLength = el.value.length;
        return function() {
            if(el.setSelectionRange !== undefined) {
                el.setSelectionRange(strLength, strLength);
            } else {
                $(el).val(el.value);
            }
    }}(this)), 0);
});
What would be the correct translation to Outwatch ?
the comment about the problem is this:
"It seems like the focus event is fired before the cursor is placed when you focus an input, a hacky workaround would be to use a setTimeout like so:"
elyphas
@elyphas

well I did this:

    val mountCellFocusSelectContent = Observer.create[(dom.Element, String, String)] { case (elem, inputType, idTxt) =>
        if (idTxt == elem.id) {
                val txt = if ( inputType == "input" ) elem.asInstanceOf[html.Input] else elem.asInstanceOf[html.TextArea]
                Try {
                    if (window.navigator.userAgent.indexOf("Chrome") == -1 || window.navigator.userAgent.indexOf("Safari") == -1) {
                        val range = dom.document.createRange
                        val sel = scalajs.dom.window.getSelection
                        sel.removeAllRanges
                        range.selectNodeContents(txt)
                        sel.addRange(range)
                    }
                } match {
                    case Success(value) =>
                        txt.focus
                    case Failure(exception) => alert("Hubo un error al convertir el valor del componente: line:102 from Grid3 " + exception.getMessage())
                }
        }
    }

althought I don't know if is right. :-)

johannes karoff
@cornerman
We finally have a real maven release again. Welcome version 1.0.0-RC3. Thank you to @FloWi for setting this up in our github actions!
moritz bust
@busti
@cornerman Quick question, is there a reason why are the map, filter, collect and mapFilter methods are implemented using transformSinkWithExec and contraMap, contraFilter and so on, while all the others modify the source?
moritz bust
@busti
Also, why do some methods use the Observable.method(source)(args) syntax, while others use the source.method(args) syntax? Feels like some verbosity could be avoided by switching to the latter.
johannes karoff
@cornerman
@busti That is a great question! Actually it is because dealing with an Observable means, we need to handle a subscriptions: adding callbacks onMount and onDismount. Operating on an Observer, is great because you can just push things into an Observer without state. So, it is kind of a performance optimization to prefer Observer operations.
We do not have syntax extensions for Source, Sink generally, because I felt, it would be too intrusive, when just working with Monix or scalarx or airstream natively. Maybe, just hide them under a syntax._-import? It is nicer too write. And that is an advantage of the Sink, Source archtiecture.
Ah, or a we just working on Observable/Observer there?
moritz bust
@busti
Yeah, coding against observer is probably more performant in many cases, I never thought about that, but after familiarizing myself with colibri it makes sense.
EmitterBuilder kinda is like a wrapper in many cases, which makes it difficult to refactor in many cases, but I like the API it produces a lot.
moritz bust
@busti
I agree, syntax extensions for Source and Sink would feel wrong because usually algebraic methods are members these days. I hope that's going to change with scala 3 and the extension keyword. No more .map on everything. Just a single global extension method for all functor instances.
But right now in colibri you are able to call member methods on observables a.withLatest(b) and the method on the static object Observable.withLatest(a, b). While I think its fine to have both, outwatch tends to use them at random in some places and I believe it would make the code more readable to make that a little more consistent.
elyphas
@elyphas
Hi, I am trying to update to 1.0.0-RC5
but I get this error:
not found: type Handler
[error]   def cmpDate(hdl: Handler[Long]) =
if I search for the location I found it on this path:
import outwatch.reactive.handler.Handler
instead of this:
import outwatch.reactive.handlers.monix._
is it right to make the change ?
elyphas
@elyphas
or Handler is deprecated ?
johannes karoff
@cornerman
Hi @elyphas! Yes, we have actually deprecated Handler. To me, this concept feels too complex, that you indirectly create new instances of your stream-types (just with the help of a magic import). It just seems more straightforward to directly create your subjects with the library of your choice. The intent is much more clear.
You are still able to render any kind of Observable in your dom nodes.
Both are still available (monix and colibri handlers). Just deprecated.
elyphas
@elyphas
@cornerman ; ah thank you
elyphas
@elyphas

any idea why this code works perfectly, but if I put the class FrmClass on another file it doesn't?

class TestingOnClassSpec extends JSDomAsyncSpec {
  class FrmClass {
    val testClick = new Observer[String] {
        def onNext(elem: String): Future[Ack] = {
            Future {
                println(elem)
                Continue
            }
        }
        def onError(ex: Throwable): Unit = { println(ex.printStackTrace.toString) }
        def onComplete(): Unit = println("O completed Handler")
    }
    val but = button( idAttr := "cmdTestOnClass", "Save", cls := "myButton",
        onClick.use("on the observer a class ----------") --> testClick
    )
  }
  it should "be test the save button" taggedAs(ButtonTestingTest) in {
    val frm = new FrmClass
    for {
        _ <- OutWatch.renderInto[IO]("#app", frm.but)
    } yield {
        val element = document.getElementById("cmdTestOnClass")
        sendEvent(element, "click")
        succeed
    }
  }
}

something lacking me ?

elyphas
@elyphas
none errors in fact is succeed but the println doesn't shows the message
elyphas
@elyphas
this happens when I tried to testing
elyphas
@elyphas
I want to catch the event keyDown from a component and send it to another component and there manage it.
How can do it in a reactive way?
Or only this way I can do it?
new Event ("keyDown", new EventInit{
         bubles = true
         cancelable
    }
)
johannes karoff
@cornerman
Hi @elyphas , How about having a subject to move the event between two components? Like this:
val subject = Subject.replay[dom.Event]
div(
  input(onKeyDown --> subject),
  div(subject.map(_.toString))
)
elyphas
@elyphas
@cornerman , cool, I will try
thank you