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

fix(watch_group): fix for NaN !== NaN #1146

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/change_detection/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/change_detection/watch_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions test/change_detection/watch_group_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down