2020-01-02 18:41:59 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-04-11 11:42:02 -04:00
|
|
|
import { EventImpl 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
|
|
|
|
2020-04-11 11:42:02 -04:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
export class CustomEventImpl<T = any> extends Event implements CustomEvent {
|
|
|
|
#detail: T;
|
2020-03-28 13:03:49 -04:00
|
|
|
|
2020-04-11 11:42:02 -04:00
|
|
|
constructor(type: string, eventInitDict: CustomEventInit<T> = {}) {
|
|
|
|
super(type, eventInitDict);
|
2020-03-28 13:03:49 -04:00
|
|
|
requiredArguments("CustomEvent", arguments.length, 1);
|
2020-04-11 11:42:02 -04:00
|
|
|
const { detail } = eventInitDict;
|
|
|
|
this.#detail = detail as T;
|
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
|
2020-04-11 11:42:02 -04:00
|
|
|
get detail(): T {
|
2020-03-28 13:03:49 -04:00
|
|
|
return this.#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
|
|
|
}
|
|
|
|
|
2020-04-11 11:42:02 -04:00
|
|
|
Reflect.defineProperty(CustomEventImpl.prototype, "detail", {
|
|
|
|
enumerable: true,
|
|
|
|
});
|