mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
10x speed-up of event propagation
This commit is contained in:
parent
ae46b3df58
commit
42e262a1c2
@ -16,7 +16,7 @@ export default class Component {
|
||||
this.componentId = `comp-` + this.sanitizedClassName + '-' + utils.randomString(8);
|
||||
/** @type Component[] */
|
||||
this.children = [];
|
||||
this.initialized = Promise.resolve();
|
||||
this.initialized = null;
|
||||
}
|
||||
|
||||
get sanitizedClassName() {
|
||||
@ -42,10 +42,16 @@ export default class Component {
|
||||
|
||||
/** @returns {Promise} */
|
||||
handleEvent(name, data) {
|
||||
return Promise.all([
|
||||
this.initialized.then(() => this.callMethod(this[name + 'Event'], data)),
|
||||
this.handleEventInChildren(name, data)
|
||||
]);
|
||||
const callMethodPromise = this.initialized
|
||||
? this.initialized.then(() => this.callMethod(this[name + 'Event'], data))
|
||||
: this.callMethod(this[name + 'Event'], data);
|
||||
|
||||
const childrenPromise = this.handleEventInChildren(name, data);
|
||||
|
||||
// don't create promises if not needed (optimization)
|
||||
return callMethodPromise && childrenPromise
|
||||
? Promise.all([callMethodPromise, childrenPromise])
|
||||
: null;
|
||||
}
|
||||
|
||||
/** @returns {Promise} */
|
||||
@ -61,7 +67,8 @@ export default class Component {
|
||||
promises.push(child.handleEvent(name, data));
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
// don't create promises if not needed (optimization)
|
||||
return promises.find(p => p) ? Promise.all(promises) : null;
|
||||
}
|
||||
|
||||
/** @returns {Promise} */
|
||||
|
@ -186,9 +186,13 @@ export default class RibbonContainer extends NoteContextAwareWidget {
|
||||
const activeChild = this.getActiveRibbonWidget();
|
||||
|
||||
if (activeChild && (refreshActiveTab || !wasAlreadyActive)) {
|
||||
activeChild.handleEvent('noteSwitched', {noteContext: this.noteContext, notePath: this.notePath}).then(() => {
|
||||
const handleEventPromise = activeChild.handleEvent('noteSwitched', {noteContext: this.noteContext, notePath: this.notePath});
|
||||
|
||||
if (handleEventPromise) {
|
||||
handleEventPromise.then(() => activeChild.focus?.());
|
||||
} else {
|
||||
activeChild.focus?.();
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.lastActiveComponentId = null;
|
||||
|
@ -23,8 +23,13 @@ export default class RightPaneContainer extends FlexContainer {
|
||||
// right pane is displayed only if some child widget is active
|
||||
// we'll reevaluate the visibility based on events which are probable to cause visibility change
|
||||
// but these events needs to be finished and only then we check
|
||||
if (promise) {
|
||||
promise.then(() => this.reevaluateIsEnabledCommand());
|
||||
}
|
||||
else {
|
||||
this.reevaluateIsEnabledCommand();
|
||||
}
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user