Skip to content

Commit f46e837

Browse files
hoebbelsBedbzn
andauthored
feat(cdk): deprecate global StrategyCredentials and replace with native (#1389)
* feat(cdk): deprecate global StrategyCredentials and replace with native * refactor(cdk): mark global strategy const and name as deprecated * docs(cdk): mark global strategy as deprecated Co-authored-by: Edouard Bozon <bozonedouard@gmail.com>
1 parent f6a82ad commit f46e837

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

libs/cdk/render-strategies/docs/basic-strategies.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ In combination with Observables, and EmbeddedViews change detection can be speed
8181

8282
### Strategies
8383

84-
| Name | Priority | Render Method | Scheduling | Render Deadline |
85-
| ---------- | -------- | ----------------- | ----------------------- | --------------- |
86-
| `"native"` ||`markForCheck` | `requestAnimationFrame` | N/A |
87-
| `"global"` ||`ɵmarkDirty` | `requestAnimationFrame` | N/A |
88-
| `"local"` || 🠗 `detectChanges` | `requestAnimationFrame` | N/A |
89-
| `"noop"` || - `noop` | `requestAnimationFrame` | N/A |
84+
| Name | Priority | Render Method | Scheduling | Render Deadline |
85+
|-------------------------| -------- | ----------------- | ----------------------- | --------------- |
86+
| `"native"` ||`markForCheck` | `requestAnimationFrame` | N/A |
87+
| `"global"` - _deprecated_ ||`ɵmarkDirty` | `requestAnimationFrame` | N/A |
88+
| `"local"` || 🠗 `detectChanges` | `requestAnimationFrame` | N/A |
89+
| `"noop"` || - `noop` | `requestAnimationFrame` | N/A |
9090

9191
#### Native
9292

@@ -103,6 +103,9 @@ as the internally called function [`markViewDirty`](https://github.com/angular/a
103103

104104
#### Global Strategy
105105

106+
> **deprecated**
107+
> angular [drops support](https://github.com/angular/angular/pull/46806) for `ɵmarkDirty`
108+
106109
This strategy leverages Angular's internal [`ɵmarkDirty`](https://github.com/angular/angular/blob/930eeaf177a4c277f437f42314605ff8dc56fc82/packages/core/src/render3/instructions/change_detection.ts#L36) render method.
107110
It acts identical to [`ChangeDetectorRef#markForCheck`](https://github.com/angular/angular/blob/930eeaf177a4c277f437f42314605ff8dc56fc82/packages/core/src/render3/view_ref.ts#L128) but works also 🚫 zone-less.
108111
`markDirty` in comparison to `markForCheck` also calls [`scheduleTick`](https://github.com/angular/angular/blob/930eeaf177a4c277f437f42314605ff8dc56fc82/packages/core/src/render3/instructions/shared.ts#L1863) which is the reason why it also works in 🚫 zone-less environments.

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ export type RxCustomStrategyCredentials<T extends string> = Record<
3030
T,
3131
RxStrategyCredentials
3232
>;
33-
export type RxNativeStrategyNames = 'native' | 'local' | 'global' | 'noop';
33+
/**
34+
* @deprecated
35+
* angular drops the internal markDirty API, will fall back to native if used
36+
*/
37+
export type RxGlobalStrategyName = 'global';
38+
export type RxNativeStrategyNames =
39+
| 'native'
40+
| 'local'
41+
| 'noop'
42+
| RxGlobalStrategyName;
3443
export type RxConcurrentStrategyNames =
3544
| 'immediate'
3645
| 'userBlocking'

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ɵmarkDirty as markDirty } from '@angular/core';
1+
import { NgZone } from '@angular/core';
22
import { Observable } from 'rxjs';
33
import { tap } from 'rxjs/operators';
44
import { coalesceWith } from '@rx-angular/cdk/coalescing';
@@ -36,15 +36,6 @@ const localCredentials: RxStrategyCredentials = {
3636
),
3737
};
3838

39-
const globalCredentials: RxStrategyCredentials = {
40-
name: 'global',
41-
work: (_, context) => markDirty(context),
42-
behavior:
43-
({ work, ngZone }) =>
44-
(o$) =>
45-
o$.pipe(tap(() => (ngZone ? ngZone.run(() => work()) : work()))),
46-
};
47-
4839
const noopCredentials: RxStrategyCredentials = {
4940
name: 'noop',
5041
work: () => void 0,
@@ -57,7 +48,22 @@ const nativeCredentials: RxStrategyCredentials = {
5748
behavior:
5849
({ work, ngZone }) =>
5950
(o$) =>
60-
o$.pipe(tap(() => (ngZone ? ngZone.run(() => work()) : work()))),
51+
o$.pipe(
52+
tap(() =>
53+
ngZone && !NgZone.isInAngularZone()
54+
? ngZone.run(() => work())
55+
: work()
56+
)
57+
),
58+
};
59+
60+
/**
61+
* @deprecated
62+
* angular drops the internal markDirty API, will fall back to native if used
63+
*/
64+
const globalCredentials: RxStrategyCredentials = {
65+
...nativeCredentials,
66+
name: 'global',
6167
};
6268

6369
export type RxNativeStrategies =

0 commit comments

Comments
 (0)