8000 refactor(state): use DestroyRef instead of OnDestroy life cycle hook · rx-angular/rx-angular@c3efc77 · GitHub
[go: up one dir, main page]

Skip to content
65FB

Commit c3efc77

Browse files
committed
refactor(state): use DestroyRef instead of OnDestroy life cycle hook
1 parent 70173f6 commit c3efc77

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

libs/state/src/lib/rx-state.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
22
computed,
3+
DestroyRef,
34
inject,
45
Injectable,
56
Injector,
67
isSignal,
7-
OnDestroy,
88
Signal,
99
} from '@angular/core';
1010
import { toSignal } from '@angular/core/rxjs-interop';
@@ -75,9 +75,8 @@ export type ReadOnly = 'get' | 'select' | 'computed' | 'signal';
7575
* @docsPage RxState
7676
*/
7777
@Injectable()
78-
export class RxState<State extends object>
79-
implements OnDestroy, Subscribable<State>
80-
{
78+
export class RxState<State extends object> implements Subscribable<State> {
79+
private readonly destroyRef = inject(DestroyRef);
8180
private subscription = new Subscription();
8281

8382
protected scheduler = inject(RX_STATE_SCHEDULER, { optional: true });
@@ -109,6 +108,8 @@ export class RxState<State extends object>
109108
*/
110109
constructor() {
111110
this.subscription.add(this.subscribe());
111+
112+
this.destroyRef.onDestroy(() => this.ngOnDestroy());
112113
}
113114

114115
/**

0 commit comments

Comments
 (0)
0