This commit is contained in:
zadam 2020-01-26 10:42:24 +01:00
parent 3f0974d3d2
commit 97a35d6fba
3 changed files with 32 additions and 8 deletions

View file

@ -123,7 +123,7 @@ class TreeCache {
}
}
async reloadNotes(noteIds) {
async reloadData(noteIds) {
const resp = await server.post('tree/load', { noteIds });
this.addResp(resp.notes, resp.branches, resp.attributes);
@ -224,6 +224,36 @@ class TreeCache {
return child.parentToBranch[parentNoteId];
}
syncDataListener({data}) {return;
const noteIdsToRefresh = new Set();
data.filter(sync => sync.entityName === 'branches').forEach(sync => {
const branch = this.branches[sync.entityId];
// we assume that the cache contains the old branch state and we add also the old parentNoteId
// so that the old parent can also be updated
noteIdsToRefresh.add(branch.parentNoteId);
// this should then contain new parentNoteId for which we should also update the cache
noteIdsToRefresh.add(sync.parentNoteId);
});
data.filter(sync => sync.entityName === 'notes').forEach(sync => noteIdsToRefresh.add(sync.entityId));
data.filter(sync => sync.entityName === 'note_reordering').forEach(sync => noteIdsToRefresh.add(sync.entityId));
data.filter(sync => sync.entityName === 'attributes').forEach(sync => {
const note = treeCache.notes[sync.noteId];
if (note && note.__attributeCache) {
noteIdsToRefresh.add(sync.entityId);
}
});
if (noteIdsToRefresh.size > 0) {
this.reloadNotes({noteIds: Array.from(noteIdsToRefresh)});
}
}
}
const treeCache = new TreeCache();

View file

@ -88,12 +88,6 @@ class AttributesWidget extends StandardWidget {
}
}
toggle(show) {
console.trace("attributes toggle", show);
super.toggle(show);
}
syncDataListener({data}) {
if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.tabContext.note.noteId)) {
// no need to invalidate attributes since the Attribute class listens to this as well

View file

@ -533,7 +533,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
}
}
syncDataListener({data}) {
syncDataListener({data}) {return;
const noteIdsToRefresh = new Set();
// this has the problem that the former parentNoteId might not be invalidated