Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a2a43b

Browse files
committed
refactor(cdk): render-strategies: convert renderbehavior params to object
1 parent 2ee0e32 commit 2a2a43b

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

libs/cdk/render-strategies/src/lib/concurrent-strategies.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ forceFrameRate(60);
2020
const immediateStrategy: RxStrategyCredentials = {
2121
name: 'immediate',
2222
work: (cdRef) => cdRef.detectChanges(),
23-
behavior: (work: any, scope: any, ngZone: NgZone) => {
23+
behavior: ({ work, scope, ngZone }) => {
2424
return (o$) =>
2525
o$.pipe(
2626
scheduleOnQueue(work, {
27-
ngZone, priority: PriorityLevel.ImmediatePriority,
27+
ngZone,
28+
priority: PriorityLevel.ImmediatePriority,
2829
scope,
2930
})
3031
);
@@ -34,11 +35,12 @@ const immediateStrategy: RxStrategyCredentials = {
3435
const userBlockingStrategy: RxStrategyCredentials = {
3536
name: 'userBlocking',
3637
work: (cdRef) => cdRef.detectChanges(),
37-
behavior: (work: any, scope: any, ngZone: NgZone) => {
38+
behavior: ({ work, scope, ngZone }) => {
3839
return (o$) =>
3940
o$.pipe(
4041
scheduleOnQueue(work, {
41-
ngZone, priority: PriorityLevel.UserBlockingPriority,
42+
ngZone,
43+
priority: PriorityLevel.UserBlockingPriority,
4244
scope,
4345
})
4446
);
@@ -48,32 +50,44 @@ const userBlockingStrategy: RxStrategyCredentials = {
4850
const normalStrategy: RxStrategyCredentials = {
4951
name: 'normal',
5052
work: (cdRef) => cdRef.detectChanges(),
51-
behavior: (work: any, scope: any, ngZone: NgZone) => {
53+
behavior: ({ work, scope, ngZone }) => {
5254
return (o$) =>
5355
o$.pipe(
54-
scheduleOnQueue(work, { ngZone, priority: PriorityLevel.NormalPriority, scope })
56+
scheduleOnQueue(work, {
57+
ngZone,
58+
priority: PriorityLevel.NormalPriority,
59+
scope,
60+
})
5561
);
5662
},
5763
};
5864

5965
const lowStrategy: RxStrategyCredentials = {
6066
name: 'low',
6167
work: (cdRef) => cdRef.detectChanges(),
62-
behavior: (work: any, scope: any, ngZone: NgZone) => {
68+
behavior: ({ work, scope, ngZone }) => {
6369
return (o$) =>
6470
o$.pipe(
65-
scheduleOnQueue(work, { ngZone, priority: PriorityLevel.LowPriority, scope })
71+
scheduleOnQueue(work, {
72+
ngZone,
73+
priority: PriorityLevel.LowPriority,
74+
scope,
75+
})
6676
);
6777
},
6878
};
6979

7080
const idleStrategy: RxStrategyCredentials = {
7181
name: 'idle',
7282
work: (cdRef) => cdRef.detectChanges(),
73-
behavior: (work: any, scope: any, ngZone: NgZone) => {
83+
behavior: ({ work, scope, ngZone }) => {
7484
return (o$) =>
7585
o$.pipe(
76-
scheduleOnQueue(work, { ngZone, priority: PriorityLevel.IdlePriority, scope })
86+
scheduleOnQueue(work, {
87+
ngZone,
88+
priority: PriorityLevel.IdlePriority,
89+
scope,
90+
})
7791
);
7892
},
7993
};
@@ -84,7 +98,7 @@ function scheduleOnQueue<T>(
8498
priority: PriorityLevel;
8599
scope: Record<string, unknown>;
86100
delay?: number;
87-
ngZone: NgZone
101+
ngZone: NgZone;
88102
}
89103
): MonoTypeOperatorFunction<T> {
90104
return (o$: Observable<T>): Observable<T> =>
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ChangeDetectorRef, NgZone } from '@angular/core';
2-
import { coalescingObj } from '@rx-angular/cdk/coalescing';
32
import { RxNotification } from '@rx-angular/cdk/notifications';
43
import { Observable } from 'rxjs';
54

@@ -11,23 +10,25 @@ export interface ScheduleOnStrategyOptions {
1110

1211
export type RxRenderWork = <T = unknown>(
1312
cdRef: ChangeDetectorRef,
14-
scope?: coalescingObj,
13+
scope?: Record<string, unknown>,
1514
notification?: RxNotification<T>
1615
) => void;
17-
export type RxRenderBehavior = <T = unknown>(
18-
work: any,
19-
scope?: coalescingObj,
20-
ngZone?: NgZone
21-
) => (o: Observable<T>) => Observable<T>;
16+
export type RxRenderBehavior = <T = unknown>(params: {
17+
work: () => any;
18+
scope?: Record<string, unknown>;
19+
ngZone?: NgZone;
20+
}) => (o: Observable<T>) => Observable<T>;
2221

2322
export interface RxStrategyCredentials<S = string> {
2423
name: S;
2524
work: RxRenderWork;
2625
behavior: RxRenderBehavior;
2726
}
2827

29-
export type RxCustomStrategyCredentials<T extends string> = Record<T,
30-
RxStrategyCredentials>;
28+
export type RxCustomStrategyCredentials<T extends string> = Record<
29+
T,
30+
RxStrategyCredentials
31+
>;
3132
export type RxNativeStrategyNames = 'native' | 'local' | 'global' | 'noop';
3233
export type RxConcurrentStrategyNames =
3334
| 'immediate'
@@ -39,4 +40,6 @@ export type RxDefaultStrategyNames =
3940
| RxNativeStrategyNames
4041
| RxConcurrentStrategyNames;
4142
export type RxStrategyNames<T> = RxDefaultStrategyNames | T;
42-
export type RxStrategies<T extends string> = RxCustomStrategyCredentials<RxStrategyNames<T>>;
43+
export type RxStrategies<T extends string> = RxCustomStrategyCredentials<
44+
RxStrategyNames<T>
45+
>;

0 commit comments

Comments
 (0)