One subscription instead of many subscriptions

This commit is contained in:
piotrpekala7 2020-02-14 15:40:06 +01:00
parent e11281ddf6
commit a1476384e6

View File

@ -109,7 +109,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
@ViewChild(D3MapComponent, {static: false}) mapChild: D3MapComponent; @ViewChild(D3MapComponent, {static: false}) mapChild: D3MapComponent;
@ViewChild(ProjectMapMenuComponent, {static: false}) projectMapMenuComponent: ProjectMapMenuComponent; @ViewChild(ProjectMapMenuComponent, {static: false}) projectMapMenuComponent: ProjectMapMenuComponent;
private subscriptions: Subscription[] = []; private projectMapSubscription: Subscription = new Subscription();
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
@ -210,22 +210,22 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
); );
}); });
this.subscriptions.push(routeSub); this.projectMapSubscription.add(routeSub);
this.subscriptions.push( this.projectMapSubscription.add(
this.mapSettingsService.mapRenderedEmitter.subscribe((value: boolean) => { this.mapSettingsService.mapRenderedEmitter.subscribe((value: boolean) => {
if (this.scrollEnabled) this.centerCanvas(); if (this.scrollEnabled) this.centerCanvas();
}) })
); );
this.subscriptions.push( this.projectMapSubscription.add(
this.drawingsDataSource.changes.subscribe((drawings: Drawing[]) => { this.drawingsDataSource.changes.subscribe((drawings: Drawing[]) => {
this.drawings = drawings; this.drawings = drawings;
this.mapChangeDetectorRef.detectChanges(); this.mapChangeDetectorRef.detectChanges();
}) })
); );
this.subscriptions.push( this.projectMapSubscription.add(
this.nodesDataSource.changes.subscribe((nodes: Node[]) => { this.nodesDataSource.changes.subscribe((nodes: Node[]) => {
if (!this.server) return; if (!this.server) return;
nodes.forEach((node: Node) => { nodes.forEach((node: Node) => {
@ -237,21 +237,21 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
}) })
); );
this.subscriptions.push( this.projectMapSubscription.add(
this.linksDataSource.changes.subscribe((links: Link[]) => { this.linksDataSource.changes.subscribe((links: Link[]) => {
this.links = links; this.links = links;
this.mapChangeDetectorRef.detectChanges(); this.mapChangeDetectorRef.detectChanges();
}) })
); );
this.subscriptions.push(this.projectWebServiceHandler.errorNotificationEmitter.subscribe((message) => { this.projectMapSubscription.add(this.projectWebServiceHandler.errorNotificationEmitter.subscribe((message) => {
this.showMessage({ this.showMessage({
type: 'error', type: 'error',
message: message message: message
}); });
})); }));
this.subscriptions.push(this.projectWebServiceHandler.warningNotificationEmitter.subscribe((message) => { this.projectMapSubscription.add(this.projectWebServiceHandler.warningNotificationEmitter.subscribe((message) => {
this.showMessage({ this.showMessage({
type: 'warning', type: 'warning',
message: message message: message
@ -323,7 +323,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
this.progressService.deactivate(); this.progressService.deactivate();
}); });
this.subscriptions.push(subscription); this.projectMapSubscription.add(subscription);
} }
setUpProjectWS(project: Project) { setUpProjectWS(project: Project) {
@ -408,14 +408,14 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
this.contextMenu.openMenuForListOfElements(drawings, nodes, labels, links, event.pageY, event.pageX); this.contextMenu.openMenuForListOfElements(drawings, nodes, labels, links, event.pageY, event.pageX);
}); });
this.subscriptions.push(onLinkContextMenu); this.projectMapSubscription.add(onLinkContextMenu);
this.subscriptions.push(onEthernetLinkContextMenu); this.projectMapSubscription.add(onEthernetLinkContextMenu);
this.subscriptions.push(onSerialLinkContextMenu); this.projectMapSubscription.add(onSerialLinkContextMenu);
this.subscriptions.push(onNodeContextMenu); this.projectMapSubscription.add(onNodeContextMenu);
this.subscriptions.push(onDrawingContextMenu); this.projectMapSubscription.add(onDrawingContextMenu);
this.subscriptions.push(onContextMenu); this.projectMapSubscription.add(onContextMenu);
this.subscriptions.push(onLabelContextMenu); this.projectMapSubscription.add(onLabelContextMenu);
this.subscriptions.push(onInterfaceLabelContextMenu); this.projectMapSubscription.add(onInterfaceLabelContextMenu);
this.mapChangeDetectorRef.detectChanges(); this.mapChangeDetectorRef.detectChanges();
} }
@ -829,7 +829,7 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
if (this.ws) { if (this.ws) {
if (this.ws.OPEN) this.ws.close(); if (this.ws.OPEN) this.ws.close();
} }
this.subscriptions.forEach((subscription: Subscription) => subscription.unsubscribe()); this.projectMapSubscription.unsubscribe();
} }
} }