Skip to content

Commit

Permalink
fix: cleanup shownPanels stream when new model supplied, closes #55 (#56
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tFaster committed Jan 5, 2023
1 parent 0309819 commit fbcce80
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions projects/stacked-panels/src/lib/stacked-panels.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class StackedPanelsService {
this._subPanelsMap.clear();
this._panelDataMap.clear();
this._panels$.next([rootPanel]);
this._showPanel<T, C>(rootPanel);
this._showPanel<T, C>(rootPanel, undefined, true);
}

private _hidePanelById(panelId: string): void {
Expand Down Expand Up @@ -73,7 +73,16 @@ export class StackedPanelsService {
return true;
}

private _showPanel<T, C>(panel: Panel<T, C>, context?: C): void {
private _showPanel<T, C>(panel: Panel<T, C>, context?: C, cleanupShownPanels: boolean = false): void {
this._addSubPanelsAndAddDataToDataMap(panel, context);
if (cleanupShownPanels) {
this._shownPanels$.next([panel]);
} else {
this._shownPanels$.next([...this._shownPanels, panel]);
}
}

private _addSubPanelsAndAddDataToDataMap<T, C>(panel: Panel<T, C>, context?: C): void {
if (panel.subPanels && panel.subPanels.length > 0) {
this._addPanels(panel.id, panel.subPanels);
}
Expand All @@ -95,7 +104,6 @@ export class StackedPanelsService {
}
this._panelDataMap.set(panel.id, data);
}
this._shownPanels$.next([...this._shownPanels, panel]);
}

public getController<T, C>(panelId: string): StackedPanelsController {
Expand Down

0 comments on commit fbcce80

Please sign in to comment.