2020-01-02 23:41:59 +00:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-04-12 01:42:02 +10:00
|
|
|
import { EventImpl as Event } from "./event.ts";
|
2020-03-29 04:03:49 +11:00
|
|
|
import { requiredArguments } from "./util.ts";
|
2019-01-23 12:20:53 +00:00
|
|
|
|
2020-04-12 01:42:02 +10:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
export class CustomEventImpl<T = any> extends Event implements CustomEvent {
|
|
|
|
#detail: T;
|
2020-03-29 04:03:49 +11:00
|
|
|
|
2020-04-12 01:42:02 +10:00
|
|
|
constructor(type: string, eventInitDict: CustomEventInit<T> = {}) {
|
|
|
|
super(type, eventInitDict);
|
2020-03-29 04:03:49 +11:00
|
|
|
requiredArguments("CustomEvent", arguments.length, 1);
|
2020-04-12 01:42:02 +10:00
|
|
|
const { detail } = eventInitDict;
|
|
|
|
this.#detail = detail as T;
|
2019-01-23 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-10 04:30:38 +11:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2020-04-12 01:42:02 +10:00
|
|
|
get detail(): T {
|
2020-03-29 04:03:49 +11:00
|
|
|
return this.#detail;
|
2019-01-23 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 20:41:05 +08:00
|
|
|
get [Symbol.toStringTag](): string {
|
|
|
|
return "CustomEvent";
|
|
|
|
}
|
2019-01-23 12:20:53 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 01:42:02 +10:00
|
|
|
Reflect.defineProperty(CustomEventImpl.prototype, "detail", {
|
|
|
|
enumerable: true,
|
|
|
|
});
|