Including LatestHTMLEvents.of, which automatically infers the event type based on the type class defined in org.lrng.binding.html
Including LatestHTMLEvents.of, which automatically infers the event type based on the type class defined in org.lrng.binding.html
Given an HTML button element,
import org.lrng.binding.html, html.autoImports.xml.attributes import org.scalajs.dom.MouseEvent @html val myButton = <button>Click me!</button>
when creating the latest click event binding with the help of LatestHTMLEvents.of,
val latestClickEvent = LatestHTMLEvents.of(myButton.value, attributes.onclick)
the event type should be inferred as org.scalajs.dom.MouseEvent,
val _ = latestClickEvent: LatestEvent[MouseEvent]
and the MouseEvent
properties, like clientX
, can be used in the derived Bindings
def clientXBinding = Binding { val mouseEvent: Option[MouseEvent] = latestClickEvent.bind mouseEvent.map(_.clientX) }
Author:
杨博 (Yang Bo)