protection against note switching race conditions

This commit is contained in:
zadam 2019-12-10 22:35:24 +01:00
parent dce54c7af3
commit 45c5287d53
3 changed files with 26 additions and 17 deletions

View File

@ -55,6 +55,8 @@ class NoteDetailCode {
this.onNoteChange(() => this.ctx.noteChanged()); this.onNoteChange(() => this.ctx.noteChanged());
} }
// lazy loading above can take time and tab might have been already switched to another note
if (this.ctx.note && this.ctx.note.type === 'code') {
// CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check) // CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check)
// we provide fallback // we provide fallback
this.codeEditor.setValue(this.ctx.note.content || ""); this.codeEditor.setValue(this.ctx.note.content || "");
@ -68,6 +70,7 @@ class NoteDetailCode {
this.show(); this.show();
} }
}
show() { show() {
this.$component.show(); this.$component.show();

View File

@ -238,14 +238,17 @@ class NoteDetailRelationMap {
await libraryLoader.requireLibrary(libraryLoader.RELATION_MAP); await libraryLoader.requireLibrary(libraryLoader.RELATION_MAP);
jsPlumb.ready(() => {
// lazy loading above can take time and tab might have been already switched to another note
if (this.ctx.note && this.ctx.note.type === 'relation-map') {
this.loadMapData(); this.loadMapData();
jsPlumb.ready(() => {
this.initJsPlumbInstance(); this.initJsPlumbInstance();
this.initPanZoom(); this.initPanZoom();
this.loadNotesAndRelations(); this.loadNotesAndRelations();
}
}); });
} }

View File

@ -98,12 +98,15 @@ class NoteDetailText {
} }
} }
// lazy loading above can take time and tab might have been already switched to another note
if (this.ctx.note && this.ctx.note.type === 'text') {
this.textEditor.isReadOnly = await this.isReadOnly(); this.textEditor.isReadOnly = await this.isReadOnly();
this.$component.show(); this.$component.show();
this.textEditor.setData(this.ctx.note.content); this.textEditor.setData(this.ctx.note.content);
} }
}
getContent() { getContent() {
let content = this.textEditor.getData(); let content = this.textEditor.getData();