8
8
Injector ,
9
9
Input ,
10
10
isSignal ,
11
- IterableDiffers ,
12
11
NgIterable ,
13
12
NgZone ,
14
13
OnDestroy ,
@@ -27,11 +26,7 @@ import {
27
26
RxStrategyNames ,
28
27
RxStrategyProvider ,
29
28
} from '@rx-angular/cdk/render-strategies' ;
30
- import {
31
- createListTemplateManager ,
32
- RxListManager ,
33
- RxListViewComputedContext ,
34
- } from '@rx-angular/cdk/template' ;
29
+ import { RxListViewComputedContext } from '@rx-angular/cdk/template' ;
35
30
import {
36
31
isObservable ,
37
32
Observable ,
@@ -41,6 +36,7 @@ import {
41
36
} from 'rxjs' ;
42
37
import { shareReplay , switchAll } from 'rxjs/operators' ;
43
38
import { RxForViewContext } from './for-view-context' ;
39
+ import { injectReconciler } from './inject-reconciler' ;
44
40
45
41
/**
46
42
* @description Will be provided through Terser global definitions by Angular CLI
@@ -84,8 +80,6 @@ declare const ngDevMode: boolean;
84
80
export class RxFor < T , U extends NgIterable < T > = NgIterable < T > >
85
81
implements OnInit , DoCheck , OnDestroy
86
82
{
87
- /** @internal */
88
- private iterableDiffers = inject ( IterableDiffers ) ;
89
83
/** @internal */
90
84
private cdRef = inject ( ChangeDetectorRef ) ;
91
85
/** @internal */
@@ -162,7 +156,8 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
162
156
* @description
163
157
*
164
158
* You can change the used `RenderStrategy` by using the `strategy` input of the `*rxFor`. It accepts
165
- * an `Observable<RxStrategyNames>` or [`RxStrategyNames`](https://github.com/rx-angular/rx-angular/blob/b0630f69017cc1871d093e976006066d5f2005b9/libs/cdk/render-strategies/src/lib/model.ts#L52).
159
+ * an `Observable<RxStrategyNames>` or
160
+ * [`RxStrategyNames`](https://github.com/rx-angular/rx-angular/blob/b0630f69017cc1871d093e976006066d5f2005b9/libs/cdk/render-strategies/src/lib/model.ts#L52).
166
161
*
167
162
* The default value for strategy is
168
163
* [`normal`](https://www.rx-angular.io/docs/template/cdk/render-strategies/strategies/concurrent-strategies).
@@ -215,7 +210,8 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
215
210
* - `@ContentChildren`
216
211
*
217
212
* Read more about this in the
218
- * [official docs](https://www.rx-angular.io/docs/template/rx-for-directive#local-strategies-and-view-content-queries-parent).
213
+ * [official
214
+ * docs](https://www.rx-angular.io/docs/template/rx-for-directive#local-strategies-and-view-content-queries-parent).
219
215
*
220
216
* @example
221
217
* \@Component({
@@ -240,7 +236,8 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
240
236
*
241
237
* @param {boolean } renderParent
242
238
*
243
- * @deprecated this flag will be dropped soon, as it is no longer required when using signal based view & content queries
239
+ * @deprecated this flag will be dropped soon, as it is no longer required when using signal based view & content
240
+ * queries
244
241
*/
245
242
@Input ( 'rxForParent' ) renderParent = this . strategyProvider . config . parent ;
246
243
@@ -253,7 +250,8 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
253
250
* Event listeners normally trigger zone. Especially high frequently events cause performance issues.
254
251
*
255
252
* Read more about this in the
256
- * [official docs](https://www.rx-angular.io/docs/template/rx-for-directive#working-with-event-listeners-patchzone).
253
+ * [official
254
+ * docs](https://www.rx-angular.io/docs/template/rx-for-directive#working-with-event-listeners-patchzone).
257
255
*
258
256
* @example
259
257
* \@Component({
@@ -280,6 +278,8 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
280
278
*/
281
279
@Input ( 'rxForPatchZone' ) patchZone = this . strategyProvider . config . patchZone ;
282
280
281
+ private defaultTrackBy : TrackByFunction < unknown > = ( i , item ) => item ;
282
+
283
283
/**
284
284
* @description
285
285
* A function or key that defines how to track changes for items in the iterable.
@@ -352,7 +352,7 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
352
352
) ;
353
353
}
354
354
if ( trackByFnOrKey == null ) {
355
- this . _trackBy = null ;
355
+ this . _trackBy = this . defaultTrackBy ;
356
356
} else {
357
357
this . _trackBy =
358
358
typeof trackByFnOrKey !== 'function'
@@ -436,47 +436,38 @@ export class RxFor<T, U extends NgIterable<T> = NgIterable<T>>
436
436
/** @internal */
437
437
private readonly strategy$ = this . strategyInput$ . pipe ( coerceDistinctWith ( ) ) ;
438
438
439
- /** @internal */
440
- private listManager : RxListManager < T > ;
441
-
442
439
/** @internal */
443
440
private _subscription = new Subscription ( ) ;
444
441
445
442
/** @internal */
446
- _trackBy : TrackByFunction < T > ;
443
+ _trackBy : TrackByFunction < T > = this . defaultTrackBy ;
447
444
/** @internal */
448
445
_distinctBy = ( a : T , b : T ) => a === b ;
449
446
447
+ private reconciler = injectReconciler ( ) ;
448
+
450
449
constructor (
451
450
private readonly templateRef : TemplateRef < RxForViewContext < T , U > > ,
452
451
) { }
453
452
454
453
/** @internal */
455
454
ngOnInit ( ) {
456
455
this . _subscription . add ( this . values$ . subscribe ( ( v ) => ( this . values = v ) ) ) ;
457
- this . listManager = createListTemplateManager < T , RxForViewContext < T > > ( {
458
- iterableDiffers : this . iterableDiffers ,
459
- renderSettings : {
460
- cdRef : this . cdRef ,
461
- strategies : this . strategyProvider . strategies as any , // TODO: move strategyProvider
462
- defaultStrategyName : this . strategyProvider . primaryStrategy ,
463
- parent : ! ! this . renderParent ,
464
- patchZone : this . patchZone ? this . ngZone : false ,
465
- errorHandler : this . errorHandler ,
466
- } ,
467
- templateSettings : {
456
+ this . _subscription . add (
457
+ this . reconciler ( {
458
+ values$ : this . values$ ,
459
+ strategy$ : this . strategy$ ,
468
460
viewContainerRef : this . viewContainerRef ,
469
- templateRef : this . template ,
461
+ template : this . template ,
462
+ strategyProvider : this . strategyProvider ,
463
+ errorHandler : this . errorHandler ,
464
+ cdRef : this . cdRef ,
465
+ trackBy : this . _trackBy ,
470
466
createViewContext : this . createViewContext . bind ( this ) ,
471
467
updateViewContext : this . updateViewContext . bind ( this ) ,
472
- } ,
473
- trackBy : this . _trackBy ,
474
- } ) ;
475
- this . listManager . nextStrategy ( this . strategy$ ) ;
476
- this . _subscription . add (
477
- this . listManager
478
- . render ( this . values$ )
479
- . subscribe ( ( v ) => this . _renderCallback ?. next ( v ) ) ,
468
+ parent : ! ! this . renderParent ,
469
+ patchZone : this . patchZone ? this . ngZone : undefined ,
470
+ } ) . subscribe ( ( values ) => this . _renderCallback ?. next ( values ) ) ,
480
471
) ;
481
472
}
482
473
0 commit comments