JavaScript

JavaScript

Made by DeepSource

Avoid using @each in deeply nested computed property JS-0780

Performance
Minor
ember

Ember does not allow deeply-nested computed property dependent keys with @each. At runtime, it will show a warning about this.

You should use @each only one level deep otherwise it will create a complex equation and effect your application performance.

Bad Practice

export default Component.extend({
  displayNames: computed('[email protected]', function () {
    return this.todos.map((todo) => todo.owner.name);
  })
});

Recommended

export default Component.extend({
  displayNames: computed('[email protected]', function () {
    return this.owners.mapBy('name');
  }),

  owners: computed('[email protected]', function () {
    return this.todos.mapBy('owner');
  })
});