Component and other handler deregisterations

This commit is contained in:
Mo Bitar
2020-03-24 12:12:07 -05:00
parent ee7cb1fce6
commit 7aa38cbdb8
11 changed files with 476 additions and 310 deletions

View File

@@ -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;
}