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

Commit e02bab6

Browse files
vicbchirayuk
authored andcommitted
fix(watch_group): fix for NaN !== NaN
closes #1139 Closes #1146
1 parent b5aa423 commit e02bab6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/change_detection/watch_group.dart

+2
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ class _EvalWatchRecord implements WatchRecord<_Handler> {
871871
if (value is String && current is String && value == current) {
872872
// it is really the same, recover and save so next time identity is same
873873
current = value;
874+
} else if (value is num && value.isNaN && current is num && current.isNaN) {
875+
// we need this for the compiled JavaScript since in JS NaN !== NaN.
874876
} else {
875877
previousValue = current;
876878
currentValue = value;

test/change_detection/watch_group_spec.dart

+21
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,27 @@ void main() {
528528
expect(logger).toEqual([]);
529529
});
530530

531+
it('should ignore NaN != NaN', () {
532+
watchGrp.watch(new ClosureAST('NaN', () => double.NAN, []), (_, __) => logger('NaN'));
533+
534+
watchGrp.detectChanges();
535+
expect(logger).toEqual(['NaN']);
536+
537+
logger.clear();
538+
watchGrp.detectChanges();
539+
expect(logger).toEqual([]);
540+
}) ;
541+
542+
it('should test string by value', () {
543+
watchGrp.watch(new ClosureAST('String', () => 'value', []), (v, _) => logger(v));
544+
545+
watchGrp.detectChanges();
546+
expect(logger).toEqual(['value']);
547+
548+
logger.clear();
549+
watchGrp.detectChanges();
550+
expect(logger).toEqual([]);
551+
});
531552

532553
it('should eval method', () {
533554
var obj = new MyClass(logger);

0 commit comments

Comments
 (0)