Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(change-detector): handle double.NAN for collections (in JS)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored and mhevery committed Feb 20, 2014
1 parent ffe43c6 commit 07f9b24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 11 additions & 5 deletions lib/change_detection/dirty_checking_change_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,17 @@ class _CollectionChangeRecord<V> implements CollectionChangeRecord<V> {
*/
ItemRecord mismatch(ItemRecord record, item, int index) {
// Guard against bogus String changes
if (record != null && item is String && record.item is String &&
record.item == item) {
// this is false change in strings we need to recover, and pretend it is
// the same. We save the value so that next time identity will pass
return record..item = item;
if (record != null) {
if (item is String && record.item is String && record.item == item) {
// this is false change in strings we need to recover, and pretend it is
// the same. We save the value so that next time identity can pass
return record..item = item;
}

if (item is num && item.isNaN && record.item is num && record.item.isNaN){
// we need this for JavaScript since in JS NaN !== NaN.
return record;
}
}

// find the previous record so that we know where to insert after.
Expand Down
10 changes: 8 additions & 2 deletions test/change_detection/dirty_checking_change_detector_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,20 @@ main() => describe('DirtyCheckingChangeDetector', () {

it('should test string by value rather than by reference', () {
var list = ['a', 'boo'];
var record = detector.watch(list, null, 'handler');
detector.collectChanges();
detector..watch(list, null, null)..collectChanges();

list[1] = 'b' + 'oo';

expect(detector.collectChanges()).toEqual(null);
});

it('should ignore [NaN] != [NaN]', () {
var list = [double.NAN];
var record = detector..watch(list, null, null)..collectChanges();

expect(detector.collectChanges()).toEqual(null);
});

it('should remove and add same item', () {
var list = ['a', 'b', 'c'];
var record = detector.watch(list, null, 'handler');
Expand Down

0 comments on commit 07f9b24

Please sign in to comment.