Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jun 12 23:33
    fdietze reopened #618
  • Jun 12 23:33
    fdietze commented #618
  • Jun 01 22:19
    fdietze demilestoned #447
  • Jun 01 22:19
    fdietze demilestoned #305
  • Jun 01 22:19
    fdietze edited #447
  • Jun 01 22:19
    fdietze demilestoned #451
  • Jun 01 22:19
    fdietze demilestoned #354
  • Jun 01 22:05
    fdietze edited #620
  • Jun 01 22:04
    fdietze opened #620
  • Jun 01 22:04
    fdietze milestoned #620
  • Jun 01 22:02

    fdietze on master

    Deploy website Deploy website … (compare)

  • Jun 01 21:59

    fdietze on v1.0.0-RC8

    (compare)

  • Jun 01 21:56
    fdietze synchronize #553
  • Jun 01 21:56

    fdietze on scoverage

    Add Scoverage Plugin (compare)

  • Jun 01 21:50

    fdietze on scoverage

    Update plugins.sbt (compare)

  • Jun 01 21:50
    fdietze synchronize #553
  • Jun 01 21:49
    mergify[bot] synchronize #597
  • Jun 01 21:49
    mergify[bot] commented #597
  • Jun 01 21:49
    fdietze commented #597
  • Jun 01 21:49
    fdietze commented #597
Rohan Sircar
@rohan-sircar
You need to import import outwatch.reactive.handlers.monix._
Here are all of my imports just in case https://pastebin.com/3zm6eZTg
Rohan Sircar
@rohan-sircar
Btw everyone my PR to update outwatch router to latest versions of scala/outwatch got merged - clovellytech/outwatch-router#9 . So there's a functioning router for outwatch now.
goes back to sleep
Aleksandr Bogdanov
@laniakea-landscape_gitlab

Here are all of my imports just in case https://pastebin.com/3zm6eZTg

No way =( It compiles after addition of this:

    def scheduler: Scheduler = Scheduler.global
    def options: IO.Options  = IO.defaultOptions.withSchedulerFeatures(scheduler)
    implicit lazy val catsEffect: ConcurrentEffect[Task] =
      new CatsConcurrentEffectForTask()(scheduler, options)

But nothing on the screen, unfortunately. Even no input field.

elyphas
@elyphas
@laniakea-landscape_gitlab; Are you sure your div id in your html correspond where outwatch is going to render?
Aleksandr Bogdanov
@laniakea-landscape_gitlab
@elyphas Sure. Checked it again.
Rohan Sircar
@rohan-sircar
@laniakea-landscape_gitlab you definitely don't need any of that. I'll upload my project tomorrow.
Rohan Sircar
@rohan-sircar
Rohan Sircar
@rohan-sircar
@laniakea-landscape_gitlab well? did it work?
Raphael Mäder
@randm-ch

Hello there. I'm trying to get into outwatch. It seems to me that the docs are a bit outdated, what's the most recent/best source?
In particular, at the moment I want to get a simple example to work:

import cats.effect._
import outwatch._
import outwatch.dsl._
import outwatch.reactive.handler._
import outwatch.util._
import scala.concurrent.ExecutionContext.Implicits.global

object Main extends IOApp {
  private val app = for {
    hdl <- Handler.createF[IO]("")
    qry <- IO.pure(hdl.map(query => Http.Request(s"https://someurl.org?query=$query")))
    res <- IO(Http.get(qry).map(_.body))
    xml <- IO.pure(div(
      input(onInput.value --> hdl),
      span(child <-- res)
    ))
    rnd <- OutWatch.renderInto[IO]("#app", xml)
  } yield rnd

  override def run(args: List[String]): IO[ExitCode] =
    app.as(ExitCode.Success)
}

but child is not available. Am I missing an import? Or did something change? Thanks!

johannes karoff
@cornerman
Hi @randm-ch , yeah the docs on the outwatch page are a bit outdated. Please refer to the github readme. The documentation there is up to date.
I will have to do something about the old webpage and remove the outdated content there.
For the question here: you can just leave out the child <-- and just put the observable into the element directly: span(res)
Raphael Mäder
@randm-ch
Perfect, thanks a bunch for the info & all your work :)
Aleksandr Bogdanov
@laniakea-landscape_gitlab

@laniakea-landscape_gitlab well? did it work?

@rohan-sircar Sorry for silence, I will look in several days. Was extremely busy last weeks.

Per Wiklander
@PerWiklander
Has anyone used Akka.js and Akka Streams and Actors for the state handling layer of an Outwatch application?
moritz bust
@busti
@PerWiklander I haven't used akka specifically, but what I am trying to do is very similar to akka. But that comes from a person who has little to no experience with akka.
That being said, I am very interested in that discussion in general.
johannes karoff
@cornerman
@PerWiklander Never did that, but I guess using akka streams and actors in outwatch should be quite straight forward. We have a typeclass Source and a typeclass Sink. You should be able to implement them with Stream and Actor respectively. Then you can use them in the outwatch dsl.
Sait Sami Kocataş
@Deliganli
hi everyone, how could I use a canvas, update it with observable (or fs2.Stream)?
johannes karoff
@cornerman
Hi there, what exactly do you want to do with the canvas? They are a bit tricky. I did this to be able to paint a chart inside of it:
    canvas(
      managedElement { elem =>
        val context = elem.asInstanceOf[dom.html.Canvas].getContext("2d").asInstanceOf[org.scalajs.dom.raw.CanvasRenderingContext2D]
        // do something with context

        cancelable(() => /*destroy something*/)
      }
    )
Does that help?
Sait Sami Kocataş
@Deliganli
thanks @cornerman I will try it out when possible :)
I was gonna draw some circles and update their position etc based on an event stream, thinking to do this in a canvas. I have no idea how frontend works honestly, just trying out.
elyphas
@elyphas

Hi, is there a way to not trigger an event when the app start? in this code:

  def getId = ( hdlFiscalPeriod: Observable[Int], hdlFolio: Observable[String])
        .parMapN { case (fiscal_period: Int, folio: String) => (fiscal_period,  folio) }

onInput
            .value
            .debounce(800 milliseconds)
            .transformLifted{ e: Observable[String] =>
              e
                .distinctUntilChanged
                .debounce(800 milliseconds)
                .withLatestFrom(getId) {case (txt@_, idCreditStoreDocument) =>
                    println("#################################")
                    idCreditStoreDocument
                }
} --> repo.eventListItems

The problem I have is that repo.eventListItems is making the query but with one data and I need two.
I tried filter after debounce but it is ignore
I have two inputs and one is by default.
year and number the year is by default so this is year is triggering the event. at the start of the app.

Felix Dietze
@fdietze
:tada: I finally found the time to update the readme and website of outwatch: https://github.com/outwatch/outwatch and https://outwatch.github.io/docs/readme.html
Let me know what you think :)
moritz bust
@busti
Cheers :tada:
moritz bust
@busti
@fdietze The examples look really good
Felix Dietze
@fdietze
Thank you :)
ioleo
@ioleo
Hi, I'm need an event handler to access the elemet's scrollTop position, but can't figure out how. I've tried:
import outwatch._
import outwatch.dsl._
import org.scalajs.dom.raw.HTMLElement
import zio.Task
import zio.interop.catz._

object Header {
  def apply(): HtmlVNode = {
    val logo = Task {
      val isDetached = events.document.onScroll.map { e =>
        val scrollTop = e.target.asInstanceOf[HTMLElement].scrollTop
        println(s"top dist = $scrollTop")
        if (scrollTop > 50) "detached" else "attached"
      }.debounceMillis(250)

      div(
       // ...
         className <- isDetached
       )
    }
    div(logo)
  }
}
ioleo
@ioleo
However it throws at runtime. I guess the asInstanceOf is wrong. What would be the correct way?
ioleo
@ioleo
Alright I see now why it fails e.target is actually HTMLDocument.
ioleo
@ioleo
For future reference, the solution is:

    val fixedOnScroll = events.document.onScroll.debounceMillis(100).map { e =>
      val documentElement = e.target.asInstanceOf[HTMLDocument]
      val scrollDistance = documentElement.documentElement.scrollTop
      if (scrollDistance > 50) VDomModifier(position.fixed, left := "50%", marginLeft := "-250px")
      else VDomModifier(position.relative, left := "auto", marginLeft := "auto")
    }

    div(
      // ...
      fixedOnScroll
    )
moritz bust
@busti
Glad to hear that you found a solution.
Aleksandr
@steakoverflow-me
Hello to all!

Hi, I'm need an event handler to access the elemet's scrollTop position, but can't figure out how. I've tried:

import outwatch._
import outwatch.dsl._
import org.scalajs.dom.raw.HTMLElement
import zio.Task
import zio.interop.catz._

object Header {
  def apply(): HtmlVNode = {
    val logo = Task {
      val isDetached = events.document.onScroll.map { e =>
        val scrollTop = e.target.asInstanceOf[HTMLElement].scrollTop
        println(s"top dist = $scrollTop")
        if (scrollTop > 50) "detached" else "attached"
      }.debounceMillis(250)

      div(
       // ...
         className <- isDetached
       )
    }
    div(logo)
  }
}

I can't get how you made it to work? I mean div(logo) when logo is the zio.Task. For me there is a error like

Found: (logo : zio.Task[outwatch.HtmlVNode]) 
Required: outwatch.VDomModifier
Felix Dietze
@fdietze
@steakoverflow-me I think ZIO Task is not supported yet. Use IO or Monix Task instead. @cornerman used to work on ZIO support, but it's not merged yet: outwatch/outwatch#442
johannes karoff
@cornerman
You should be able to use https://github.com/zio/interop-cats, because it gives you an Effect instance for zio tasks. You get this implicit via the import: import zio.interop.catz._. Though you need an implicit runtime in the scope.
As @fdietze pointed out, we are currently working on a better zio support in the PR, but i think, it might need some more time to be merged. Until then interop-cats is the way to go.
@steakoverflow-me ^
moritz bust
@busti
I can confirm what @cornerman said about the implicit runtime. I have been toying around with zio for some time now aswell and it works quite well with outwatch.
Try adding this like to your scope for example:
implicit def runtime = Runtime.default
Not the purest thing, but it does the job for getting started.
moritz bust
@busti

@cornerman I have made some progress implementing what I was talking about recently.
Please take a look at https://github.com/busti/hummingbird
I have started implementing the concept into outwatch on this branch: https://github.com/busti/outwatch/tree/integrate_hummingbird

Unfortunately my current implementation is flawed. Since using the library requires passing around instances of the base trait and not implementations of it, there will be instances of them at every call. Value-Classes don't work in this case.

I will probably try to refactor what I have so far to remove that limitation.
But what do you think of the general idea and of how the interface is designed?

bblfish
@bblfish:matrix.org
[m]
Hi, has there been a recent blog post or talk on Outwatch since the 2017 talk, giving some idea of how it has evolved?
bblfish
@bblfish:matrix.org
[m]
btw. where does the name OutWatch come from? My first impression was that it could be Australian, something to do with the Outback ...
bblfish
@bblfish:matrix.org
[m]
I used scalajs-react 6-7 years ago. I guess outwatch is more closely designed for scala and has a number of advantages. Also I was wondering how it compared with Laminar. I wonder if Laminar making changes directly to the browser actually speeds things up or slows things down.
bblfish
@bblfish:matrix.org
[m]
going through the docs. Very helpful.
bblfish
@bblfish:matrix.org
[m]

Laminar's library Airstream has the following to say:

Some reactive UI libraries such as Outwatch give you a way to bind the lifecycle of subscriptions to the lifecycle of corresponding UI components, and that automatically kills the subscription (removes the observer) when the UI component it relates to is destroyed. However, the underlying streaming libraries that such UI libraries use have no concept of such binding, and so in those libraries you can manually call stream.addObserver and create a subscription that will not be automatically killed when the UI component that it conceptually relates to is unmounted.

Is that still true? Is that easy to fix?

bblfish
@bblfish:matrix.org
[m]
I watched your 2017 talk in full now.
moritz bust
@busti

@bblfish:matrix.org I was personally drawn to outwach because it combined the syntax of scalatags with monix, a library I had already used before. We have since replaced monix with an abstraction that makes it possible to use other reactive programming libraries such as scala.Rx and perhaps fs2, we have also adopted the F[_] pattern for effects, which basically allows me to share large portions of code between my backend server and the frontend and something that makes the library stand out more than it did when I first started using it.
There is still a lot of work going on regarding the streaming and effect abstraction parts though to allow for more library support such as zio and zio-streams.

I must admit that I am not as familiar with laminar as I want to be, but the whole ownership concept is super interesting and definitely something I want to take a deeper dive into in the future.
There is probably some interesting stuff that laminar does that we cannot do as easily since it's very tightly integrated with it's own streaming lib.

Since we want to support all kinds of streaming libraries handling lifecycles outside of those that arise from the DOM is outside our scope and must be handled by those libraries. I.e. I would love to know how fs2 solves the problems the airstream docs are talking about.

I personally like the F[_] functional programming style for libraries which is why I avoided using laminar in the past and I would like to migrate my front-end to zio in the future which is why I am looking into supporting it at the moment.

That being said, interacting with the dom directly is really interesting and probably somewhat faster. We currently use the javascript v-dom library (snabbdom)[https://github.com/snabbdom/snabbdom] for dom interaction.
I have some ideas on how we could model dom diffing directly in outwatch I never did anything specific.

bblfish
@bblfish:matrix.org
[m]
Thanks for the updates.
@busti Re the speed of updating the DOM directly or virtually, I can see arguments going both ways. If the events can be directed to small parts of the virtual dom so that it does not need to be recomputed completely, and if writing the diff can be done more efficiently in one go. rather than a lot of small changes, I could see the VDOM method being faster.
I don't know much about zio - I have been using akka to tell the truth, but that won't work that well on the client :-)
I need to try out one library to get going. I was thinking of cats effects. We used scalaz in banana-rdf 8 years ago.