From 89a4165c77906623f22c2182ad5b6f671754a782 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 10 Jul 2022 15:01:05 +0200 Subject: [PATCH] fixes in event propagation --- src/public/app/widgets/component.js | 24 +++++++++---------- .../app/widgets/note_context_aware_widget.js | 6 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/public/app/widgets/component.js b/src/public/app/widgets/component.js index cc461c637..0d594461a 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.js index ed0b56985..38729be5a 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 meantime if (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 meantime if (this.notePath === notePath) { await this.refresh(); }