Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(table): Fixes an issue with ngDestroy timings.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheller committed Nov 2, 2023
1 parent 538c78e commit bb0dc86
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 16 deletions.
16 changes: 12 additions & 4 deletions libs/barista-components/table/src/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,18 @@ export class DtCell implements AfterContentInit, OnDestroy {
}

ngOnDestroy(): void {
this._stateChanges.complete();
this._sortChangeSubscription.unsubscribe();
this._destroy.next();
this._destroy.complete();
// Exhaustively check if the subjects still exist during the onDestroy
// ADES-5588
if (this._stateChanges) {
this._stateChanges.complete();
}
if (this._sortChangeSubscription) {
this._sortChangeSubscription.unsubscribe();
}
if (this._destroy) {
this._destroy.next();
this._destroy.complete();
}
if (this._row) {
this._row._unregisterCell(this);
}
Expand Down
8 changes: 6 additions & 2 deletions libs/barista-components/table/src/header/header-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export class DtHeaderCell implements OnDestroy {
}

ngOnDestroy(): void {
this._destroy.next();
this._destroy.complete();
// Exhaustively check if the subjects still exist during the onDestroy
// ADES-5588
if (this._destroy) {
this._destroy.next();
this._destroy.complete();
}
}
}
8 changes: 6 additions & 2 deletions libs/barista-components/table/src/order/order-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ export class DtOrderCell<T>
}

ngOnDestroy(): void {
this._destroy$.next();
this._destroy$.complete();
// Exhaustively check if the subjects still exist during the onDestroy
// ADES-5588
if (this._destroy$) {
this._destroy$.next();
this._destroy$.complete();
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions libs/barista-components/table/src/selection/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ export class DtTableHeaderSelector<T> implements OnDestroy {
}

ngOnDestroy(): void {
this._destroy$.next();
this._destroy$.complete();
// Exhaustively check if the subjects still exist during the onDestroy
// ADES-5588
if (this._destroy$) {
this._destroy$.next();
this._destroy$.complete();
}
}

/** @internal Callback when the master checkbox is interacted with */
Expand Down
13 changes: 10 additions & 3 deletions libs/barista-components/table/src/sort/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export class DtSort

/** Event emitted when the user changes either the active sort or sort direction. */
@Output('dtSortChange')
readonly sortChange: EventEmitter<DtSortEvent> = new EventEmitter<DtSortEvent>();
readonly sortChange: EventEmitter<DtSortEvent> =
new EventEmitter<DtSortEvent>();

/** Sets the active sort id and determines the new sort direction. */
sort(sortable: DtSortHeader): void;
Expand Down Expand Up @@ -172,8 +173,14 @@ export class DtSort
}

ngOnDestroy(): void {
this._stateChanges.complete();
this._initialized.complete();
// Exhaustively check if the subjects still exist during the onDestroy
// ADES-5588
if (this._stateChanges) {
this._stateChanges.complete();
}
if (this._initialized) {
this._initialized.complete();
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions libs/barista-components/table/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,15 @@ export class DtTable<T> extends _DtTableBase<T> implements OnDestroy {

ngOnDestroy(): void {
super.ngOnDestroy();
this._destroy$.next();
this._destroy$.complete();
this._portalOutletSubscription.unsubscribe();
// Exhaustively check if the subjects still exist during the onDestroy
// ADES-5588
if (this._destroy$) {
this._destroy$.next();
this._destroy$.complete();
}
if (this._portalOutletSubscription) {
this._portalOutletSubscription.unsubscribe();
}
}

/**
Expand Down

0 comments on commit bb0dc86

Please sign in to comment.