From e02bab6cb9bffea2c4ae22a7ea624eac42aefec5 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 11 Jun 2014 23:57:44 +0200 Subject: [PATCH] fix(watch_group): fix for NaN !== NaN closes #1139 Closes #1146 --- lib/change_detection/watch_group.dart | 2 ++ test/change_detection/watch_group_spec.dart | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/change_detection/watch_group.dart b/lib/change_detection/watch_group.dart index 2be94c1a7..49e3e7360 100644 --- a/lib/change_detection/watch_group.dart +++ b/lib/change_detection/watch_group.dart @@ -871,6 +871,8 @@ class _EvalWatchRecord implements WatchRecord<_Handler> { if (value is String && current is String && value == current) { // it is really the same, recover and save so next time identity is same current = value; + } else if (value is num && value.isNaN && current is num && current.isNaN) { + // we need this for the compiled JavaScript since in JS NaN !== NaN. } else { previousValue = current; currentValue = value; diff --git a/test/change_detection/watch_group_spec.dart b/test/change_detection/watch_group_spec.dart index ba5dcdfbd..9614fac80 100644 --- a/test/change_detection/watch_group_spec.dart +++ b/test/change_detection/watch_group_spec.dart @@ -528,6 +528,27 @@ void main() { expect(logger).toEqual([]); }); + it('should ignore NaN != NaN', () { + watchGrp.watch(new ClosureAST('NaN', () => double.NAN, []), (_, __) => logger('NaN')); + + watchGrp.detectChanges(); + expect(logger).toEqual(['NaN']); + + logger.clear(); + watchGrp.detectChanges(); + expect(logger).toEqual([]); + }) ; + + it('should test string by value', () { + watchGrp.watch(new ClosureAST('String', () => 'value', []), (v, _) => logger(v)); + + watchGrp.detectChanges(); + expect(logger).toEqual(['value']); + + logger.clear(); + watchGrp.detectChanges(); + expect(logger).toEqual([]); + }); it('should eval method', () { var obj = new MyClass(logger);