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): fix the handling of NaN & string values for maps
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored and mhevery committed Feb 20, 2014
1 parent 07f9b24 commit 156d638
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/change_detection/dirty_checking_change_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,13 @@ class _MapChangeRecord<K, V> implements MapChangeRecord<K, V> {
if (oldSeqRecord != null && key == oldSeqRecord.key) {
newSeqRecord = oldSeqRecord;
if (!identical(value, oldSeqRecord._currentValue)) {
oldSeqRecord._previousValue = oldSeqRecord._currentValue;
var prev = oldSeqRecord._previousValue = oldSeqRecord._currentValue;
oldSeqRecord._currentValue = value;
_addToChanges(oldSeqRecord);
if (!((value is String && prev is String && value == prev) ||
(value is num && value.isNaN && prev is num && prev.isNaN))) {
// Check string by value rather than reference
_addToChanges(oldSeqRecord);
}
}
} else {
seqChanged = true;
Expand Down
25 changes: 25 additions & 0 deletions test/change_detection/dirty_checking_change_detector_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,31 @@ main() => describe('DirtyCheckingChangeDetector', () {
changes: [],
removals: ['a[A -> null]', 'd[D -> null]']));
});

it('should test string keys by value rather than by reference', () {
var map = {'foo': 0};
detector..watch(map, null, null)..collectChanges();

map['f' + 'oo'] = 0;

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

it('should test string values by value rather than by reference', () {
var map = {'foo': 'bar'};
detector..watch(map, null, null)..collectChanges();

map['foo'] = 'b' + 'ar';

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

it('should not see a NaN value as a change', () {
var map = {'foo': double.NAN};
var record = detector..watch(map, null, null)..collectChanges();

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

describe('DuplicateMap', () {
Expand Down

0 comments on commit 156d638

Please sign in to comment.