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

@@ -25,7 +25,7 @@ import { Subscription } from 'rxjs/Rx';
styleUrls: [ './current-user.component.scss' ]
})
export class CurrentUserComponent implements OnInit, OnDestroy {
private personSubscription: Subscription;
private subscriptions: Subscription[] = [];
user: any = null;
@@ -35,14 +35,13 @@ export class CurrentUserComponent implements OnInit, OnDestroy {
) {}
ngOnInit() {
this.personSubscription = this.peopleApi.getCurrentPerson()
.subscribe((person: any) => {
this.user = person.entry;
});
this.subscriptions = this.subscriptions.concat([
this.peopleApi.getCurrentPerson().subscribe((person: any) => this.user = person.entry)
]);
}
ngOnDestroy() {
this.personSubscription.unsubscribe();
this.subscriptions.forEach(s => s.unsubscribe());
}
get userFirstName(): string {

View File

@@ -34,7 +34,7 @@ export class FavoritesComponent extends PageComponent implements OnInit, OnDestr
@ViewChild(DocumentListComponent)
documentList: DocumentListComponent;
private subscriptions: any = [];
private subscriptions: Subscription[] = [];
constructor(
private router: Router,

View File

@@ -35,15 +35,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
isValidPath = true;
private nodePath: PathElement[];
private onCopyNode: Subscription;
private onRemoveItem: Subscription;
private onCreateFolder: Subscription;
private onEditFolder: Subscription;
private onDeleteNode: Subscription;
private onMoveNode: Subscription;
private onRestoreNode: Subscription;
private onFileUploadComplete: Subscription;
private onToggleFavorite: Subscription;
private subscriptions: Subscription[] = [];
constructor(
private router: Router,
@@ -85,30 +77,21 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
);
});
this.onCopyNode = nodeActionsService.contentCopied
.subscribe((nodes) => this.onContentCopied(nodes));
this.onCreateFolder = contentService.folderCreate.subscribe(() => this.load());
this.onEditFolder = contentService.folderEdit.subscribe(() => this.load());
this.onDeleteNode = contentManagementService.deleteNode.subscribe(() => this.load());
this.onMoveNode = contentManagementService.moveNode.subscribe(() => this.load());
this.onRestoreNode = contentManagementService.restoreNode.subscribe(() => this.load());
this.onToggleFavorite = contentManagementService.toggleFavorite.subscribe(() => this.load());
this.onFileUploadComplete = uploadService.fileUploadComplete
.subscribe(file => this.onFileUploadedEvent(file));
this.onRemoveItem = uploadService.fileUploadDeleted
.subscribe((file) => this.onFileUploadedEvent(file));
this.subscriptions = this.subscriptions.concat([
nodeActionsService.contentCopied.subscribe((nodes) => this.onContentCopied(nodes)),
contentService.folderCreate.subscribe(() => this.load()),
contentService.folderEdit.subscribe(() => this.load()),
contentManagementService.deleteNode.subscribe(() => this.load()),
contentManagementService.moveNode.subscribe(() => this.load()),
contentManagementService.restoreNode.subscribe(() => this.load()),
contentManagementService.toggleFavorite.subscribe(() => this.load()),
uploadService.fileUploadComplete.subscribe(file => this.onFileUploadedEvent(file)),
uploadService.fileUploadDeleted.subscribe((file) => this.onFileUploadedEvent(file))
]);
}
ngOnDestroy() {
this.onCopyNode.unsubscribe();
this.onRemoveItem.unsubscribe();
this.onCreateFolder.unsubscribe();
this.onEditFolder.unsubscribe();
this.onDeleteNode.unsubscribe();
this.onMoveNode.unsubscribe();
this.onRestoreNode.unsubscribe();
this.onFileUploadComplete.unsubscribe();
this.onToggleFavorite.unsubscribe();
this.subscriptions.forEach(s => s.unsubscribe());
this.browsingFilesService.onChangeParent.next(null);
}

View File

@@ -29,19 +29,20 @@ import { BrowsingFilesService } from '../../common/services/browsing-files.servi
export class LayoutComponent implements OnInit, OnDestroy {
node: MinimalNodeEntryEntity;
browsingFilesSubscription: Subscription;
private subscriptions: Subscription[] = [];
constructor(
private contentService: ContentService,
private browsingFilesService: BrowsingFilesService) {}
ngOnInit() {
this.browsingFilesSubscription = this.browsingFilesService.onChangeParent
.subscribe((node: MinimalNodeEntryEntity) => this.node = node);
this.subscriptions.concat([
this.browsingFilesService.onChangeParent.subscribe((node: MinimalNodeEntryEntity) => this.node = node)
]);
}
ngOnDestroy() {
this.browsingFilesSubscription.unsubscribe();
this.subscriptions.forEach(s => s.unsubscribe());
}
canCreateContent(node: MinimalNodeEntryEntity): boolean {

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) {

View File

@@ -33,10 +33,7 @@ export class SharedFilesComponent 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,
@@ -46,17 +43,16 @@ export class SharedFilesComponent 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(link: { nodeId?: string }) {

View File

@@ -31,9 +31,10 @@ import { BrowsingFilesService } from '../../common/services/browsing-files.servi
})
export class SidenavComponent implements OnInit, OnDestroy {
node: MinimalNodeEntryEntity = null;
onChangeParentSubscription: Subscription;
navigation = [];
private subscriptions: Subscription[] = [];
constructor(
private browsingFilesService: BrowsingFilesService,
private contentService: ContentService,
@@ -46,14 +47,14 @@ export class SidenavComponent implements OnInit, OnDestroy {
}
ngOnInit() {
this.onChangeParentSubscription = this.browsingFilesService.onChangeParent
.subscribe((node: MinimalNodeEntryEntity) => {
this.node = node;
});
this.subscriptions.concat([
this.browsingFilesService.onChangeParent
.subscribe((node: MinimalNodeEntryEntity) => this.node = node)
]);
}
ngOnDestroy() {
this.onChangeParentSubscription.unsubscribe();
this.subscriptions.forEach(s => s.unsubscribe());
}
canCreateContent(parentNode: MinimalNodeEntryEntity): boolean {