Skip to content

Commit

Permalink
fix: 🐛 get children or parent delay (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
NewByVector authored Dec 13, 2021
1 parent 6b01ceb commit 8508b91
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions packages/x6/src/model/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 extends Cell = Cell>(): T | null {
const parentId = this.getParentId()
if (parentId && this.model) {
const parent = this.model.getCell<T>(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() {
Expand Down

0 comments on commit 8508b91

Please sign in to comment.