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

Fix for issue with Em.computed.sort observers #11220

Merged
merged 2 commits into from
May 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/ember-runtime/lib/computed/reduce_computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,13 @@ function ReduceComputedProperty(options) {
var previousDependentArray = meta.dependentArrays[dependentKey];

if (dependentArray === previousDependentArray) {

// The array may be the same, but our item property keys may have
// changed, so we set them up again. We can't easily tell if they've
// changed: the array may be the same object, but with different
// contents.
if (cp._previousItemPropertyKeys[dependentKey]) {
meta.dependentArraysObserver.teardownPropertyObservers(dependentKey, cp._previousItemPropertyKeys[dependentKey]);
delete cp._previousItemPropertyKeys[dependentKey];
meta.dependentArraysObserver.setupPropertyObservers(dependentKey, cp._itemPropertyKeys[dependentKey]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,34 @@ QUnit.module('computedSort - sortProperties', {

commonSortTests();

QUnit.test("updating sort properties detaches observers for old sort properties", function() {
var objectToRemove = get(obj, 'items').objectAt(3);

run(function() {
sorted = get(obj, 'sortedItems');
});

deepEqual(sorted.mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], "precond - array is initially sorted");

run(function() {
set(obj, 'itemSorting', Ember.A(['fname:desc']));
});

deepEqual(sorted.mapBy('fname'), ['Robb', 'Jaime', 'Cersei', 'Bran'], "after updating sort properties array is updated");

run(function() {
get(obj, 'items').removeObject(objectToRemove);
});

deepEqual(sorted.mapBy('fname'), ['Robb', 'Jaime', 'Cersei'], "after removing item array is updated");

run(function() {
set(objectToRemove, 'lname', 'Updated-Stark');
});

deepEqual(sorted.mapBy('fname'), ['Robb', 'Jaime', 'Cersei'], "after changing removed item array is not updated");
});

QUnit.test("updating sort properties updates the sorted array", function() {
run(function() {
sorted = get(obj, 'sortedItems');
Expand Down