mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	simplification of sync event API
This commit is contained in:
		| @@ -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); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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(); | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
|     } | ||||
| } | ||||
| @@ -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); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user