shadaj / slinky

Write Scala.js React apps just like you would in ES6
https://slinky.dev
MIT License
656 stars 57 forks source link

Synatic sugar for setting event handlers with useCapture #689

Closed malcolmredheron closed 3 months ago

malcolmredheron commented 11 months ago

When using react directly (say, from Typescript or JS), I can set an event handler that runs during the capture phase of event dispatch like this: div({onKeyDownCapture: handler})

Slinky seems to be missing the subclasses of slinky.core.TagElement to let this happen naturally. So when I want to do this, I do something like:

              new slinky.core.AttrPair[_onKeyDown_attr.type](
                "onKeyDownCapture",
                (event: slinky.web.SyntheticKeyboardEvent[org.scalajs.dom.html.Div]) =>
                  js.console.log("onKeyDownCapture", event.nativeEvent.eventPhase)
              )

Have you thought about adding them? I'm happy to help, but would need some pointers. Are these files auto-generated? I hope so. From what? I'd be even more happy to sponsor this project if that helps to get this kind of thing done.

shadaj commented 11 months ago

Yeah, these are all generated in https://github.com/shadaj/slinky/blob/main/generator/src/main/scala/slinky/generator/Generator.scala, which uses the JSON files in the web subproject to generate typed attributes. So that could be extended to generate the capture variants!

Happy to review any PRs for improvements around this!

malcolmredheron commented 11 months ago

Thanks! This will be the first time that I've modified Scala code outside my source tree. Do you have a recommended way for me to link my project against a fork that I make before I send you a PR?


Sent with Superhuman ( https://superhuman.com/refer/cmsqjaxn ). Please favor brief email ( http://three.sentenc.es/ ) over chat, especially for tasks. For chat (+1-415-235-0687), WhatsApp is best. Never Signal unless there are legal issues.

On Mon, Dec 25, 2023 at 3:07 PM, Shadaj Laddad < @.*** > wrote:

Yeah, these are all generated in https:/ / github. com/ shadaj/ slinky/ blob/ main/ generator/ src/ main/ scala/ slinky/ generator/ Generator. scala ( https://github.com/shadaj/slinky/blob/main/generator/src/main/scala/slinky/generator/Generator.scala ) , which uses the JSON files in the web subproject to generate typed attributes. So that could be extended to generate the capture variants!

Happy to review any PRs for improvements around this!

— Reply to this email directly, view it on GitHub ( https://github.com/shadaj/slinky/issues/689#issuecomment-1869146321 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAAOIXIBTKFCWJPYAOUQWWDYLIBMBAVCNFSM6AAAAABBCBL3D2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRZGE2DMMZSGE ). You are receiving this because you authored the thread. Message ID: <shadaj/slinky/issues/689/1869146321 @ github. com>

shadaj commented 11 months ago

You'll want to commit to a branch in your local copy, and then run sbt publishLocal, which will generate a version based on the current git commit. You can then just point your projects against that version and it should work!

malcolmredheron commented 11 months ago

Cool. I'm trying to add onBeforeInput for a start. Some questions so far:

shadaj commented 10 months ago

To re-generate, you need to run sbt web/clean. Unfortunately, due to the sheer number of generated files, incremental compilation isn't super helpful so the iteration time will be pretty slow.

To build for Scala 3, you'll want to run ++3.x.x (for your preferred version` in the SBT shell.