onDestroy needed for broadcast subscriptions

This commit is contained in:
Chad Scharf 2020-11-04 14:00:44 -05:00
parent c9c6a11390
commit 97e982bf01
7 changed files with 40 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import {
Component,
OnDestroy,
NgZone,
} from '@angular/core';
import {
@ -28,7 +29,7 @@ const BroadcasterSubscriptionId = 'LockComponent';
selector: 'app-lock',
templateUrl: 'lock.component.html',
})
export class LockComponent extends BaseLockComponent {
export class LockComponent extends BaseLockComponent implements OnDestroy {
constructor(router: Router, i18nService: I18nService,
platformUtilsService: PlatformUtilsService, messagingService: MessagingService,
userService: UserService, cryptoService: CryptoService,
@ -59,6 +60,10 @@ export class LockComponent extends BaseLockComponent {
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
onWindowHidden() {
this.showPassword = false;
}

View File

@ -1,6 +1,7 @@
import {
Component,
ComponentFactoryResolver,
OnDestroy,
NgZone,
ViewChild,
ViewContainerRef,
@ -31,7 +32,7 @@ const BroadcasterSubscriptionId = 'LoginComponent';
selector: 'app-login',
templateUrl: 'login.component.html',
})
export class LoginComponent extends BaseLoginComponent {
export class LoginComponent extends BaseLoginComponent implements OnDestroy {
@ViewChild('environment', { read: ViewContainerRef, static: true }) environmentModal: ViewContainerRef;
showingModal = false;
@ -63,6 +64,10 @@ export class LoginComponent extends BaseLoginComponent {
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
settings() {
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
const modal = this.environmentModal.createComponent(factory).instance;

View File

@ -1,5 +1,6 @@
import {
Component,
OnDestroy,
OnInit,
NgZone,
} from '@angular/core';
@ -23,7 +24,7 @@ const BroadcasterSubscriptionId = 'RegisterComponent';
selector: 'app-register',
templateUrl: 'register.component.html',
})
export class RegisterComponent extends BaseRegisterComponent implements OnInit {
export class RegisterComponent extends BaseRegisterComponent implements OnInit, OnDestroy {
constructor(authService: AuthService, router: Router,
i18nService: I18nService, cryptoService: CryptoService,
apiService: ApiService, stateService: StateService,
@ -46,6 +47,10 @@ export class RegisterComponent extends BaseRegisterComponent implements OnInit {
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
onWindowHidden() {
this.showPassword = false;
}

View File

@ -1,5 +1,6 @@
import {
Component,
OnDestroy,
NgZone,
} from '@angular/core';
@ -30,7 +31,7 @@ import {
selector: 'app-set-password',
templateUrl: 'set-password.component.html',
})
export class SetPasswordComponent extends BaseSetPasswordComponent {
export class SetPasswordComponent extends BaseSetPasswordComponent implements OnDestroy {
constructor(apiService: ApiService, i18nService: I18nService,
cryptoService: CryptoService, messagingService: MessagingService,
userService: UserService, passwordGenerationService: PasswordGenerationService,
@ -85,6 +86,10 @@ export class SetPasswordComponent extends BaseSetPasswordComponent {
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
onWindowHidden() {
this.showPassword = false;
}

View File

@ -1,6 +1,7 @@
import {
Component,
OnChanges,
OnDestroy,
NgZone,
} from '@angular/core';
@ -25,7 +26,7 @@ const BroadcasterSubscriptionId = 'AddEditComponent';
selector: 'app-vault-add-edit',
templateUrl: 'add-edit.component.html',
})
export class AddEditComponent extends BaseAddEditComponent implements OnChanges {
export class AddEditComponent extends BaseAddEditComponent implements OnChanges, OnDestroy {
constructor(cipherService: CipherService, folderService: FolderService,
i18nService: I18nService, platformUtilsService: PlatformUtilsService,
auditService: AuditService, stateService: StateService,
@ -55,6 +56,10 @@ export class AddEditComponent extends BaseAddEditComponent implements OnChanges
await this.load();
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
async load() {
if (document.querySelectorAll('app-vault-add-edit .ng-dirty').length === 0 ||
(this.cipher != null && this.cipherId !== this.cipher.id)) {

View File

@ -1,5 +1,6 @@
import {
Component,
OnDestroy,
OnInit,
NgZone,
} from '@angular/core';
@ -41,6 +42,10 @@ export class ExportComponent extends BaseExportComponent implements OnInit {
});
}
ngOnDestroy() {
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
onWindowHidden() {
this.showPassword = false;
}

View File

@ -58,6 +58,11 @@ export class ViewComponent extends BaseViewComponent implements OnChanges {
});
}
ngOnDestroy() {
super.ngOnDestroy();
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
async ngOnChanges() {
await super.load();
}