OlivierBlanvillain / monadic-html

Tiny DOM binding library for Scala.js
https://olivierblanvillain.github.io/monadic-html/examples/
MIT License
225 stars 24 forks source link

allowing event handlers that return Rxs #105

Closed bbarker closed 2 years ago

bbarker commented 6 years ago

Use case:

            def actionHandler(ev: MouseEvent): Rx[Unit] = action.command().map {
              case Some(actRes) => actionResult := actRes
              case None => println("no RunResult")
            }

If this makes sense, would it be OK to publish an RC2 - I have some production code that may depend on this working, though I guess i could get around it by manually working with Cancelables

OlivierBlanvillain commented 6 years ago

So, you want to use MouseEvent => Rx[Unit] an a xml attribute... Could you used Rx[MouseEvent => Unit] instead?

bbarker commented 6 years ago

Good point, this seems to work:

            val actionHandler = action.command().map{ actResMaybe =>
              (_: MouseEvent) => actResMaybe match {
                case Some(actRes) => actionResult := actRes
                case None => println("no RunResult")
              }
            }

Thought it feels slightly unnatural to have to do so - I'll adjust the PR later today to address your comment, thanks!

OlivierBlanvillain commented 6 years ago

If Rx[MouseEvent => Unit] works for you then I think we don't need to change anything as you can get an instance for that type with rxAttributeEmbeddable(function1AttributeEmbeddable[MouseEvent])

bbarker commented 6 years ago

Oh, yes, it works, and I'm happy enough with it for now. But this PR would allow more expressions (and shorter expressions) to work that are equivalent, which seems to be a desirable goal.

OlivierBlanvillain commented 2 years ago

@bbarker I'm closing your long-standing PR as part of my repo clean-up, I hope you don't mind. Feel free to reopen/ping me if you want to bring anything back to life!