You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/docs/template/rx-for-directive.mdx
+130-5Lines changed: 130 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ title: 'RxFor'
6
6
7
7
importTabsfrom'@theme/Tabs';
8
8
importTabItemfrom'@theme/TabItem';
9
+
importReactPlayerfrom'react-player';
9
10
10
11
## Motivation
11
12
@@ -46,13 +47,17 @@ Each instance of `RxFor` can be configured to render with different settings.
46
47
47
48
<TabItemvalue="signal"label="Usage with signals">
48
49
50
+
:::info
51
+
You don't need to unwrap the signal, just pass its reference to `rxFor`, it'll do the rest for you.
52
+
:::
53
+
49
54
```html title="src/list.component.html"
50
55
<divclass="movie-list">
51
56
<movie*rxFor="let movie of movies;"[movie]="movie" />
52
57
</div>
53
58
```
54
59
55
-
```typescript title="src/list.component.html"
60
+
```typescript title="src/list.component.ts"
56
61
import { RxFor } from'@rx-angular/template/for';
57
62
import { Component } from'@angular/core';
58
63
@@ -76,7 +81,7 @@ export class ListComponent {
76
81
</div>
77
82
```
78
83
79
-
```typescript title="src/list.component.html"
84
+
```typescript title="src/list.component.ts"
80
85
import { RxFor } from'@rx-angular/template/for';
81
86
import { Component } from'@angular/core';
82
87
@@ -105,7 +110,7 @@ export class ListComponent {
105
110
</div>
106
111
```
107
112
108
-
```typescript title="src/list.component.html"
113
+
```typescript title="src/list.component.ts"
109
114
import { RxFor } from'@rx-angular/template/for';
110
115
import { Component } from'@angular/core';
111
116
@@ -167,7 +172,7 @@ You can pass any valid property from the given input type as a shortcut instead
167
172
</div>
168
173
```
169
174
170
-
```typescript title="src/list.component.html"
175
+
```typescript title="src/list.component.ts"
171
176
import { RxFor } from'@rx-angular/template/for';
172
177
import { Component } from'@angular/core';
173
178
@@ -191,7 +196,7 @@ export class ListComponent {
191
196
</div>
192
197
```
193
198
194
-
```typescript title="src/list.component.html"
199
+
```typescript title="src/list.component.ts"
195
200
import { RxFor } from'@rx-angular/template/for';
196
201
import { Component } from'@angular/core';
197
202
@@ -330,6 +335,126 @@ The following context variables are available for each template:
330
335
|`odd$`|`Observable<boolean>`| odd as `Observable`|
331
336
|`select`|`(keys: (keyof T)[], distinctByMap) => Observable<Partial<T>>`| returns a selection function which accepts an array of properties to pluck out of every list item. The function returns the selected properties of the current list item as distinct `Observable` key-value-pair. |
332
337
338
+
## Use the new reconciliation algorithm
339
+
340
+
You can opt in to use the new reconciliation algorithm, which was shipped by the
341
+
angular team as part of the new `@for` control flow.
342
+
343
+
The original implementations can be found [here](https://github.com/angular/angular/blob/main/packages/core/src/render3/list_reconciliation.ts) & [here](https://github.com/angular/angular/blob/f8d22a9ba4e426f14f9c7fd608e1ad752cd44eb5/packages/core/src/render3/instructions/control_flow.ts#L281)
344
+
345
+
By default, `rxFor` uses the `IterableDiffer` to calculate the operations it needs to apply
In general, the new reconciliation algorithm diffs two lists with fewer operations to achieve the same goal as the legacy `IterableDiffer` approach. However, this only applies for move / swap operations.
382
+
383
+
It's also more memory efficient than the iterable differ.
384
+
385
+
For `rxFor` specifically, there are also **behavioral impacts**.
386
+
Instead of actually moving around DOM, the new reconciliation works by `detaching` & `attaching` views.
387
+
As rxFor by default uses the concurrent mode, it splits each individual task (attach, detach, update, remove) and works them off in a queue.
388
+
As we are operating on the DOM, we have to run tasks in the given order.
389
+
The biggest impact is that you'll visually see views disappearing from the screen when the whole data set is being shuffled around.
390
+
391
+
This leads to visual instability on the one hand, but also makes sure no view is ever in the wrong position as in the legacy approach.
392
+
393
+
#### Swap
394
+
395
+
Swapping the first item with the last item. This shows off the advantages of the new reconciliation in the most impressive way.
396
+
397
+
<Tabs>
398
+
<TabItemvalue="experimental-swap"label="Sw
F438
ap new reconciliation">
399
+
400
+
The new reconciliation algorithm only needs 4 operations (detach x2, attach x2) to achieve the end result.
0 commit comments