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: content/ember/v6/deprecate-array-proxy.md
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@ until: 7.0.0
4
4
since: 6.5.0
5
5
---
6
6
7
-
`ArrayProxy` is deprecated. In modern Ember, you should use tracked arrays and modern patterns instead. The best replacement depends on how you were using `ArrayProxy`. Some example use cases are shown below.
7
+
8
+
`ArrayProxy` is deprecated. In modern Ember, you should use tracking primitives—such as tracked arrays and tracked properties—whenever possible. This is almost always the best approach going forward. Some of the examples below demonstrate alternatives using proxies or advanced patterns, but these are generally not ideal. You should strongly consider refactoring your code to use tracking if at all possible, as it leads to simpler, more maintainable, and idiomatic Ember code. However, the best replacement depends on how you were using `ArrayProxy`. Some example use cases are shown below.
8
9
9
10
## Recommended: Use Tracked Arrays
10
11
@@ -24,13 +25,15 @@ pets.length; // 4
24
25
25
26
This provides automatic tracking without the complexity of proxies and follows modern Ember patterns.
26
27
28
+
27
29
## Advanced Use Cases
28
30
29
-
If you need more advanced behavior like content swapping or transformation, you can use the approaches below.
31
+
If you need more advanced behavior like content swapping or transformation, you can use the approaches below. However, these patterns are generally not recommended unless you have a strong reason not to use tracked arrays and properties. In most cases, refactoring to use tracking primitives will result in better, more future-proof code.
30
32
31
33
### Swapping Content
32
34
33
-
If you were using `ArrayProxy` to easily swap out the underlying array while keeping a stable reference, you can achieve a similar, transparent effect using a native `Proxy` backed by a class with a `@tracked` property.
35
+
36
+
If you were using `ArrayProxy` to easily swap out the underlying array while keeping a stable reference, you can achieve a similar, transparent effect using a native `Proxy` backed by a class with a `@tracked` property. Again, prefer tracked arrays and properties if you can refactor your code to use them.
34
37
35
38
Before:
36
39
@@ -112,7 +115,8 @@ pets.length; // 2
112
115
113
116
### Transforming Content
114
117
115
-
If you were using `objectAtContent` to transform the array's content, you can use a native JavaScript `Proxy` to achieve the same result with standard array syntax.
118
+
119
+
If you were using `objectAtContent` to transform the array's content, you can use a native JavaScript `Proxy` to achieve the same result with standard array syntax. This is an advanced pattern and should only be used if refactoring to tracked properties is not feasible.
For more complex use cases where you need a native `Proxy` for dynamic behavior:
221
+
222
+
For more complex use cases where you need a native `Proxy` for dynamic behavior, you can use the following pattern. However, this is rarely necessary and should be avoided if you can use tracked properties and computed values instead:
1.**First choice**: Use `TrackedArray` from `tracked-built-ins` for automatic reactivity
264
-
2.**For computed arrays**: Use `@cached` getters with tracked data
265
-
3.**Only if needed**: Use native `Proxy` for complex dynamic behavior that can't be achieved with tracked properties
269
+
1.**First choice (strongly recommended)**: Use `TrackedArray` from `tracked-built-ins`and tracked properties for automatic reactivity and idiomatic Ember code.
270
+
2.**For computed arrays**: Use `@cached` getters with tracked data.
271
+
3.**Only if truly necessary**: Use native `Proxy` for complex dynamic behavior that cannot be achieved with tracked properties. This should be rare.
266
272
267
-
The modern Ember approach favors explicit tracking and computed properties over proxy-based solutions, which are easier to understand, debug, and optimize.
273
+
The modern Ember approach strongly favors explicit tracking and computed properties over proxy-based solutions. Tracking primitives are easier to understand, debug, and optimize, and will be the best choice for almost all use cases going forward.
0 commit comments