Skip to content

Fix #219: Fix Event constructors. #367

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

Merged
merged 11 commits into from
May 16, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import scala.scalajs.js.annotation._

@js.native
@JSGlobal
class DeviceOrientationEvent(
`type`: String,
eventInitDict: DeviceOrientationEventInit
) extends dom.Event {
class DeviceOrientationEvent(typeArg: String,
init: js.UndefOr[DeviceOrientationEventInit])
extends dom.Event(typeArg, init) {

/** Z-Axis rotation in degrees. */
val alpha: Double = js.native
Expand All @@ -29,23 +28,23 @@ class DeviceOrientationEvent(
val absolute: Boolean = js.native
}

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


/** Z-Axis rotation in degrees. */
val alpha: Double
var alpha: js.UndefOr[Double] = js.undefined

/** X-Axis rotation in degrees. */
val beta: Double
var beta: js.UndefOr[Double] = js.undefined

/** Y-Axis rotation in degrees. */
val gamma: Double
var gamma: js.UndefOr[Double] = js.undefined

/**
* If true, this event data is has been produced using sensor fusion from
* the magnometer and other sensors. When false- only the gyroscope has
* been used.
*/
val absolute: Boolean
var absolute: js.UndefOr[Boolean] = js.undefined
}

object DeviceOrientationEventInit {
Expand Down Expand Up @@ -83,7 +82,9 @@ trait DeviceRotationRate extends js.Any {

@js.native
@JSGlobal
class DeviceMotionEvent extends dom.Event {
class DeviceMotionEvent(typeArg: String,
init: js.UndefOr[DeviceMotionEventInit] = js.undefined)
extends dom.Event(typeArg, init) {

/** Device acceleration with gravity removed. */
val acceleration: DeviceAcceleration = js.native
Expand All @@ -98,17 +99,18 @@ class DeviceMotionEvent extends dom.Event {
val interval: Double = js.native
}

trait DeviceMotionEventInit extends js.Any {
trait DeviceMotionEventInit extends dom.raw.EventInit {

/** Device acceleration with gravity removed. */
val acceleration: DeviceAcceleration
val acceleration: js.UndefOr[DeviceAcceleration] = js.undefined

/** Device acceleration including the force of gravity. */
val accelerationIncludingGravity: DeviceAcceleration
val accelerationIncludingGravity: js.UndefOr[DeviceAcceleration] =
js.undefined

/** The rate of rotation. */
val rotationRate: DeviceRotationRate
val rotationRate: js.UndefOr[DeviceRotationRate] = js.undefined

/** The sampling rate in seconds that data is received from the hardware. */
val interval: Double
val interval: js.UndefOr[Double] = js.undefined
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ trait Gamepad extends js.Any {
val mapping: GamepadMappingType
}

trait GamepadEventInit extends js.Any {
val gamepad: Gamepad
trait GamepadEventInit extends dom.raw.EventInit {
var gamepad: js.UndefOr[Gamepad]
}

object GamepadEventInit {
Expand All @@ -76,7 +76,9 @@ object GamepadEventInit {

@JSGlobal("GamepadEvent")
@js.native
class GamepadEvent(init: GamepadEventInit) extends dom.Event {
class GamepadEvent(typeArg: String,
init: js.UndefOr[GamepadEventInit] = js.undefined)
extends dom.Event(typeArg, init) {
val gamepad: Gamepad = js.native
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.scalajs.js
import scala.scalajs.js.|
import scala.scalajs.js.annotation._

import org.scalajs.dom.raw.{DOMError, Event, EventTarget}
import org.scalajs.dom.raw.{DOMError, Event, EventInit, EventTarget}

/**
* The MediaStream
Expand Down Expand Up @@ -462,9 +462,8 @@ object MediaStreamConstraints {
}
}

@js.native
trait MediaStreamTrackEventInit extends js.Object {
var track: MediaStreamTrack = js.native
trait MediaStreamTrackEventInit extends EventInit {
var track: js.UndefOr[MediaStreamTrack] = js.undefined
}

object MediaStreamTrackEventInit {
Expand All @@ -480,9 +479,9 @@ object MediaStreamTrackEventInit {

@js.native
@JSGlobal
class MediaStreamTrackEvent(`type`: String,
eventInitDict: MediaStreamTrackEventInit)
extends Event {
class MediaStreamTrackEvent(typeArg: String,
init: js.UndefOr[MediaStreamTrackEventInit])
extends Event(typeArg, init) {
val track: MediaStreamTrack = js.native
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import org.scalajs.dom.experimental.{
}
import org.scalajs.dom.raw.{WorkerGlobalScope, ErrorEvent}
import org.scalajs.dom.webgl.RenderingContext
import org.scalajs.dom.{Event, EventTarget, MessagePort}
import org.scalajs.dom.{Event, EventTarget, MessageEvent, MessagePort}
import org.scalajs.dom.raw.EventInit

@js.native
sealed trait FrameType extends js.Any
Expand Down Expand Up @@ -79,6 +80,12 @@ trait Client extends js.Object {
trait CanvasProxy extends js.Any {
def setContext(context: RenderingContext): Unit = js.native
}
trait FetchEventInit extends EventInit {
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.

}

/**
* See [[https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent FetchEvent]] on MDN
Expand All @@ -88,7 +95,8 @@ trait CanvasProxy extends js.Any {
*/
@js.native
@JSGlobal
class FetchEvent extends Event {
class FetchEvent(typeArg: String, init: js.UndefOr[FetchEventInit])
extends Event(typeArg, init) {

/**
* Boolean that is true if the event was dispatched with the user's
Expand All @@ -103,6 +111,14 @@ class FetchEvent extends Event {
*/
def request: Request = js.native

def preloadResponse: js.Promise[Response] = js.native

def clientId: String = js.native

def replacesClientId: String = js.native

def resultingClientId: String = js.native

/**
* See [[https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith respondWith]]
* page on MDN.
Expand Down Expand Up @@ -382,8 +398,9 @@ trait ServiceWorkerContainer extends EventTarget {
*
* MDN
*/
var onmessage: js.Function1[ServiceWorkerMessageEvent, _] = js.native
var onmessage: js.Function1[MessageEvent, _] = js.native
}
trait ExtendableEventInit extends EventInit {}

/**
* See [[https://slightlyoff.github.io/ServiceWorker/spec/service_worker_1/#extendable-event-interface ¶4.4 ExtendableEvent]]
Expand All @@ -394,21 +411,21 @@ trait ServiceWorkerContainer extends EventTarget {
*/
@js.native
@JSGlobal
class ExtendableEvent extends Event {
class ExtendableEvent(typeArg: String, init: js.UndefOr[ExtendableEventInit])
extends Event(typeArg, init) {
def waitUntil(promise: js.Promise[Any]): Unit = js.native
}

@js.native
trait ExtendableMessageEventInit extends js.Object {
var data: js.Any = js.native
trait ExtendableMessageEventInit extends ExtendableEventInit {
var data: js.UndefOr[js.Any] = js.undefined

var origin: String = js.native
var origin: js.UndefOr[String] = js.undefined

var lastEventId: String = js.native
var lastEventId: js.UndefOr[String] = js.undefined

var source: Client | ServiceWorker | MessagePort = js.native
var source: js.UndefOr[Client | ServiceWorker | MessagePort] = js.undefined

var ports: js.Array[MessagePort] = js.native
var ports: js.UndefOr[js.Array[MessagePort]] = js.undefined
}

/**
Expand All @@ -419,14 +436,14 @@ trait ExtendableMessageEventInit extends js.Object {
*/
@js.native
@JSGlobal
class ExtendableMessageEvent(`type`: String,
eventInitDict: ExtendableMessageEventInit)
extends ExtendableEvent {
class ExtendableMessageEvent(typeArg: String,
init: js.UndefOr[ExtendableMessageEventInit])
extends ExtendableEvent(typeArg, init) {

/**
* 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.


/**
* Returns the origin of the service worker's environment settings object.
Expand All @@ -449,17 +466,12 @@ class ExtendableMessageEvent(`type`: String,
def ports: js.Array[MessagePort] = js.native
}

@js.native
trait ServiceWorkerMessageEventInit extends js.Object {
var data: js.Any = js.native

var origin: String = js.native

var lastEventId: String = js.native

var source: ServiceWorker | MessagePort = js.native

var ports: js.Array[MessagePort] = js.native
trait ServiceWorkerMessageEventInit extends EventInit {
var data: 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 suspect this data should be js.UndefOr[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 7f98757

var origin: js.UndefOr[String] = js.undefined
var lastEventId: js.UndefOr[String] = js.undefined
var source: js.UndefOr[ServiceWorker | MessagePort] = js.undefined
var ports: js.UndefOr[js.Array[MessagePort]] = js.undefined
}

/**
Expand All @@ -474,9 +486,10 @@ trait ServiceWorkerMessageEventInit extends js.Object {
*/
@js.native
@JSGlobal
class ServiceWorkerMessageEvent(`type`: String,
eventInitDict: ServiceWorkerMessageEventInit = js.native)
extends Event {
@deprecated("Instead use MessageEvent", "0.9.8")
class ServiceWorkerMessageEvent(typeArg: String,
init: js.UndefOr[ServiceWorkerMessageEventInit] = js.undefined)
extends Event(typeArg, init) {

/**
* Returns the event's data. It can be any data type.
Expand Down Expand Up @@ -780,7 +793,7 @@ trait ServiceWorkerGlobalScope extends WorkerGlobalScope {
*
* MDN
*/
var onmessage: js.Function1[ServiceWorkerMessageEvent, _] = js.native
var onmessage: js.Function1[MessageEvent, _] = js.native

/**
* Forces the waiting service worker to become the active service worker.
Expand Down
Loading