This commit is contained in:
Mo Bitar
2020-04-17 16:41:51 -05:00
parent 8050c9cccd
commit 851269200b
15 changed files with 521 additions and 487 deletions

View File

@@ -59,7 +59,6 @@ export class AppState {
this.registerVisibilityObservers();
this.addAppEventObserver();
this.streamNotesAndTags();
const onVisibilityChange = () => {
const visible = document.visibilityState === "visible";
const event = visible

View File

@@ -97,7 +97,11 @@ export class WebApplication extends SNApplication {
(this.scope! as any).application = undefined;
this.scope!.$destroy();
this.scope = undefined;
super.deinit();
/** Allow our Angular directives to be destroyed and any pending digest cycles
* to complete before destroying the global application instance and all its services */
setImmediate(() => {
super.deinit();
})
}
setWebServices(services: WebServices) {

View File

@@ -20,14 +20,11 @@ export class ComponentGroup {
}
get componentManager() {
return this.application.componentManager!;
return this.application?.componentManager!;
}
public deinit() {
(this.application as any) = undefined;
for (const component of this.allActiveComponents()) {
this.componentManager.deregisterComponent(component.uuid);
}
}
async activateComponent(component: SNComponent) {
@@ -50,9 +47,15 @@ export class ComponentGroup {
return;
}
removeFromArray(this.activeComponents, component.uuid);
await this.componentManager.deactivateComponent(component.uuid);
if(notify) {
this.notifyObservers();
/** If this function is called as part of global application deinit (locking),
* componentManager can be destroyed. In this case, it's harmless to not take any
* action since the componentManager will be destroyed, and the component will
* essentially be deregistered. */
if(this.componentManager) {
await this.componentManager.deactivateComponent(component.uuid);
if(notify) {
this.notifyObservers();
}
}
}

View File

@@ -59,6 +59,9 @@ export class EditorGroup {
if (this.activeEditor) {
callback();
}
return () => {
removeFromArray(this.changeObservers, callback);
}
}
private notifyObservers() {