How to define an Ember.computed helper that acts on an itemController Ember.ArrayController?

I recently fell in love with Ember.computed helpers. In particular, the abbreviation is computed, for example computed.mapBy .

They work great when used with an contentArrayController.

App.People = Ember.ArrayController.extend({
  //"content" is an array of App.Person objects.
  chosen: Ember.computed.filterBy('content', 'isChosen', true)
})

So, let's say the property isChosendoes not belong to the model person.

Then I could define itemControllerand create a so-called computed property.

App.PeopleController = Ember.ArrayController.extend({
  itemController: 'person',

  chosen: function() {
    return this.filterBy('isChosen', true)
  }.property('@each.isChosen')

}); 

App.PersonController = Ember.ObjectController.extend({
  isChosen: false
});

This works, the computed property chosenreturns an array based on the property personController.isChosen.

But this is not effective because it executes the entire filterBy function every time the child changes. Where as an assistant Em.computed.filterByadds and removes individual objects as needed.

- , Ember.computed , itemController Ember.ArrayController?

+4
1

@this dependentKey itemControllers.

App.PeopleController = Ember.ArrayController.extend({
  itemController: 'person',

  chosen: Ember.computed.filterBy('@this', 'isChosen', true)

}); 

App.PersonController = Ember.ObjectController.extend({
  isChosen: false
});

. sf ember meetup.

+3

Source: https://habr.com/ru/post/1530511/


All Articles