-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9356 from ef4/fix-9278
[BUGFIX beta] fixing broken computed.sort semantics
- Loading branch information
Showing
2 changed files
with
184 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -770,7 +770,7 @@ function commonSortTests() { | |
deepEqual(sorted.mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], "sorted array is updated"); | ||
}); | ||
|
||
test("guid sort-order fallback with a serach proxy is not confused by non-search ObjectProxys", function() { | ||
test("guid sort-order fallback with a search proxy is not confused by non-search ObjectProxys", function() { | ||
var tyrion = { fname: "Tyrion", lname: "Lannister" }; | ||
var tyrionInDisguise = ObjectProxy.create({ | ||
fname: "Yollo", | ||
|
@@ -779,9 +779,9 @@ function commonSortTests() { | |
}); | ||
|
||
items = get(obj, 'items'); | ||
sorted = get(obj, 'sortedItems'); | ||
|
||
run(function() { | ||
sorted = get(obj, 'sortedItems'); | ||
items.pushObject(tyrion); | ||
}); | ||
|
||
|
@@ -1103,6 +1103,108 @@ test("changing item properties not specified via @each does not trigger a resort | |
deepEqual(sorted.mapBy('fname'), ['Cersei', 'Jaime', 'Bran', 'Robb'], "updating an unspecified property on an item does not resort it"); | ||
}); | ||
|
||
QUnit.module('computedSort - stability', { | ||
setup: function() { | ||
run(function() { | ||
obj = EmberObject.createWithMixins({ | ||
items: Ember.A(Ember.A([{ | ||
name: "A", count: 1 | ||
}, { | ||
name: "B", count: 1 | ||
}, { | ||
name: "C", count: 1 | ||
}, { | ||
name: "D", count: 1 | ||
}]).map(function(elt){return EmberObject.create(elt);})), | ||
|
||
sortProps: Ember.A(['count', 'name']), | ||
sortedItems: computedSort('items', 'sortProps') | ||
}); | ||
}); | ||
}, | ||
teardown: function() { | ||
run(function() { | ||
obj.destroy(); | ||
}); | ||
} | ||
}); | ||
|
||
test("sorts correctly as only one property changes", function(){ | ||
var sorted; | ||
run(function() { | ||
sorted = obj.get('sortedItems'); | ||
}); | ||
deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], "initial"); | ||
obj.get('items').objectAt(3).set('count', 2); | ||
run(function() { | ||
sorted = obj.get('sortedItems'); | ||
}); | ||
deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], "final"); | ||
}); | ||
|
||
QUnit.module('computedSort - concurrency', { | ||
setup: function() { | ||
run(function() { | ||
obj = EmberObject.createWithMixins({ | ||
items: Ember.A(Ember.A([{ | ||
name: "A", count: 1 | ||
}, { | ||
name: "B", count: 2 | ||
}, { | ||
name: "C", count: 3 | ||
}, { | ||
name: "D", count: 4 | ||
}]).map(function(elt){return EmberObject.create(elt);})), | ||
|
||
sortProps: Ember.A(['count']), | ||
sortedItems: computedSort('items', 'sortProps'), | ||
customSortedItems: computedSort('[email protected]', function(a,b){ | ||
return get(a, 'count') - get(b, 'count'); | ||
}) | ||
}); | ||
}); | ||
}, | ||
teardown: function() { | ||
run(function() { | ||
obj.destroy(); | ||
}); | ||
} | ||
}); | ||
|
||
test("sorts correctly when there are concurrent changes", function(){ | ||
var sorted; | ||
run(function() { | ||
sorted = obj.get('sortedItems'); | ||
}); | ||
deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], "initial"); | ||
Ember.changeProperties(function(){ | ||
obj.get('items').objectAt(1).set('count', 5); | ||
obj.get('items').objectAt(2).set('count', 6); | ||
}); | ||
run(function() { | ||
sorted = obj.get('sortedItems'); | ||
}); | ||
deepEqual(sorted.mapBy('name'), ['A', 'D', 'B', 'C'], "final"); | ||
}); | ||
|
||
test("sorts correctly with a user-provided comparator when there are concurrent changes", function(){ | ||
var sorted; | ||
run(function() { | ||
sorted = obj.get('customSortedItems'); | ||
}); | ||
deepEqual(sorted.mapBy('name'), ['A', 'B', 'C', 'D'], "initial"); | ||
run(function() { | ||
Ember.changeProperties(function(){ | ||
obj.get('items').objectAt(1).set('count', 5); | ||
obj.get('items').objectAt(2).set('count', 6); | ||
}); | ||
sorted = obj.get('customSortedItems'); | ||
}); | ||
deepEqual(sorted.mapBy('name'), ['A', 'D', 'B', 'C'], "final"); | ||
}); | ||
|
||
|
||
|
||
QUnit.module('computedMax', { | ||
setup: function() { | ||
run(function() { | ||
|
@@ -1311,9 +1413,11 @@ QUnit.module('Ember.arrayComputed - chains', { | |
}); | ||
|
||
test("it can filter and sort when both depend on the same item property", function() { | ||
filtered = get(obj, 'filtered'); | ||
sorted = get(obj, 'sorted'); | ||
todos = get(obj, 'todos'); | ||
run(function(){ | ||
filtered = get(obj, 'filtered'); | ||
sorted = get(obj, 'sorted'); | ||
todos = get(obj, 'todos'); | ||
}); | ||
|
||
deepEqual(todos.mapProperty('name'), ['E', 'D', 'C', 'B', 'A'], "precond - todos initially correct"); | ||
deepEqual(sorted.mapProperty('name'), ['A', 'B', 'C', 'D', 'E'], "precond - sorted initially correct"); | ||
|