diff --git a/lib/change_detection/ast.dart b/lib/change_detection/ast.dart index 80653a0ba..a18bc5b30 100644 --- a/lib/change_detection/ast.dart +++ b/lib/change_detection/ast.dart @@ -91,8 +91,7 @@ class PureFunctionAST extends AST { /** * SYNTAX: fn(arg0, arg1, ...) * - * Invoke a pure function. Pure means that the function has no state, and - * therefore it needs to be re-computed only if its args change. + * Invoke a (non-pure) function. */ class ClosureAST extends AST { final String name; diff --git a/lib/change_detection/watch_group.dart b/lib/change_detection/watch_group.dart index 884491d06..dd0c1213d 100644 --- a/lib/change_detection/watch_group.dart +++ b/lib/change_detection/watch_group.dart @@ -849,6 +849,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);