-
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
TargetOps assume incorrect type for target and currentTarget #93
Comments
I'm in favor of version 1. It's simple and flexible. Version 2 requires more knowledge and imports about the required HTML elements. |
Related: scala-js/scala-js-dom#228 |
This is not true, |
Oh, you are right! |
For something like this, we would need This would then be for |
Hrm. In Scala Dom Builder & Laminar I have properly typed references to real JS nodes:
Having that type param available inside the I haven't actually tried this yet, there could be some problems e.g. in my case |
Good idea! That might actually work. Will give it a try! |
Hmm, in general this works and the types of the element get inferred correctly. I have a So then I have something like this for subscribing events to an def -->[Elem <: dom.Element](sink: Sink[_ >: Event]): VDomModifierBuilder[Elem, Emitter] = ... When I then try to make use of the def --->[Elem <: dom.Element, O](f: Event with TypedCurrentTargetEvent[Elem] => O)(sink: Sink[_ >: O]): VDomModifierBuilder[Elem, Emitter] = ... |
On top of the scala-dom-types branch I have started to build a Currently the best I can come up with for the input(
input.event(onChange).map(_.currentTarget.value) --> strHandler
) As opposed to the following, which does not compile as input(
onChange.map(_.currentTarget.value) --> strHandler
) So, all old code using Update: Ok, this is also possible: input(
_(onChange).map(_.currentTarget.value) --> strHandler
) |
Seems like we need a macro for the tags like |
I hope not, because a macro would not really work with scala-dom-types as it is now. Then the definitions of the tags like And this problem is only because of how we build our eventemitters. A simple version like this could easily work: val node = div("bla")
val events = node.event(onChange) : Observable[Event with TypedCurrentTargetEvent[dom.html.Div]] |
@cornerman What is Edit: Nevermind, I missed the link to your branch. I see it now: |
@raquo oh, that was an example of how "short" i could get the workaround to make an extra step to type the current target. I have made the modifiers a function I am not really happy with it, but I cannot get type inference to help me in the case of events. Because I need the element type at the |
Behaviour has changed with #139, but still just assumes |
Currently, we have
InputEvent
for representing all form events. But InputEvent assumes the wrong type of theeventTarget
and casts toHTMLInputElement
. Even events likeonInput
can trigger on elements like<input>
,<textarea>
,<select>
, or<... contenteditable>
. The other events have different possible element targets.We try to tackle this in
scala-dom-types
and for most events we can only assumehtml.Element
for typing theeventTarget
. It is better than typeEventTarget
, but the problem is, you still do not have access to the.value
,.valueAsNumber
,.checked
properties (we currently have that).Four options for not having to write
.asInstanceOf[HtmlInputElement].value
:targetValue
,targetValueAsNumber
,targetChecked
on the event. Something like this:I kind of like this option, as it is short and will work for any element that could be the target. But has to make certain assumptions, especially for implementing something like
targetValueAsNumber
,targetChecked
.targetT
as a shortcut fortarget.asInstanceOf
:More flexible, as is
asInstanceOf
, but not typesafe. If you ever come to change the embedding element, it will fail.targetInput
,targetTextarea
,targetSelect
. Similar like the one before, but saving you from importing the type parameter.Nicer to write than 2), but same drawback.
currentTarget
of the event, as it is always the type of the element, to which the event listener was attached. So on the user side, we hopefully could write something likeinput(onChange(_.currentEvent.value) --> strHandler)
.I like this option most, as it is typesafe and does not make us handle specific use-cases but the general use-case.
What do you think?
The text was updated successfully, but these errors were encountered: