(schema: NodeSchema, checkId = true)
| 181 | |
| 182 | @action |
| 183 | createNode(schema: NodeSchema, checkId = true) { |
| 184 | if (schema?.id && this.hasNode(schema.id)) { |
| 185 | schema.id = undefined |
| 186 | } |
| 187 | |
| 188 | let node: Node | null = null |
| 189 | let isNewNode = false |
| 190 | |
| 191 | if (schema?.id) { |
| 192 | node = this.getNode(schema.id) |
| 193 | if (node && node.componentName === schema.componentName) { |
| 194 | if (node.parent) { |
| 195 | node.internalSetParent(null, false) |
| 196 | } |
| 197 | node.import(schema, checkId) |
| 198 | } else if (node) { |
| 199 | node = null |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (!node) { |
| 204 | node = new Node(this, schema) |
| 205 | isNewNode = true |
| 206 | } |
| 207 | |
| 208 | this.nodes.add(node) |
| 209 | this._nodesMap.set(node.id, node) |
| 210 | this.emitter.emit(NODE_EVENT.ADD, node) |
| 211 | |
| 212 | // 追踪物料使用:仅对新创建的节点增加使用计数 |
| 213 | if (isNewNode && node.componentName) { |
| 214 | this.designer.materials.incrementUsage(node.materialUsageKey) |
| 215 | } |
| 216 | |
| 217 | return node |
| 218 | } |
| 219 | |
| 220 | getNode(id: string) { |
| 221 | return this._nodesMap.get(id) || null |
no test coverage detected