Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Entangle Errors.errorsFor properly
We recently made some changes to the way arrays get consumed when autotracking in Ember - specifically, whenever an array is return from `Ember.get`, `@computed`, or `@tracked`, we track that array for changes in the future. Previously, we also tracked it if it was an _EmberArray_. This check was a bit redundant, and costly, so we removed it and now only do it for native arrays. The reason this is generally safe is that non-native EmberArrays usually have a contract - you must access the state of the array via `objectAt`, and you must update via `pushObject`, `popObject`, etc. The array is consumed when using `objectAt`, so theres no need to do it eagerly in `Ember.get` (and penalize all other object access). The `Errors` class is a bit of a special case, because it adds additonal capabilities - the `errorsFor` method, which returns a subset of errors in the array. This info is accessed via the `errorsFor()` method, which does not consume the array proxy at all. So, previously, if a user did something like: ```js model.errors.errorsFor(field).map(error => error.message); ``` When `model.errors` was accessed, it was a `@computed` property, and it consumed the entire array proxy. Later on, when the user goes to add an error, it adds the error to the main array _and_ the subarray returned by `errorsFor()`, and dirties both, so the user's code is called again and updates properly. With the recent changes, that doesn't happen anymore. Since `errorsFor` returns a native array (with prototype extensions enabled), `map` does not use `objectAt` internally either. So, there is nothing that is properly consuming the array. This PR adds the consumption manually. In the future, we can likely add a primitive that allows Errors to create and manually manage tags, or it can use something along the lines of a TrackedArray for these errors instead.
- Loading branch information