-
Notifications
You must be signed in to change notification settings - Fork 161
EventTarrget.addEventListener event subclass #82
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
Conversation
The first commit should not be in this PR. |
My concern with this change is that it is not typesafe. The type of event depends on the |
The first commit is a separate PR #81. It was included here since I wanted to include an example testing the functionality.
I am new to Scala and still a bit confused regarding its type system. Can you show an example demonstrating it is not type safe? I figure out that if I tried to parametrize only the function parameter it wouldn't compile because of type safe issues. So my solution was to parametrize the whole function (and not just the function parameter). My understanding is that this way scala would create different type-safe versions of the function based on the parameter type. |
@schettino72 The type that |
Concretely, with your change one can write x.addEventListener("mousedown", { e: dom.KeyboardEvent =>
// boom
} This blows up because the name of the event and the event handler type do not match up. |
Reference to the SIP http://docs.scala-lang.org/sips/pending/42.type.html Thanks for explaining... I guess I understand now. But IMO the situation is a bit different from While So my conclusion is that it is indeed not type safe but there is no other way (Singleton types could solve the problem only for pre-defined events generated by the browser - not custom user defined events). Or do you have any other suggestions on how to write the code from my example? |
Yep, doesn't look like there is any way to define this method properly. The current version is the only typesafe variant. But at the same time, it's true that it is annoying to use in practice. Maybe this is a case where convenience should prevail over safety. Anyway, I believe most people write their handler with a hard So I would agree with this change. It shouldn't be merged before #81 is merged and this is rebased, or the first commit is removed in favor of just having the change in the definition. |
…b-classes of Event.
I removed the first commit and rebased. Thanks. |
LGTM |
EventTarrget.addEventListener event subclass
yay =) |
Currently it is not possible to use an event listener that takes a subclass of Event as a parameter.
This change enables any subclass of Event to be taken as a parameter of the listener.