(node: Node, key?: string)
| 133 | } |
| 134 | |
| 135 | public registerNode(node: Node, key?: string): [string, () => void] { |
| 136 | const className = node.constructor?.name ?? 'unknown'; |
| 137 | const counter = (this.nodeCounters.get(className) ?? 0) + 1; |
| 138 | this.nodeCounters.set(className, counter); |
| 139 | |
| 140 | if (key && this.registeredNodes.has(key)) { |
| 141 | useLogger().error({ |
| 142 | message: `Duplicated node key: "${key}".`, |
| 143 | inspect: key, |
| 144 | stack: new Error().stack, |
| 145 | }); |
| 146 | key = undefined; |
| 147 | } |
| 148 | |
| 149 | key ??= `${this.name}/${className}[${counter}]`; |
| 150 | this.registeredNodes.set(key, node); |
| 151 | const currentNodeMap = this.registeredNodes; |
| 152 | return [key, () => currentNodeMap.delete(key!)]; |
| 153 | } |
| 154 | |
| 155 | public getNode(key: any): Node | null { |
| 156 | if (typeof key !== 'string') return null; |
no test coverage detected