-
Notifications
You must be signed in to change notification settings - Fork 161
Invalid Event constructor #219
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
Comments
scalajs-dom is incorrect: scala-js/scala-js-dom#219
I don't know whether someone else has taken a look at this issue before, but I was curious to find out what it would take to fix it. It seemed simple enough at first glance... Most of the events are currently defined as a hierarchy of simple classes or traits with default constructors:
There are a few exceptions to this. For example, the
However, MDN lists all four of these events as having constructors that take one string argument, and an optional dictionary argument which is used to initialise the fields of the event, including the fields of its superclasses. Therefore the signature of I think in order to get the constructor signatures right, one would first have to define the hierarchy of types for the initialisation dictionaries. For the first three events listed above, that would look something like this:
Then the events themselves can be defined like this:
Given the number of events currently defined, I think it would not be straightforward to do this for all events. Unfortunately I don't see a good way to fix just the Related MDN pages: |
Yep, I think your analysis is correct, indeed. To mitigate the difficulty of migrating everything at once, we can start at the top of the hierarchy, and every time add a class Event(typeArg: String, init: js.UndefOr[EventInit] = js.undefined) extends js.Object {
protected def this() = this("") // for compatibility of subtypes
} |
now that we deprecate val evt = document.createEvent("HTMLEvents")
evt.initEvent("scroll", canBubbleArg = true, cancelableArg = true) What is the workaround for it? |
While it's not particularly pretty or type-safe, I think one workaround would be to use val eventInit = js.Dictionary("bubbles" -> true, "cancelable" -> false)
val event = js.Dynamic.newInstance(js.Dynamic.global.Event)("scroll", eventInit).asInstanceOf[dom.Event] |
* Add valid constructors that accept type name and init, as well as type-safe constructor options `***EventInit` * Removes invalid default (0 args) constructors since `new ***Event()` raises RuntimeError due to lack of required argument * Add `@deprecated` based on MDN
This:
breaks FireFox with
Spec shows it should be: https://developer.mozilla.org/en-US/docs/Web/API/Event/Event
The text was updated successfully, but these errors were encountered: