From 3953668ef92bd5890ef9c3016e50f51193c2b8e0 Mon Sep 17 00:00:00 2001 From: Matthias Konitzny <konitzny@ibr.cs.tu-bs.de> Date: Fri, 9 Sep 2022 19:01:29 +0200 Subject: [PATCH] Fixed some bugs caused by unbound this --- src/common/graph/graphelement.ts | 6 ++++++ src/common/graph/link.ts | 7 +++++++ src/editor/graph.ts | 6 +++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/common/graph/graphelement.ts b/src/common/graph/graphelement.ts index 85e1d25..6e0fe1e 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 100894e..a69469f 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 9ea0fd5..d55cbd3 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( -- GitLab