8000 refactor(demos): remove programmatic usage of ngOnDestroy · rx-angular/rx-angular@aba2ee5 · GitHub
[go: up one dir, main page]

Skip to content

Commit aba2ee5

Browse files
committed
refactor(demos): remove programmatic usage of ngOnDestroy
1 parent 7043b41 commit aba2ee5

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

apps/demos/src/app/features/tutorials/basics/5-side-effects/side-effects.solution.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
ChangeDetectionStrategy,
33
Component,
44
Input,
5-
OnDestroy,
65
OnInit,
76
Output,
87
} from '@angular/core';
@@ -74,7 +73,7 @@ const initComponentState = {
7473
})
7574
export class SideEffectsSolution
7675
extends RxState<ComponentState>
77-
implements OnInit, OnDestroy
76+
implements OnInit
7877
{
7978
model$ = this.select();
8079

apps/demos/src/app/shared/debug-helper/value-provider/primitives-provider.service.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { merge, Observable, Subject } from 'rxjs';
44
import { map, scan } from 'rxjs/operators';
55
import { ngInputFlatten } from '../../utils/ngInputFlatten';
66
import { ProvidedValues } from './model';
7-
import { toBoolean, toImgUrl, toInt, toRandom, withCompleteAndError } from './utils';
7+
import {
8+
toBoolean,
9+
toImgUrl,
10+
toInt,
11+
toRandom,
12+
withCompleteAndError,
13+
} from './utils';
814

915
@Injectable()
1016
export class PrimitivesProviderService {
@@ -16,7 +22,7 @@ export class PrimitivesProviderService {
1622
protected error$ = this.errorSubject.pipe(
1723
map((_) => {
1824
throw new Error('ERROR');
19-
})
25+
}),
2026
);
2127
protected completeSubject = new Subject<any>();
2228
protected resetSubject = new Subject<any>();
@@ -46,32 +52,31 @@ export class PrimitivesProviderService {
4652
};
4753

4854
private resetObservables = () => {
49-
this.state.ngOnDestroy();
5055
this.state = new RxState<ProvidedValues>();
5156

5257
this.state.connect(
5358
'random',
5459
merge(this.nextSubject, this.outerChanges.pipe(ngInputFlatten())).pipe(
55-
map(toRandom)
56-
)
60+
map(toRandom),
61+
),
5762
);
5863

5964
this.float$ = this.state.select('random');
6065
this.int$ = this.state.select(
6166
map((s) => toInt(s.random, this.min, this.max)),
62-
withCompleteAndError(this.error$, this.completeSubject)
67+
withCompleteAndError(this.error$, this.completeSubject),
6368
);
6469
this.incremental$ = this.state.select(
6570
scan((inc) => ++inc, 0),
66-
withCompleteAndError(this.error$, this.completeSubject)
71+
withCompleteAndError(this.error$, this.completeSubject),
6772
);
6873
this.boolean$ = this.state.select(
6974
map((s) => toBoolean(s.random, this.truthy)),
70-
withCompleteAndError(this.error$, this.completeSubject)
75+
withCompleteAndError(this.error$, this.completeSubject),
7176
);
7277
this.imgUrl$ = this.state.select(
7378
map((s) => toImgUrl(s.random)),
74-
withCompleteAndError(this.error$, this.completeSubject)
79+
withCompleteAndError(this.error$, this.completeSubject),
7580
);
7681

7782
this.state.hold(this.float$, this.updateStatic);
@@ -86,7 +91,7 @@ export class PrimitivesProviderService {
8691

8792
constructor(
8893
protected state: RxState<ProvidedValues>,
89-
protected cdRef: ChangeDetectorRef
94+
protected cdRef: ChangeDetectorRef,
9095
) {
9196
this.resetAll();
9297
}

apps/demos/src/app/shared/viewport.service.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { BreakpointObserver, Breakpoints, BreakpointState } from '@angular/cdk/layout';
2-
import { Injectable, OnDestroy } from '@angular/core';
1+
import {
2+
BreakpointObserver,
3+
Breakpoints,
4+
BreakpointState,
5+
} from '@angular/cdk/layout';
6+
import { Injectable } from '@angular/core';
37
import { RxState } from '@rx-angular/state';
48
import { distinctUntilChanged, map } from 'rxjs/operators';
59

@@ -20,7 +24,7 @@ interface ViewportServiceState {
2024
@Injectable({
2125
providedIn: 'root',
2226
})
23-
export class ViewportService implements OnDestroy {
27+
export class ViewportService {
2428
private readonly state = new RxState<ViewportServiceState A21C >();
2529

2630
readonly viewport$ = this.state.select('viewport');
@@ -52,15 +56,10 @@ export class ViewportService implements OnDestroy {
5256
);
5357
this.state.connect(viewport$, (oldState, viewportChange) => ({
5458
viewport: viewportChange,
55-
isHandset:
56-
viewportChange === 'mobile' || viewportChange === 'tablet',
59+
isHandset: viewportChange === 'mobile' || viewportChange === 'tablet',
5760
isMobile: viewportChange === 'mobile',
5861
isTablet: viewportChange === 'tablet',
5962
isDesktop: viewportChange === 'desktop',
6063
}));
6164
}
62-
63-
ngOnDestroy() {
64-
this.state.ngOnDestroy();
65-
}
6665
}

0 commit comments

Comments
 (0)
0