2020-01-02 18:41:59 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-09-02 17:07:11 -04:00
|
|
|
import * as domTypes from "./dom_types.ts";
|
|
|
|
import * as event from "./event.ts";
|
2020-03-28 13:03:49 -04:00
|
|
|
import { requiredArguments } from "./util.ts";
|
2019-01-23 07:20:53 -05:00
|
|
|
|
|
|
|
export class CustomEvent extends event.Event implements domTypes.CustomEvent {
|
2020-03-28 13:03:49 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
#detail: any;
|
|
|
|
|
2019-01-23 07:20:53 -05:00
|
|
|
constructor(
|
|
|
|
type: string,
|
|
|
|
customEventInitDict: domTypes.CustomEventInit = {}
|
|
|
|
) {
|
|
|
|
super(type, customEventInitDict);
|
2020-03-28 13:03:49 -04:00
|
|
|
requiredArguments("CustomEvent", arguments.length, 1);
|
2019-01-23 07:20:53 -05:00
|
|
|
const { detail = null } = customEventInitDict;
|
2020-03-28 13:03:49 -04:00
|
|
|
this.#detail = detail;
|
2019-01-23 07:20:53 -05:00
|
|
|
}
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2019-01-23 07:20:53 -05:00
|
|
|
get detail(): any {
|
2020-03-28 13:03:49 -04:00
|
|
|
return this.#detail;
|
2019-01-23 07:20:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
initCustomEvent(
|
2020-03-28 13:03:49 -04:00
|
|
|
_type: string,
|
|
|
|
_bubbles?: boolean,
|
|
|
|
_cancelable?: boolean,
|
2019-03-09 12:30:38 -05:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2019-01-23 07:20:53 -05:00
|
|
|
detail?: any
|
2019-03-09 12:30:38 -05:00
|
|
|
): void {
|
2019-01-23 07:20:53 -05:00
|
|
|
if (this.dispatched) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-28 13:03:49 -04:00
|
|
|
this.#detail = detail;
|
2019-01-23 07:20:53 -05:00
|
|
|
}
|
2019-04-03 08:41:05 -04:00
|
|
|
|
|
|
|
get [Symbol.toStringTag](): string {
|
|
|
|
return "CustomEvent";
|
|
|
|
}
|
2019-01-23 07:20:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Reflect.defineProperty(CustomEvent.prototype, "detail", { enumerable: true });
|