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

[BUGFIX beta] computed.sort should not sort if sortProperties is empty #16246

Merged
merged 1 commit into from
Feb 15, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,11 @@ function propertySort(itemsKey, sortPropertiesKey) {
let items = itemsKeyIsAtThis ? this : get(this, itemsKey);
if (!isArray(items)) { return emberA(); }

return sortByNormalizedSortProperties(items, normalizedSortProperties);
if (normalizedSortProperties.length === 0) {
return emberA(items.slice());
} else {
return sortByNormalizedSortProperties(items, normalizedSortProperties);
}
}, { dependentKeys: [`${sortPropertiesKey}.[]`], readOnly: true });

cp._activeObserverMap = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,20 @@ QUnit.test('updating an item\'s sort properties does not error when binary searc
], 'array is sorted correctly');
});

QUnit.test('array should not be sorted if sort properties array is empty', function(assert) {
var o = EmberObject.extend({
sortedItems: sort('items', 'itemSorting')
}).create({
itemSorting: emberA([]),
// This bug only manifests when array.sort(() => 0) is not equal to array.
// In order for this to happen, the browser must use an unstable sort and the
// array must be sufficient large. On Chrome, 12 items is currently sufficient.
items: emberA([6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5])
});

assert.deepEqual(o.get('sortedItems'), [6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5], 'array is not changed');
});

QUnit.test('array observers do not leak', function(assert) {
let daria = { name: 'Daria' };
let jane = { name: 'Jane' };
Expand Down