-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk): add
tuiTakeUntilDestroyed
helper (#7381)
Signed-off-by: waterplea <[email protected]>
- Loading branch information
Showing
6 changed files
with
50 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type {DestroyRef} from '@angular/core'; | ||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; | ||
import type {MonoTypeOperatorFunction} from 'rxjs'; | ||
import {catchError, defaultIfEmpty, EMPTY, NEVER, pipe, takeUntil} from 'rxjs'; | ||
|
||
// NOTE: takeUntilDestroyed and DestroyRef can cause error: | ||
// NG0911: View has already been destroyed | ||
// https://github.com/angular/angular/issues/54527 | ||
export function tuiTakeUntilDestroyed<T>( | ||
destroyRef?: DestroyRef, | ||
): MonoTypeOperatorFunction<T> { | ||
return pipe( | ||
takeUntil( | ||
NEVER.pipe( | ||
// eslint-disable-next-line rxjs/no-unsafe-takeuntil | ||
takeUntilDestroyed(destroyRef), | ||
catchError(() => EMPTY), | ||
defaultIfEmpty(null), | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters