-
Notifications
You must be signed in to change notification settings - Fork 418
/
log_controller.ts
100 lines (85 loc) · 2.25 KB
/
log_controller.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { ActionEvent } from "../../core/action_event"
import { Controller } from "../../core/controller"
export type ActionLogEntry = {
name: string
controller: Controller
identifier: string
eventType: string
currentTarget: EventTarget | null
params: { [key: string]: any }
defaultPrevented: boolean
passive: boolean
}
export type MutationLogEntry = {
attributeName: string,
controller: Controller
identifier: string
newValue: string | null,
oldValue: string | null,
}
export class LogController extends Controller {
static actionLog: ActionLogEntry[] = []
initializeCount = 0
connectCount = 0
disconnectCount = 0
attributeChangedCount = 0
mutationLog: MutationLogEntry[] = []
initialize() {
this.initializeCount++
}
connect() {
this.connectCount++
}
disconnect() {
this.disconnectCount++
}
attributeChanged(attributeName: string, oldValue: string | null, newValue: string | null) {
this.recordMutation(attributeName, oldValue, newValue)
}
log(event: ActionEvent) {
this.recordAction("log", event)
}
log2(event: ActionEvent) {
this.recordAction("log2", event)
}
log3(event: ActionEvent) {
this.recordAction("log3", event)
}
logPassive(event: ActionEvent) {
event.preventDefault()
if (event.defaultPrevented) {
this.recordAction("logPassive", event, false)
} else {
this.recordAction("logPassive", event, true)
}
}
stop(event: ActionEvent) {
this.recordAction("stop", event)
event.stopImmediatePropagation()
}
get actionLog() {
return (this.constructor as typeof LogController).actionLog
}
private recordAction(name: string, event: ActionEvent, passive?: boolean) {
this.actionLog.push({
name,
controller: this,
identifier: this.identifier,
eventType: event.type,
currentTarget: event.currentTarget,
params: event.params,
defaultPrevented: event.defaultPrevented,
passive: passive || false
})
}
private recordMutation(attributeName: string, oldValue: string | null, newValue: string | null) {
this.attributeChangedCount++
this.mutationLog.push({
attributeName,
oldValue,
newValue,
controller: this,
identifier: this.identifier,
})
}
}