-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CurrentTarget / Target ops #139
Conversation
Thanks for working on this. I did not have time to make a full review of the changes just yet. But I do not get why we need these generic methods for currentTarget Also, why do we decide that |
You are correct, there's no benefit from having the generic methods for casting to different event targets, they will behave the same way. I've removed them and simplified the PR. |
@@ -426,4 +427,69 @@ class DomEventSpec extends JSDomSpec { | |||
docClicked shouldBe true | |||
} | |||
|
|||
"TagWith" should "correctly work on events" in { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename TagWith to TargetOps in test string here
def checked: EmitterBuilder[E, Boolean] = builder.map(e => e.currentTarget.asInstanceOf[html.Input].checked) | ||
} | ||
|
||
implicit class TargetMap[E <: Event, O <: Event](builder: EmitterBuilder[E, O]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue against mapping to EventTarget here, as _.map(_.target)
seems good enough to me and we do not have the same helper functions for other event properties. Instead we can only define a target object with the above methods in an implicit class for the EmitterBuilder.
Like this:
implicit class TargetAsInput[E <: Event, O <: Event](builder: EmitterBuilder[E, O]) {
object target {
def value = ???
def valueAsNumber = ???
def checked = ???
}
 }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'll update the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR improves the handling for using currentTarget and target. For now, this is nice to use. But I am still unhappy that we do not have any kind of typesafety here - which we should definitely tackle in an upcoming PR.
This PR is a result of the discussion we had in #119 (comment). It still uses the non-typesafe cast for
currentTarget
, but allows for a nicer syntax and uses theTagWith...
typeclasses for restricting the type the target can be cast to.The syntax is the following:
currentTarget
useshtml.Input
by default as the underlying event target:The PR removes
onInputString
,onInputNumber
andonInputChecked
and updates the deprecation message oninputString
,inputNumber
andinputChecked
to useonInput.value
,onInput.valueAsNumber
andonChange.checked
instead.currentTarget
, but only if theTagWith...
typeclasses are implemented for it (html.TextArea
,html.Select
).target
, the type fromTypedTargetEvent
is used by defaultTypedTargetEvent
is not specific enough it's possible to force a more specific type: