safe unsubscribe (#75)

This commit is contained in:
Cilibiu Bogdan
2017-11-22 20:38:51 +02:00
committed by Denys Vuika
parent 702614d8b0
commit 69f43d75f7
7 changed files with 47 additions and 71 deletions

View File

@@ -32,10 +32,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes
@ViewChild(DocumentListComponent)
documentList: DocumentListComponent;
private onDeleteNode: Subscription;
private onMoveNode: Subscription;
private onRestoreNode: Subscription;
private onToggleFavorite: Subscription;
private subscriptions: Subscription[] = [];
constructor(
private router: Router,
@@ -44,17 +41,16 @@ export class RecentFilesComponent extends PageComponent implements OnInit, OnDes
}
ngOnInit() {
this.onDeleteNode = this.content.deleteNode.subscribe(() => this.refresh());
this.onMoveNode = this.content.moveNode.subscribe(() => this.refresh());
this.onRestoreNode = this.content.restoreNode.subscribe(() => this.refresh());
this.onToggleFavorite = this.content.toggleFavorite.subscribe(() => this.refresh());
this.subscriptions = this.subscriptions.concat([
this.content.deleteNode.subscribe(() => this.refresh()),
this.content.moveNode.subscribe(() => this.refresh()),
this.content.restoreNode.subscribe(() => this.refresh()),
this.content.toggleFavorite.subscribe(() => this.refresh())
]);
}
ngOnDestroy() {
this.onDeleteNode.unsubscribe();
this.onMoveNode.unsubscribe();
this.onRestoreNode.unsubscribe();
this.onToggleFavorite.unsubscribe();
this.subscriptions.forEach(s => s.unsubscribe());
}
onNodeDoubleClick(node: MinimalNodeEntryEntity) {