Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f521a34

Browse filesBrowse files
committed
fix(cdk): mark scheduler tasks as pending tasks
1 parent 96750c4 commit f521a34
Copy full SHA for f521a34

File tree

2 files changed

+37
-22
lines changed
Filter options

2 files changed

+37
-22
lines changed

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

Copy file name to clipboardExpand all lines: libs/cdk/render-strategies/src/lib/concurrent-strategies.ts
+21-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NgZone } from '@angular/core';
1+
import { NgZone, PendingTasks } from '@angular/core';
22
import { coalescingManager, coalescingObj } from '@rx-angular/cdk/coalescing';
33
import {
44
cancelCallback,
@@ -17,6 +17,14 @@ import {
1717
// set default to 60fps
1818
forceFrameRate(60);
1919

20+
let pendingTasks: PendingTasks | undefined;
21+
22+
export function setPendingTasks(p: PendingTasks) {
23+
if (!pendingTasks) {
24+
pendingTasks = p;
25+
}
26+
}
27+
2028
const immediateStrategy: RxStrategyCredentials = {
2129
name: 'immediate',
2230
work: (cdRef) => cdRef.detectChanges(),
@@ -27,7 +35,7 @@ const immediateStrategy: RxStrategyCredentials = {
2735
ngZone,
2836
priority: PriorityLevel.ImmediatePriority,
2937
scope,
30-
})
38+
}),
3139
);
3240
},
3341
};
@@ -42,7 +50,7 @@ const userBlockingStrategy: RxStrategyCredentials = {
4250
ngZone,
4351
priority: PriorityLevel.UserBlockingPriority,
4452
scope,
45-
})
53+
}),
4654
);
4755
},
4856
};
@@ -57,7 +65,7 @@ const normalStrategy: RxStrategyCredentials = {
5765
ngZone,
5866
priority: PriorityLevel.NormalPriority,
5967
scope,
60-
})
68+
}),
6169
);
6270
},
6371
};
@@ -72,7 +80,7 @@ const lowStrategy: RxStrategyCredentials = {
7280
ngZone,
7381
priority: PriorityLevel.LowPriority,
7482
scope,
75-
})
83+
}),
7684
);
7785
},
7886
};
@@ -87,7 +95,7 @@ const idleStrategy: RxStrategyCredentials = {
8795
ngZone,
8896
priority: PriorityLevel.IdlePriority,
8997
scope,
90-
})
98+
}),
9199
);
92100
},
93101
};
@@ -99,7 +107,7 @@ function scheduleOnQueue<T>(
99107
scope: coalescingObj;
100108
delay?: number;
101109
ngZone: NgZone;
102-
}
110+
},
103111
): MonoTypeOperatorFunction<T> {
104112
const scope = (options.scope as Record<string, unknown>) || {};
105113
return (o$: Observable<T>): Observable<T> =>
@@ -108,21 +116,24 @@ function scheduleOnQueue<T>(
108116
switchMap((v) =>
109117
new Observable<T>((subscriber) => {
110118
coalescingManager.add(scope);
119+
const cleanup = pendingTasks?.add();
111120
const task = scheduleCallback(
112121
options.priority,
113122
() => {
114123
work();
115124
coalescingManager.remove(scope);
116125
subscriber.next(v);
126+
cleanup?.();
117127
},
118-
{ delay: options.delay, ngZone: options.ngZone }
128+
{ delay: options.delay, ngZone: options.ngZone },
119129
);
120130
return () => {
121131
coalescingManager.remove(scope);
122132
cancelCallback(task);
133+
cleanup?.();
123134
};
124-
}).pipe(mapTo(v))
125-
)
135+
}).pipe(mapTo(v)),
136+
),
126137
);
127138
}
128139

‎libs/cdk/render-strategies/src/lib/strategy-provider.service.ts

Copy file name to clipboardExpand all lines: libs/cdk/render-strategies/src/lib/strategy-provider.service.ts
+16-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {
22
ChangeDetectorRef,
33
Inject,
4+
inject,
45
Injectable,
56
NgZone,
67
Optional,
8+
PendingTasks,
79
} from '@angular/core';
810
import {
911
BehaviorSubject,
@@ -12,6 +14,7 @@ import {
1214
Observable,
1315
} from 'rxjs';
1416
import { map, shareReplay, switchMap, takeUntil } from 'rxjs/operators';
17+
import { setPendingTasks } from './concurrent-strategies';
1518
import {
1619
mergeDefaultConfig,
1720
RX_RENDER_STRATEGIES_CONFIG,
@@ -108,7 +111,7 @@ export class RxStrategyProvider<T extends string = string> {
108111
*/
109112
set primaryStrategy(strategyName: RxStrategyNames<T>) {
110113
this._primaryStrategy$.next(
111-
<RxStrategyCredentials<RxStrategyNames<T>>>this.strategies[strategyName]
114+
<RxStrategyCredentials<RxStrategyNames<T>>>this.strategies[strategyName],
112115
);
113116
}
114117

@@ -131,7 +134,7 @@ export class RxStrategyProvider<T extends string = string> {
131134
*/
132135
readonly strategyNames$ = this.strategies$.pipe(
133136
map((strategies) => Object.values(strategies).map((s) => s.name)),
134-
shareReplay({ bufferSize: 1, refCount: true })
137+
shareReplay({ bufferSize: 1, refCount: true }),
135138
);
136139

137140
/**
@@ -140,8 +143,9 @@ export class RxStrategyProvider<T extends string = string> {
140143
constructor(
141144
@Optional()
142145
@Inject(RX_RENDER_STRATEGIES_CONFIG)
143-
cfg: RxRenderStrategiesConfig<T>
146+
cfg: RxRenderStrategiesConfig<T>,
144147
) {
148+
setPendingTasks(inject(PendingTasks));
145149
this._cfg = mergeDefaultConfig(cfg);
146150
this._strategies$.next(this._cfg.customStrategies as any);
147151
this.primaryStrategy = this.config.primaryStrategy;
@@ -165,7 +169,7 @@ export class RxStrategyProvider<T extends string = string> {
165169
*/
166170
scheduleWith<R>(
167171
work: (v?: R) => void,
168-
options?: ScheduleOnStrategyOptions
172+
options?: ScheduleOnStrategyOptions,
169173
): MonoTypeOperatorFunction<R> {
170174
const strategy = this.strategies[options?.strategy || this.primaryStrategy];
171175
const scope = options?.scope || {};
@@ -180,9 +184,9 @@ export class RxStrategyProvider<T extends string = string> {
180184
(_v) => {
181185
_work(_v);
182186
},
183-
{ scope, ngZone }
184-
)
185-
)
187+
{ scope, ngZone },
188+
),
189+
),
186190
);
187191
}
188192

@@ -202,7 +206,7 @@ export class RxStrategyProvider<T extends string = string> {
202206
*/
203207
schedule<R>(
204208
work: () => R,
205-
options?: ScheduleOnStrategyOptions
209+
options?: ScheduleOnStrategyOptions,
206210
): Observable<R> {
207211
const strategy = this.strategies[options?.strategy || this.primaryStrategy];
208212
const scope = options?.scope || {};
@@ -215,7 +219,7 @@ export class RxStrategyProvider<T extends string = string> {
215219
() => {
216220
returnVal = _work();
217221
},
218-
{ scope, ngZone }
222+
{ scope, ngZone },
219223
).pipe(map(() => returnVal));
220224
}
221225

@@ -236,7 +240,7 @@ export class RxStrategyProvider<T extends string = string> {
236240
options?: ScheduleOnStrategyOptions & {
237241
afterCD?: () => void;
238242
abortCtrl?: AbortController;
239-
}
243+
},
240244
): AbortController {
241245
const strategy = this.strategies[options?.strategy || this.primaryStrategy];
242246
const scope = options?.scope || cdRef;
@@ -254,7 +258,7 @@ export class RxStrategyProvider<T extends string = string> {
254258
() => {
255259
work();
256260
},
257-
{ scope, ngZone }
261+
{ scope, ngZone },
258262
)
259263
.pipe(takeUntil(fromEvent(abC.signal, 'abort')))
260264
.subscribe();
@@ -264,7 +268,7 @@ export class RxStrategyProvider<T extends string = string> {
264268

265269
function getWork<T>(
266270
work: (args?: any) => T,
267-
patchZone?: false | NgZone
271+
patchZone?: false | NgZone,
268272
): (args?: any) => T {
269273
let _work = work;
270274
if (patchZone) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.