Skip to content

Build your personal knowledge base with Trilium Notes

simplification of sync event API

zadam25553c9e67a1
diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js
index 71f092beb7..d924518fa9 100644
--- a/src/public/javascripts/services/app_context.js
+++ b/src/public/javascripts/services/app_context.js
@@ -55,19 +55,23 @@ class AppContext {
this.trigger('initialRenderComplete');
}
- trigger(name, data, sync = false) {
+ async trigger(name, data) {
this.eventReceived(name, data);
+ const promises = [];
+
for (const component of this.components) {
- component.eventReceived(name, data, sync);
+ promises.push(component.eventReceived(name, data));
}
+
+ await Promise.all(promises);
}
- async eventReceived(name, data, sync) {
+ async eventReceived(name, data) {
const fun = this[name + 'Listener'];
if (typeof fun === 'function') {
- await fun.call(this, data, sync);
+ await fun.call(this, data);
}
}
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index e755c5d5c2..806be911bd 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -38,7 +38,7 @@ class TabContext extends Component {
return; // note is outside of hoisted subtree and user chose not to unhoist
}
- await this.trigger('beforeNoteSwitch', {tabId: this.tabId}, true);
+ await this.trigger('beforeNoteSwitch', {tabId: this.tabId});
utils.closeActiveDialog();
diff --git a/src/public/javascripts/widgets/component.js b/src/public/javascripts/widgets/component.js
index dc10ddb073..4001136543 100644
--- a/src/public/javascripts/widgets/component.js
+++ b/src/public/javascripts/widgets/component.js
@@ -15,13 +15,11 @@ export default class Component {
this.mutex = new Mutex();
}
- async eventReceived(name, data, sync = false) {
+ async eventReceived(name, data) {
await this.initialized;
const fun = this[name + 'Listener'];
- let propagateToChildren = true;
-
const start = Date.now();
if (typeof fun === 'function') {
@@ -30,7 +28,7 @@ export default class Component {
try {
release = await this.mutex.acquire();
- propagateToChildren = await fun.call(this, data) !== false;
+ await fun.call(this, data);
}
finally {
if (release) {
@@ -45,28 +43,20 @@ export default class Component {
console.log(`Event ${name} in component ${this.componentId} took ${end-start}ms`);
}
- if (propagateToChildren) {
- const promise = this.triggerChildren(name, data, sync);
-
- if (sync) {
- await promise;
- }
- }
+ await this.triggerChildren(name, data);
}
- trigger(name, data, sync = false) {
- this.appContext.trigger(name, data, sync);
+ async trigger(name, data) {
+ await this.appContext.trigger(name, data);
}
- async triggerChildren(name, data, sync = false) {
+ async triggerChildren(name, data) {
const promises = [];
for (const child of this.children) {
- promises.push(child.eventReceived(name, data, sync));
+ promises.push(child.eventReceived(name, data));
}
- if (sync) {
- await Promise.all(promises);
- }
+ await Promise.all(promises);
}
}
\ No newline at end of file
diff --git a/src/public/javascripts/widgets/side_pane_container.js b/src/public/javascripts/widgets/side_pane_container.js
index ee2efdbcc3..cb250e6f48 100644
--- a/src/public/javascripts/widgets/side_pane_container.js
+++ b/src/public/javascripts/widgets/side_pane_container.js
@@ -13,9 +13,9 @@ export default class SidePaneContainer extends FlexContainer {
return super.isEnabled() && options.is(this.side + 'PaneVisible');
}
- eventReceived(name, data, sync = false) {
+ eventReceived(name, data) {
if (options.is(this.side + 'PaneVisible')) {
- super.eventReceived(name, data, sync);
+ super.eventReceived(name, data);
}
}
diff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.js
index 8914e8a989..8052f6123d 100644
--- a/src/public/javascripts/widgets/tab_caching_widget.js
+++ b/src/public/javascripts/widgets/tab_caching_widget.js
@@ -16,12 +16,12 @@ export default class TabCachingWidget extends TabAwareWidget {
return this.$widget = $(`<div class="marker" style="display: none;">`);
}
- activeTabChangedListener(param) {
- super.activeTabChangedListener(param);
-
+ async triggerChildren(name, data) {
// stop propagation of the event to the children, individual tab widget should not know about tab switching
// since they are per-tab
- return false;
+ if (name !== 'activeTabChanged') {
+ super.triggerChildren(name, data);
+ }
}
refreshWithNote() {