From 08122aa5ad0921b867e8661c659fbbeea68888bb Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Mon, 27 Jan 2025 22:47:53 +0000 Subject: [PATCH] bug: setup onDidAcitvePanelChange subscription quicker --- .../src/api/dockviewGroupPanelApi.ts | 18 +----------------- .../src/dockview/dockviewGroupPanel.ts | 6 ++++++ 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/dockview-core/src/api/dockviewGroupPanelApi.ts b/packages/dockview-core/src/api/dockviewGroupPanelApi.ts index 12424debb..a1b194b36 100644 --- a/packages/dockview-core/src/api/dockviewGroupPanelApi.ts +++ b/packages/dockview-core/src/api/dockviewGroupPanelApi.ts @@ -50,8 +50,7 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl { readonly onDidLocationChange: Event = this._onDidLocationChange.event; - private readonly _onDidActivePanelChange = - new Emitter(); + readonly _onDidActivePanelChange = new Emitter(); readonly onDidActivePanelChange = this._onDidActivePanelChange.event; get location(): DockviewGroupLocation { @@ -140,21 +139,6 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl { } initialize(group: DockviewGroupPanel): void { - /** - * TODO: Annoying initialization order caveat, find a better way to initialize and avoid needing null checks - * - * Due to the order on initialization we know that the model isn't defined until later in the same stack-frame of setup. - * By queuing a microtask we can ensure the setup is completed within the same stack-frame, but after everything else has - * finished ensuring the `model` is defined. - */ - this._group = group; - - queueMicrotask(() => { - this._mutableDisposable.value = - this._group!.model.onDidActivePanelChange((event) => { - this._onDidActivePanelChange.fire(event); - }); - }); } } diff --git a/packages/dockview-core/src/dockview/dockviewGroupPanel.ts b/packages/dockview-core/src/dockview/dockviewGroupPanel.ts index a3e714829..fd5e70fe3 100644 --- a/packages/dockview-core/src/dockview/dockviewGroupPanel.ts +++ b/packages/dockview-core/src/dockview/dockviewGroupPanel.ts @@ -124,6 +124,12 @@ export class DockviewGroupPanel options, this ); + + this.addDisposables( + this.model.onDidActivePanelChange((event) => { + this.api._onDidActivePanelChange.fire(event); + }) + ); } override focus(): void {