Skip to content

Commit be76175

Browse files
committed
fixed cytoscape edgehandles reregistration bug.
cancling subscriptions on destroy
1 parent b1199ba commit be76175

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

client/src/app/dashboard/graph-view/graph-view.service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ export class GraphViewService {
139139
}
140140

141141
public getElementRemoveObservable(): Observable<Array<string>> {
142-
return new Observable((observer) => {
143-
this.elementRemover.subscribe(observer);
144-
});
142+
return this.elementRemover.asObservable();
145143
}
146144
}

client/src/app/dashboard/graph-view/graph-view/graph-view.component.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { MatDialog } from '@angular/material';
88
import { ConnectDialogComponent } from '../connect-dialog/connect-dialog.component';
99
import { ComponentTypeEnum, ComponentType } from 'src/app/model/models/instance';
1010
import { GraphConfig } from '../GraphConfig';
11+
import { Subscription } from 'rxjs';
1112

1213
@Component({
1314
selector: 'app-graph-view',
@@ -18,11 +19,11 @@ export class GraphViewComponent implements OnInit, OnDestroy {
1819
@ViewChild('cy') cyDiv: ElementRef;
1920
private cy: cytoscape.Core;
2021
private config: GraphConfig;
22+
private elementSubscription: Subscription;
23+
private elementRemoveSubscription: Subscription;
2124

2225
constructor(private graphViewService: GraphViewService, public dialog: MatDialog) {
23-
if (!(cytoscape as any).edgehandles) {
24-
cytoscape.use(edgehandles);
25-
}
26+
2627
}
2728

2829

@@ -35,14 +36,16 @@ export class GraphViewComponent implements OnInit, OnDestroy {
3536

3637
ngOnDestroy() {
3738
this.cy.destroy();
39+
this.elementSubscription.unsubscribe();
40+
this.elementRemoveSubscription.unsubscribe();
3841
}
3942

4043
/**
4144
* Adds listeners to the graphViewService and describe how the
4245
* view should be updated if it receives any changes / updates.
4346
*/
4447
private addChangeListener() {
45-
this.graphViewService.getElementObservable().subscribe((update: ElementUpdate) => {
48+
this.elementSubscription = this.graphViewService.getElementObservable().subscribe((update: ElementUpdate) => {
4649
if (update.elements) {
4750
if (update.type === Actions.ADD) {
4851
this.cy.add(update.elements);
@@ -65,7 +68,7 @@ export class GraphViewComponent implements OnInit, OnDestroy {
6568
}
6669
});
6770

68-
this.graphViewService.getElementRemoveObservable().subscribe((ids: Array<string>) => {
71+
this.elementRemoveSubscription = this.graphViewService.getElementRemoveObservable().subscribe((ids: Array<string>) => {
6972
if (ids) {
7073
for (let i = 0; i < ids.length; i++) {
7174
this.cy.remove(this.cy.getElementById(ids[i]));
@@ -183,6 +186,9 @@ export class GraphViewComponent implements OnInit, OnDestroy {
183186
this.config.cytoscapeConfig.container = this.cyDiv.nativeElement;
184187

185188
this.cy = cytoscape(this.config.cytoscapeConfig);
189+
if (!Object.getPrototypeOf(this.cy).edgehandles) {
190+
cytoscape.use(edgehandles);
191+
}
186192

187193
(this.cy as any).edgehandles(this.config.edgeDragConfig);
188194
}

0 commit comments

Comments
 (0)