Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fixes in event propagation
zadam89a4165c7790
diff --git a/src/public/app/widgets/component.js b/src/public/app/widgets/component.jsindex cc461c6373..0d594461ac 100644--- a/src/public/app/widgets/component.js+++ b/src/public/app/widgets/component.js@@ -51,7 +51,7 @@ export default class Component {// don't create promises if not needed (optimization)return callMethodPromise && childrenPromise? Promise.all([callMethodPromise, childrenPromise])- : null;+ : (callMethodPromise || childrenPromise);}/** @returns {Promise} */@@ -64,11 +64,15 @@ export default class Component {const promises = [];for (const child of this.children) {- promises.push(child.handleEvent(name, data));+ const ret = child.handleEvent(name, data);++ if (ret) {+ promises.push(ret);+ }}// don't create promises if not needed (optimization)- return promises.find(p => p) ? Promise.all(promises) : null;+ return promises.length > 0 ? Promise.all(promises) : null;}/** @returns {Promise} */@@ -83,9 +87,9 @@ export default class Component {}}- async callMethod(fun, data) {+ callMethod(fun, data) {if (typeof fun !== 'function') {- return false;+ return;}const startTime = Date.now();@@ -98,14 +102,10 @@ export default class Component {console.log(`Call to ${fun.name} in ${this.componentId} took ${took}ms`);}- if (glob.isDev) {- await utils.timeLimit(promise, 20000, `Time limit failed on ${this.constructor.name} with ${fun.name}`);- }- else {- // cheaper and in non-dev the extra reporting is lost anyway through reload- await promise;+ if (glob.isDev && promise) {+ return utils.timeLimit(promise, 20000, `Time limit failed on ${this.constructor.name} with ${fun.name}`);}- return true;+ return promise;}}diff --git a/src/public/app/widgets/note_context_aware_widget.js b/src/public/app/widgets/note_context_aware_widget.jsindex ed0b569851..38729be5a2 100644--- a/src/public/app/widgets/note_context_aware_widget.js+++ b/src/public/app/widgets/note_context_aware_widget.js@@ -28,7 +28,7 @@ export default class NoteContextAwareWidget extends BasicWidget {}get notePath() {- return this.noteContext.notePath && this.noteContext;+ return this.noteContext?.notePath;}get hoistedNoteId() {@@ -64,7 +64,7 @@ export default class NoteContextAwareWidget extends BasicWidget {async refreshWithNote(note) {}async noteSwitchedEvent({noteContext, notePath}) {- // if notePath does not match then the noteContext has been switched to another note in the mean time+ // if notePath does not match then the noteContext has been switched to another note in the meantimeif (noteContext.notePath === notePath) {await this.noteSwitched();}@@ -88,7 +88,7 @@ export default class NoteContextAwareWidget extends BasicWidget {async noteSwitchedAndActivatedEvent({noteContext, notePath}) {this.noteContext = noteContext;- // if notePath does not match then the noteContext has been switched to another note in the mean time+ // if notePath does not match then the noteContext has been switched to another note in the meantimeif (this.notePath === notePath) {await this.refresh();}