exposing tree cache methods to reload note's parents/children to frontend API

This commit is contained in:
zadam
2019-04-13 22:56:45 +02:00
parent dae674a7cd
commit 2b4413a1bd
3 changed files with 33 additions and 4 deletions

View File

@@ -50,7 +50,10 @@ class TreeCache {
}
}
async reload(noteId) {
/**
* Reload children of given noteId.
*/
async reloadChildren(noteId) {
const resp = await server.post('tree/load', { noteIds: [noteId] });
for (const childNoteId of this.children[noteId] || []) {
@@ -69,6 +72,22 @@ class TreeCache {
this.addResp(resp.notes, resp.branches, resp.relations);
}
/**
* Reloads parents of given noteId - useful when new note is created to make sure note is loaded
* in a correct order.
*/
async reloadParents(noteId) {
// to be able to find parents we need first to make sure it is actually loaded
await this.getNote(noteId);
for (const parentNoteId of this.parents[noteId] || []) {
await this.reloadChildren(parentNoteId);
}
// this is done to load the new parents for the noteId
await this.reloadChildren(noteId);
}
/** @return {Promise<NoteShort[]>} */
async getNotes(noteIds, silentNotFoundError = false) {
const missingNoteIds = noteIds.filter(noteId => this.notes[noteId] === undefined);