Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions goldens/public-api/core/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ export function destroyPlatform(): void;

// @public
export abstract class DestroyRef {
abstract get destroyed(): boolean;
abstract onDestroy(callback: () => void): () => void;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/rxjs-interop/src/take_until_destroyed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export function takeUntilDestroyed<T>(destroyRef?: DestroyRef): MonoTypeOperator
}

const destroyed$ = new Observable<void>((subscriber) => {
if ((destroyRef as unknown as {destroyed: boolean}).destroyed) {
if (destroyRef.destroyed) {
subscriber.next();
return;
}
const unregisterFn = destroyRef!.onDestroy(subscriber.next.bind(subscriber));
const unregisterFn = destroyRef.onDestroy(subscriber.next.bind(subscriber));
return unregisterFn;
});

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/linker/destroy_ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export abstract class DestroyRef {
*/
abstract onDestroy(callback: () => void): () => void;

/** @internal */
/**
* Indicates whether the instance has already been destroyed and whether its `onDestroy` callbacks have executed.
*/
abstract get destroyed(): boolean;

/**
Expand Down