Skip to content

Instantly share code, notes, and snippets.

@arkadiyk
Last active January 2, 2016 13:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkadiyk/8310248 to your computer and use it in GitHub Desktop.
Save arkadiyk/8310248 to your computer and use it in GitHub Desktop.
Interesting observation on difference between `array.filterBy` and `Ember.Computed.filterBy`

Apparently array.filterBy creates a new array based on the filtered content, whether Ember.Computed.filterBy reuses the same array.

This difference can be very important when you display a filtered list with {{each}} helper.

For eaxample, if you define the propery like this:

  filteredArray: function(){
    return this.get('content').filterBy('isDone', false);
  }.property('content.@each.isDone')

The whole {{each}} block will be rerendered every time the isDone flag of any record is changed.

If you use Ember.computed instead, the only changed records will be rerendered:

  filteredComputed: Ember.computed.filterBy('content','isDone', false)

Here is a quick example : http://jsbin.com/uHOvANoJ/7/edit?html,js,console,output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment