Skip to content

Commit

Permalink
bug: setup onDidAcitvePanelChange subscription quicker
Browse files Browse the repository at this point in the history
  • Loading branch information
mathuo committed Jan 27, 2025
1 parent ca09ae5 commit 08122aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
18 changes: 1 addition & 17 deletions packages/dockview-core/src/api/dockviewGroupPanelApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export class DockviewGroupPanelApiImpl extends GridviewPanelApiImpl {
readonly onDidLocationChange: Event<DockviewGroupPanelFloatingChangeEvent> =
this._onDidLocationChange.event;

private readonly _onDidActivePanelChange =
new Emitter<DockviewGroupChangeEvent>();
readonly _onDidActivePanelChange = new Emitter<DockviewGroupChangeEvent>();
readonly onDidActivePanelChange = this._onDidActivePanelChange.event;

get location(): DockviewGroupLocation {
Expand Down Expand Up @@ -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);
});
});
}
}
6 changes: 6 additions & 0 deletions packages/dockview-core/src/dockview/dockviewGroupPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ export class DockviewGroupPanel
options,
this
);

this.addDisposables(
this.model.onDidActivePanelChange((event) => {
this.api._onDidActivePanelChange.fire(event);
})
);
}

override focus(): void {
Expand Down

0 comments on commit 08122aa

Please sign in to comment.