/
node.ts
88 lines (76 loc) · 1.75 KB
/
node.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
/* eslint-disable @typescript-eslint/no-explicit-any */
import { JDEventSource } from "./eventsource"
/**
* Base class for JDOM Node classes.
* @category JDOM
*/
export abstract class JDNode extends JDEventSource {
private _nodeData: Record<string, unknown>
constructor() {
super()
}
/**
* Globally unique identifier in the tree
* @category JDOM
*/
abstract get id(): string
/**
* Gets a kind identifier useful for UI descriptions
* @category JDOM
*/
abstract get nodeKind(): string
/**
* Gets the local name
* @category JDOM
*/
abstract get name(): string
/**
* A human friendly name
* @category JDOM
*/
get friendlyName(): string {
return this.name
}
/**
* Gets the name including parents
* @category JDOM
*/
abstract get qualifiedName(): string
/**
* Gets the parent node in the Jacdac dom
* @category JDOM
*/
abstract get parent(): JDNode
/**
* Gets the children of the current node
* @category JDOM
*/
abstract get children(): JDNode[]
/**
* Gets a databag to store custom information
* @category JDOM
*/
get nodeData() {
if (!this._nodeData) this._nodeData = {}
return this._nodeData
}
/**
* Emit event in current node and parent nodes
* @param event event to emit
* @param arg event arguments
* @category JDOM
*/
emitPropagated(event: string, arg?: any) {
let current = this as JDNode
while (current) {
current.emit(event, arg || this)
current = current.parent
}
}
/**
* @hidden
*/
toString() {
return this.friendlyName
}
}