summaryrefslogtreecommitdiff
path: root/cli/js/web/custom_event.ts
blob: ea76d2c94ea2e10655304a8a7dd6bb4a2af30a28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { EventImpl as Event } from "./event.ts";
import { requiredArguments } from "./util.ts";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export class CustomEventImpl<T = any> extends Event implements CustomEvent {
  #detail: T;

  constructor(type: string, eventInitDict: CustomEventInit<T> = {}) {
    super(type, eventInitDict);
    requiredArguments("CustomEvent", arguments.length, 1);
    const { detail } = eventInitDict;
    this.#detail = detail as T;
  }

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  get detail(): T {
    return this.#detail;
  }

  get [Symbol.toStringTag](): string {
    return "CustomEvent";
  }
}

Reflect.defineProperty(CustomEventImpl.prototype, "detail", {
  enumerable: true,
});