1 | const getTime = () => {
|
2 | const time = process.hrtime();
|
3 | return time[0] * 1000000 + time[1] / 1000;
|
4 | };
|
5 |
|
6 |
|
7 | class Event {
|
8 |
|
9 | constructor(type, eventInitDict = {
|
10 | bubbles: false,
|
11 | cancelable: false,
|
12 | composed: false
|
13 | }) {
|
14 | if (type) this.initEvent(
|
15 | type,
|
16 | eventInitDict.bubbles,
|
17 | eventInitDict.cancelable
|
18 | );
|
19 | this.composed = eventInitDict.composed;
|
20 | this.isTrusted = false;
|
21 | this.defaultPrevented = false;
|
22 | this.cancelBubble = false;
|
23 | this.cancelImmediateBubble = false;
|
24 | this.eventPhase = Event.NONE;
|
25 | this.timeStamp = getTime();
|
26 | }
|
27 |
|
28 | initEvent(type, bubbles, cancelable) {
|
29 | this.type = type;
|
30 | this.bubbles = bubbles;
|
31 | this.cancelable = cancelable;
|
32 | }
|
33 |
|
34 | stopPropagation() {
|
35 | this.cancelBubble = true;
|
36 | }
|
37 |
|
38 | stopImmediatePropagation() {
|
39 | this.cancelBubble = true;
|
40 | this.cancelImmediateBubble = true;
|
41 | }
|
42 |
|
43 | preventDefault() {
|
44 | this.defaultPrevented = true;
|
45 | }
|
46 |
|
47 | }
|
48 |
|
49 | Event.NONE = 0;
|
50 | Event.CAPTURING_PHASE = 1;
|
51 | Event.AT_TARGET = 2;
|
52 | Event.BUBBLING_PHASE = 3;
|
53 |
|
54 | module.exports = Event;
|