Skip to content

Commit

Permalink
feat: add updateNode/updateEdge API #3235 (#3239)
Browse files Browse the repository at this point in the history
* feat: add updateNode/updateEdge API #3235

* feat: add updateNode/updateEdge API #3235

* feat: update return value

* fix: call error create function
  • Loading branch information
lloydzhou authored Feb 17, 2023
1 parent 441dd56 commit 04656f3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/x6/src/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ export class Model extends Basecoat<Model.EventArgs> {
return node
}

updateNode(metadata: Node.Metadata, options: Model.SetOptions = {}) {
const node = this.createNode(metadata)
const prop = node.getProp()
node.dispose()
return this.updateCell(prop, options)
}

createNode(metadata: Node.Metadata) {
return Node.create(metadata)
}
Expand All @@ -258,6 +265,13 @@ export class Model extends Basecoat<Model.EventArgs> {
return Edge.create(metadata)
}

updateEdge(metadata: Edge.Metadata, options: Model.SetOptions = {}) {
const edge = this.createEdge(metadata)
const prop = edge.getProp()
edge.dispose()
return this.updateCell(prop, options)
}

addCell(cell: Cell | Cell[], options: Model.AddOptions = {}) {
if (Array.isArray(cell)) {
return this.addCells(cell, options)
Expand Down Expand Up @@ -295,6 +309,23 @@ export class Model extends Basecoat<Model.EventArgs> {
return this
}

updateCell(prop: Cell.Properties, options: Model.SetOptions = {}): boolean {
const existing = prop.id && this.getCell(prop.id)
if (existing) {
return this.batchUpdate(
'update',
() => {
Object.keys(prop).forEach((key) =>
existing.setProp(key, prop[key], options),
)
return true
},
prop,
)
}
return false
}

removeCell(cellId: string, options?: Collection.RemoveOptions): Cell | null
removeCell(cell: Cell, options?: Collection.RemoveOptions): Cell | null
removeCell(
Expand Down

0 comments on commit 04656f3

Please sign in to comment.