Skip to content

Commit

Permalink
[BUGFIX beta] computed.sort array should update if sort properties ar…
Browse files Browse the repository at this point in the history
…ray is empty
  • Loading branch information
miguelcobain committed May 13, 2018
1 parent d5a9092 commit 6f33b19
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/@ember/object/lib/computed/reduce_computed_macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,17 @@ function propertySort(itemsKey, sortPropertiesKey) {

let itemsKeyIsAtThis = itemsKey === '@this';
let normalizedSortProperties = normalizeSortProperties(sortProperties);
activeObservers = normalizedSortProperties.map(([prop]) => {
let path = itemsKeyIsAtThis ? `@each.${prop}` : `${itemsKey}.@each.${prop}`;
if (normalizedSortProperties.length === 0) {
let path = itemsKeyIsAtThis ? `[]` : `${itemsKey}.[]`;
addObserver(this, path, sortPropertyDidChange);
return [this, path, sortPropertyDidChange];
});
activeObservers = [[this, path, sortPropertyDidChange]];
} else {
activeObservers = normalizedSortProperties.map(([prop]) => {
let path = itemsKeyIsAtThis ? `@each.${prop}` : `${itemsKey}.@each.${prop}`;
addObserver(this, path, sortPropertyDidChange);
return [this, path, sortPropertyDidChange];
});
}

activeObserversMap.set(this, activeObservers);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,29 @@ moduleFor(
);
}

['@test array should update if sort properties array is empty'](assert) {
var o = EmberObject.extend({
sortedItems: sort('items', 'itemSorting'),
}).create({
itemSorting: emberA([]),
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'
);

set(o, 'items', emberA([5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4]));

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

['@test array observers do not leak'](assert) {
let daria = { name: 'Daria' };
let jane = { name: 'Jane' };
Expand Down

0 comments on commit 6f33b19

Please sign in to comment.