summaryrefslogtreecommitdiff
path: root/cli/js/web/custom_event.ts
blob: 418b7ea34f701d97d6e84ba0f383516c275c8f24 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as domTypes from "./dom_types.ts";
import * as event from "./event.ts";
import { requiredArguments } from "./util.ts";

export class CustomEvent extends event.Event implements domTypes.CustomEvent {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  #detail: any;

  constructor(
    type: string,
    customEventInitDict: domTypes.CustomEventInit = {}
  ) {
    super(type, customEventInitDict);
    requiredArguments("CustomEvent", arguments.length, 1);
    const { detail = null } = customEventInitDict;
    this.#detail = detail;
  }

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

  initCustomEvent(
    _type: string,
    _bubbles?: boolean,
    _cancelable?: boolean,
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    detail?: any
  ): void {
    if (this.dispatched) {
      return;
    }

    this.#detail = detail;
  }

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

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