diff --git a/src/common/graph/graphelement.ts b/src/common/graph/graphelement.ts index 85e1d2584bfc26cfbbc9e4b54acbf017d934f9e7..6e0fe1ef4e4d4580915e2deeec12caca3b34ef31 100644 --- a/src/common/graph/graphelement.ts +++ b/src/common/graph/graphelement.ts @@ -9,6 +9,8 @@ export class GraphElement<JSONType, HistoryType> extends SerializableItem< constructor(id = -1, graph: Graph = undefined) { super(id); + this.equals = this.equals.bind(this); + this.graph = graph; } @@ -33,6 +35,10 @@ export class GraphElement<JSONType, HistoryType> extends SerializableItem< * @returns True, if given object is identical. */ public equals(other: GraphElement<JSONType, HistoryType>): boolean { + if (other == undefined) { + return false; + } + return other.constructor == this.constructor && other.id == this.id; } } diff --git a/src/common/graph/link.ts b/src/common/graph/link.ts index 100894e30f09f2a4e50090109591992c92b89afa..a69469f09963e573df66a864c461edab5c7e743f 100644 --- a/src/common/graph/link.ts +++ b/src/common/graph/link.ts @@ -37,6 +37,9 @@ export class Link constructor(source?: Node, target?: Node, graph?: Graph) { super(0, graph); + + this.equals = this.equals.bind(this); + this.source = source; this.target = target; } @@ -94,6 +97,10 @@ export class Link } public equals(other: GraphElement<LinkData, SimLinkData>): boolean { + if (other == undefined) { + return false; + } + if (other.constructor != this.constructor) { return false; } diff --git a/src/editor/graph.ts b/src/editor/graph.ts index 9ea0fd5910c06905edfa1f85234b8a661e7c7606..d55cbd38f58abf67677221365700edde456c77e2 100644 --- a/src/editor/graph.ts +++ b/src/editor/graph.ts @@ -15,6 +15,10 @@ export class DynamicGraph extends Common.Graph { super(data); this.onChangeCallbacks = []; + super.deleteNode = super.deleteNode.bind(this); + super.deleteLink = super.deleteLink.bind(this); + super.deleteNodeType = super.deleteNodeType.bind(this); + if (data != undefined) { this.history = new History<SimGraphData>( this, @@ -116,7 +120,7 @@ export class DynamicGraph extends Common.Graph { } public deleteLink(id: number): boolean { - return this.delete(id, super.deleteNode); + return this.delete(id, super.deleteLink); } getLink(