From 8508b91da297fef7819d6404854f4592466dec62 Mon Sep 17 00:00:00 2001 From: vector Date: Mon, 13 Dec 2021 22:32:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20get=20children=20or=20par?= =?UTF-8?q?ent=20delay=20(#1641)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/x6/src/model/cell.ts | 36 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/packages/x6/src/model/cell.ts b/packages/x6/src/model/cell.ts index 64954812d79..cbf98c0ba4f 100644 --- a/packages/x6/src/model/cell.ts +++ b/packages/x6/src/model/cell.ts @@ -750,30 +750,26 @@ export class Cell< return this.store.get('parent') } - getParent() { - let parent = this._parent - if (parent == null && this.store) { - const parentId = this.getParentId() - if (parentId != null && this.model) { - parent = this.model.getCell(parentId) - this._parent = parent - } + getParent(): T | null { + const parentId = this.getParentId() + if (parentId && this.model) { + const parent = this.model.getCell(parentId) + this._parent = parent + return parent } - return parent + return null } getChildren() { - let children = this._children - if (children == null) { - const childrenIds = this.store.get('children') - if (childrenIds && childrenIds.length && this.model) { - children = childrenIds - .map((id) => this.model?.getCell(id)) - .filter((cell) => cell != null) as Cell[] - this._children = children - } - } - return children ? [...children] : null + const childrenIds = this.store.get('children') + if (childrenIds && childrenIds.length && this.model) { + const children = childrenIds + .map((id) => this.model?.getCell(id)) + .filter((cell) => cell != null) as Cell[] + this._children = children + return [...children] + } + return null } hasParent() {