fix(tracker): some guards for node id check

This commit is contained in:
nick-delirium 2023-08-24 14:36:57 +02:00
parent 9784ab8c8e
commit 24b2b46b2c

View file

@ -13,6 +13,7 @@ export default class Nodes {
attachNodeCallback(nodeCallback: NodeCallback): void {
this.nodeCallbacks.push(nodeCallback)
}
attachNodeListener(node: Node, type: string, listener: EventListener, useCapture = true): void {
const id = this.getID(node)
if (id === undefined) {
@ -38,6 +39,7 @@ export default class Nodes {
}
return [id, isNew]
}
unregisterNode(node: Node): number | undefined {
const id = (node as any)[this.node_id]
if (id !== undefined) {
@ -67,12 +69,16 @@ export default class Nodes {
}
}
}
callNodeCallbacks(node: Node, isStart: boolean): void {
this.nodeCallbacks.forEach((cb) => cb(node, isStart))
}
getID(node: Node): number | undefined {
if (!node) return undefined
return (node as any)[this.node_id]
}
getNode(id: number) {
return this.nodes[id]
}