1
- import { InjectionToken } from '@angular/core' ;
1
+ import { InjectionToken , Provider } from '@angular/core' ;
2
2
import { RX_CONCURRENT_STRATEGIES } from './concurrent-strategies' ;
3
3
import {
4
4
RxCustomStrategyCredentials ,
@@ -38,9 +38,7 @@ export function mergeDefaultConfig<T extends string>(
38
38
) : Required < RxRenderStrategiesConfig < T | RxDefaultStrategyNames > > {
39
39
const custom : RxRenderStrategiesConfig < T > = cfg
40
40
? cfg
41
- : ( {
42
- customStrategies : { } ,
43
- } as any ) ;
41
+ : ( { customStrategies : { } } as any ) ;
44
42
return {
45
43
...RX_RENDER_STRATEGIES_DEFAULTS ,
46
44
...custom ,
@@ -50,3 +48,49 @@ export function mergeDefaultConfig<T extends string>(
50
48
} ,
51
49
} ;
52
50
}
51
+
52
+ /**
53
+ * @description
54
+ * Can be used to set the default render strategy or create custom render strategies.
55
+ *
56
+ * With this function you can customize the behavior of:
57
+ * - `rxLet` directive
58
+ * - `rxFor` directive
59
+ * - `rxIf` directive
60
+ * - `rxVirtualFor` directive
61
+ * - `rxVirtualView` directive
62
+ * - `RxStrategyProvider` service.
63
+ *
64
+ * @example
65
+ * import { provideRxRenderStrategies } from '@rx-angular/cdk/render-strategies';
66
+ *
67
+ * const appConfig: ApplicationConfig = {
68
+ * providers: [
69
+ * provideRxRenderStrategies({
70
+ * primaryStrategy: 'sync',
71
+ * customStrategies: {
72
+ * sync: {
73
+ * name: 'sync',
74
+ * work: (cdRef) => { cdRef.detectChanges(); },
75
+ * behavior: ({ work }) => (o$) => o$.pipe(tap(() => work()))
76
+ * },
77
+ * asap: {
78
+ * name: 'asap',
79
+ * work: (cdRef) => { cdRef.detectChanges(); },
80
+ * behavior: ({ work }) => (o$) => o$.pipe(delay(0, asapScheduler), tap(() => work()))
81
+ * },
82
+ * }),
83
+ * ],
84
+ * };
85
+ *
86
+ * @param config - The configuration object.
87
+ * @returns A provider that can be used to set the default render strategy or create custom render strategies.
88
+ */
89
+ export function provideRxRenderStrategies (
90
+ config : RxRenderStrategiesConfig < string > ,
91
+ ) : Provider {
92
+ return {
93
+ provide : RX_RENDER_STRATEGIES_CONFIG ,
94
+ useValue : mergeDefaultConfig ( config ) ,
95
+ } satisfies Provider ;
96
+ }
0 commit comments