-
Notifications
You must be signed in to change notification settings - Fork 782
/
BaseEvent.ts
50 lines (43 loc) · 1.4 KB
/
BaseEvent.ts
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
45
46
47
48
49
50
import type { Interactable } from '@interactjs/core/Interactable'
import type { Interaction, InteractionProxy } from '@interactjs/core/Interaction'
import type { ActionName } from '@interactjs/core/types'
export class BaseEvent<T extends ActionName | null = never> {
declare type: string
declare target: EventTarget
declare currentTarget: Node
declare interactable: Interactable
/** @internal */
declare _interaction: Interaction<T>
declare timeStamp: number
immediatePropagationStopped = false
propagationStopped = false
constructor(interaction: Interaction<T>) {
this._interaction = interaction
}
preventDefault() {}
/**
* Don't call any other listeners (even on the current target)
*/
stopPropagation() {
this.propagationStopped = true
}
/**
* Don't call listeners on the remaining targets
*/
stopImmediatePropagation() {
this.immediatePropagationStopped = this.propagationStopped = true
}
}
// defined outside of class definition to avoid assignment of undefined during
// construction
export interface BaseEvent<T extends ActionName> {
interaction: InteractionProxy<T>
}
// getters and setters defined here to support typescript 3.6 and below which
// don't support getter and setters in .d.ts files
Object.defineProperty(BaseEvent.prototype, 'interaction', {
get(this: BaseEvent) {
return this._interaction._proxy
},
set(this: BaseEvent) {},
})