Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Em.computed.sort triggers computed property twice #10133

Closed
catc opened this issue Jan 4, 2015 · 2 comments
Closed

Em.computed.sort triggers computed property twice #10133

catc opened this issue Jan 4, 2015 · 2 comments

Comments

@catc
Copy link

catc commented Jan 4, 2015

I'm having problems with Em.computed.sort which seems to be triggered twice and ends up causing a bunch of other issues in my app.

See my SO question or my jsbin for a simplified version.

Basically, one of the components in my app copies or maps the model, sorts it, slices it, and then loops through the data.

// initial property copied
initial: function(){
    return this.get('model').slice()
}.property('model'),

// sorted
sortProp: ['age:desc'],
sorted: Ember.computed.sort('initial', 'sortProp'),

// slice it and then loop through it - this function runs twice
final:  function(){
    return this.get('sorted').slice(0, 5)
}.property('sorted.[]'),

The issue is that the final() is triggered twice when the model is changed. The first time final() runs, Em.computed.sort is still using data from the old model (which contains 3 items). Only during the second time does Em.computed.sort use the new, updated model data (which contains 4 items).

I'm not sure as to why the sort function runs twice - whether I messed something up or it's actually a bug.

@ahacking
Copy link

ahacking commented Jan 4, 2015

This is a known issue: #9462

@wagenet
Copy link
Member

wagenet commented Jan 26, 2015

Closing in favor of the meta.

@wagenet wagenet closed this as completed Jan 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants