Skip to content

Commit

Permalink
fix(array-observation): handle push then sort
Browse files Browse the repository at this point in the history
Flush any existing changeRecords prior to enqueuing a collection reset

Fixes #233
  • Loading branch information
jdanyow committed Dec 7, 2015
1 parent 83f0f53 commit 2ae6d0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/array-observation.js
Expand Up @@ -40,6 +40,7 @@ class ModifyArrayObserver extends ModifyCollectionObserver {
}

array['reverse'] = function(){
observer.flushChangeRecords();
var oldArray = array.slice();
var methodCallResult = arrayProto['reverse'].apply(array, arguments);
observer.reset(oldArray);
Expand All @@ -58,6 +59,7 @@ class ModifyArrayObserver extends ModifyCollectionObserver {
};

array['sort'] = function() {
observer.flushChangeRecords();
var oldArray = array.slice();
var methodCallResult = arrayProto['sort'].apply(array, arguments);
observer.reset(oldArray);
Expand Down
6 changes: 6 additions & 0 deletions src/collection-observation.js
Expand Up @@ -52,6 +52,12 @@ export class ModifyCollectionObserver {
}
}

flushChangeRecords() {
if ((this.changeRecords && this.changeRecords.length) || this.oldCollection) {
this.call();
}
}

reset(oldCollection) {
this.oldCollection = oldCollection;

Expand Down

0 comments on commit 2ae6d0e

Please sign in to comment.