Component and other handler deregisterations
This commit is contained in:
@@ -67,6 +67,8 @@ class EditorCtrl extends PureCtrl {
|
||||
this.leftPanelPuppet = null;
|
||||
this.rightPanelPuppet = null;
|
||||
this.onEditorLoad = null;
|
||||
this.unregisterComponent();
|
||||
this.unregisterComponent = null;
|
||||
super.deinit();
|
||||
}
|
||||
|
||||
@@ -243,7 +245,7 @@ class EditorCtrl extends PureCtrl {
|
||||
this.reloadPreferences();
|
||||
|
||||
if (note.dummy) {
|
||||
this.focusEditor();
|
||||
this.focusTitle();
|
||||
}
|
||||
if (previousNote && previousNote !== note) {
|
||||
if (previousNote.dummy) {
|
||||
@@ -866,7 +868,7 @@ class EditorCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
registerComponentHandler() {
|
||||
this.application.componentManager.registerHandler({
|
||||
this.unregisterComponent = this.application.componentManager.registerHandler({
|
||||
identifier: 'editor',
|
||||
areas: [
|
||||
'note-tags',
|
||||
|
||||
@@ -31,6 +31,8 @@ class FooterCtrl extends PureCtrl {
|
||||
deinit() {
|
||||
this.rooms.length = 0;
|
||||
this.themesWithIcons.length = 0;
|
||||
this.unregisterComponent();
|
||||
this.unregisterComponent = null;
|
||||
this.rootScopeListener1();
|
||||
this.rootScopeListener2();
|
||||
this.rootScopeListener1 = null;
|
||||
@@ -65,11 +67,7 @@ class FooterCtrl extends PureCtrl {
|
||||
|
||||
onAppLaunch() {
|
||||
super.onAppLaunch();
|
||||
const hasPasscode = this.application.hasPasscode();
|
||||
this.setState({
|
||||
hasPasscode: hasPasscode
|
||||
});
|
||||
|
||||
this.reloadPasscodeStatus();
|
||||
this.reloadUpgradeStatus();
|
||||
this.user = this.application.getUser();
|
||||
this.updateOfflineStatus();
|
||||
@@ -78,6 +76,13 @@ class FooterCtrl extends PureCtrl {
|
||||
this.registerComponentHandler();
|
||||
}
|
||||
|
||||
async reloadPasscodeStatus() {
|
||||
const hasPasscode = this.application.hasPasscode();
|
||||
this.setState({
|
||||
hasPasscode: hasPasscode
|
||||
});
|
||||
}
|
||||
|
||||
addRootScopeListeners() {
|
||||
this.rootScopeListener1 = this.$rootScope.$on("reload-ext-data", () => {
|
||||
this.reloadExtendedData();
|
||||
@@ -118,6 +123,13 @@ class FooterCtrl extends PureCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async onAppKeyChange() {
|
||||
super.onAppKeyChange();
|
||||
this.reloadPasscodeStatus();
|
||||
}
|
||||
|
||||
|
||||
/** @override */
|
||||
onAppEvent(eventName) {
|
||||
if (eventName === ApplicationEvents.KeyStatusChanged) {
|
||||
@@ -183,7 +195,7 @@ class FooterCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
registerComponentHandler() {
|
||||
this.application.componentManager.registerHandler({
|
||||
this.unregisterComponent = this.application.componentManager.registerHandler({
|
||||
identifier: "roomBar",
|
||||
areas: ["rooms", "modal"],
|
||||
activationHandler: (component) => { },
|
||||
|
||||
@@ -111,16 +111,34 @@ class NotesCtrl extends PureCtrl {
|
||||
await this.reloadNotes();
|
||||
}
|
||||
} else if (eventName === ApplicationEvents.CompletedSync) {
|
||||
if (this.state.notes.length === 0) {
|
||||
await this.createPlaceholderNote();
|
||||
}
|
||||
} else if (eventName === ApplicationEvents.LocalDataLoaded) {
|
||||
if (this.application.getLastSyncDate() && this.state.notes.length === 0) {
|
||||
await this.createPlaceholderNote();
|
||||
}
|
||||
this.getMostValidNotes().then((notes) => {
|
||||
if (notes.length === 0) {
|
||||
this.createPlaceholderNote();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
* Access the current state notes without awaiting any potential reloads
|
||||
* that may be in progress. This is the sync alternative to `async getMostValidNotes`
|
||||
*/
|
||||
getPossiblyStaleNotes() {
|
||||
return this.state.notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
* Access the current state notes after waiting for any pending reloads.
|
||||
* This returns the most up to date notes, but is the asyncronous counterpart
|
||||
* to `getPossiblyStaleNotes`
|
||||
*/
|
||||
async getMostValidNotes() {
|
||||
await this.reloadNotesPromise;
|
||||
return this.getPossiblyStaleNotes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered programatically to create a new placeholder note
|
||||
* when conditions allow for it. This is as opposed to creating a new note
|
||||
@@ -251,6 +269,11 @@ class NotesCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
async reloadNotes() {
|
||||
this.reloadNotesPromise = this.performPeloadNotes();
|
||||
return this.reloadNotesPromise;
|
||||
}
|
||||
|
||||
async performPeloadNotes() {
|
||||
if (!this.state.tag) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import template from '%/root.pug';
|
||||
|
||||
class RootCtrl {
|
||||
/* @ngInject */
|
||||
constructor(applicationManager) {
|
||||
constructor($timeout, applicationManager) {
|
||||
this.$timeout = $timeout;
|
||||
this.applicationManager = applicationManager;
|
||||
this.applicationManager.addApplicationChangeObserver(() => {
|
||||
this.reload();
|
||||
@@ -10,7 +11,9 @@ class RootCtrl {
|
||||
}
|
||||
|
||||
reload() {
|
||||
this.applications = this.applicationManager.getApplications();
|
||||
this.$timeout(() => {
|
||||
this.applications = this.applicationManager.getApplications();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,12 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
};
|
||||
}
|
||||
|
||||
deinit() {
|
||||
this.unregisterComponent();
|
||||
this.unregisterComponent = null;
|
||||
super.deinit();
|
||||
}
|
||||
|
||||
getInitialState() {
|
||||
return {
|
||||
tags: [],
|
||||
@@ -154,7 +160,7 @@ class TagsPanelCtrl extends PureCtrl {
|
||||
}
|
||||
|
||||
registerComponentHandler() {
|
||||
this.application.componentManager.registerHandler({
|
||||
this.unregisterComponent = this.application.componentManager.registerHandler({
|
||||
identifier: 'tags',
|
||||
areas: ['tags-list'],
|
||||
activationHandler: (component) => {
|
||||
|
||||
Reference in New Issue
Block a user