Skip to content

Conversation

@exoego
Copy link
Contributor

@exoego exoego commented May 15, 2019

Closes #219

  • 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
@exoego exoego force-pushed the event-constructor branch from 68e265a to 1c90901 Compare May 15, 2019 14:03
}

trait DeviceOrientationEventInit extends js.Object {
trait DeviceOrientationEventInit extends dom.raw.EventInit {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend importing dom.raw.EventInit at the top of the file, and then use EventInit everywhere. There might be other files where this comment applies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 882c079

var isReload: js.UndefOr[Boolean] = js.undefined
var request: js.UndefOr[Request] = js.undefined
var clientId: js.UndefOr[String] = js.undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there should be no blank line here.

* Returns the event's data. It can be any data type.
*/
val data: Any = js.native
val data: js.Any = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this become a js.Any? Is the data interpreted by JS code in any way? If it is just carried around, it should stay Any.

* MDN
*/
def data: Any = js.native
def data: String | Blob | ArrayBuffer = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDN says that data can be any data type, so this should stay Any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4457811

def initMessageEvent(typeArg: String, canBubbleArg: Boolean,
cancelableArg: Boolean, dataArg: js.Any, originArg: String,
lastEventIdArg: String, sourceArg: Window): Unit = js.native
cancelableArg: Boolean, dataArg: String | Blob | ArrayBuffer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be Any as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4457811

}

trait CustomEventInit extends EventInit {
var detailArg: js.UndefOr[js.Any] = js.undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure this should an Any as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4457811

@js.native
@JSGlobal
class BeforeUnloadEvent extends Event {
class BeforeUnloadEvent extends Event("") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more customary to use js.native as the arguments to another argument, in order to be confused that "" is not actually taken into account.

Copy link
Contributor Author

@exoego exoego May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I did not know the custom / tips.
That sounds reasonable.
Fixed in b7194a5

@JSGlobal
class MutationEvent(typeArg: String, init: js.UndefOr[MutationEventInit])
extends Event(typeArg, init) {
class MutationEvent extends Event("", js.undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it has no constructor, its constructor should be marked private. Otherwise there is nothing preventing to do new MutationEvent from the Scala side (with a run-time error).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 879d4ae

Used private[this] instead of private(), thanks to deprecation warning declaring private constructors in native JS classes is deprecated, because they do not behave the same way as in Scala.js-defined JS classes. Use `private[this]` instead. This will become an error in 1.0.0.

}

@deprecated("Obsolete.", "WHATWG DOM")
trait MutationEventInit extends EventInit {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this definition? Couldn't we just not define it at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 96938be

@sjrd sjrd changed the title Fix Event constructors Fix Event constructors May 16, 2019
@sjrd sjrd changed the title Fix Event constructors Fix #219: Fix Event constructors. May 16, 2019
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@sjrd sjrd merged commit 159526a into scala-js:master May 16, 2019
@exoego exoego deleted the event-constructor branch May 16, 2019 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants