fix(ChangeDetector): support for NaN

Closes #4853
This commit is contained in:
Victor Berchet
2015-10-21 13:49:52 -07:00
parent 758062807a
commit 1316c3e391
8 changed files with 43 additions and 26 deletions

View File

@ -284,7 +284,7 @@ export class ChangeDetectorJITGenerator {
var condition = `!${pipe}.pure || (${contexOrArgCheck.join(" || ")})`;
var check = `
if (${oldValue} !== ${newValue}) {
if (${this.changeDetectionUtilVarName}.looseNotIdentical(${oldValue}, ${newValue})) {
${newValue} = ${this.changeDetectionUtilVarName}.unwrapValue(${newValue})
${this._genChangeMarker(r)}
${this._genUpdateDirectiveOrElement(r)}
@ -311,7 +311,7 @@ export class ChangeDetectorJITGenerator {
`;
var check = `
if (${newValue} !== ${oldValue}) {
if (${this.changeDetectionUtilVarName}.looseNotIdentical(${oldValue}, ${newValue})) {
${this._genChangeMarker(r)}
${this._genUpdateDirectiveOrElement(r)}
${this._genAddToChanges(r)}

View File

@ -1,4 +1,11 @@
import {CONST_EXPR, isPresent, isBlank, Type, StringWrapper} from 'angular2/src/core/facade/lang';
import {
CONST_EXPR,
isPresent,
isBlank,
Type,
StringWrapper,
looseIdentical
} from 'angular2/src/core/facade/lang';
import {BaseException} from 'angular2/src/core/facade/exceptions';
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {ProtoRecord} from './proto_record';
@ -202,4 +209,6 @@ export class ChangeDetectionUtil {
static directiveIndex(elementIndex: number, directiveIndex: number): DirectiveIndex {
return new DirectiveIndex(elementIndex, directiveIndex);
}
static looseNotIdentical(a: any, b: any): boolean { return !looseIdentical(a, b); }
}

View File

@ -1,4 +1,4 @@
import {isPresent, isBlank, looseIdentical} from 'angular2/src/core/facade/lang';
import {isPresent, isBlank, looseIdentical, StringWrapper} from 'angular2/src/core/facade/lang';
import {ListWrapper, Map} from 'angular2/src/core/facade/collection';
import {RecordType, ProtoRecord} from './proto_record';
@ -52,7 +52,7 @@ function _findMatching(r: ProtoRecord, rs: ProtoRecord[]) {
return ListWrapper.find(
rs, (rr) => rr.mode !== RecordType.DirectiveLifecycle && _sameDirIndex(rr, r) &&
rr.mode === r.mode && looseIdentical(rr.funcOrValue, r.funcOrValue) &&
rr.contextIndex === r.contextIndex && looseIdentical(rr.name, r.name) &&
rr.contextIndex === r.contextIndex && StringWrapper.equals(rr.name, r.name) &&
ListWrapper.equals(rr.args, r.args));
}

View File

@ -245,7 +245,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
if (proto.shouldBeChecked()) {
var prevValue = this._readSelf(proto, values);
if (!isSame(prevValue, currValue)) {
if (ChangeDetectionUtil.looseNotIdentical(prevValue, currValue)) {
if (proto.lastInBinding) {
var change = ChangeDetectionUtil.simpleChange(prevValue, currValue);
if (throwOnChange) this.throwOnChangeError(prevValue, currValue);
@ -348,7 +348,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
if (proto.shouldBeChecked()) {
var prevValue = this._readSelf(proto, values);
if (!isSame(prevValue, currValue)) {
if (ChangeDetectionUtil.looseNotIdentical(prevValue, currValue)) {
currValue = ChangeDetectionUtil.unwrapValue(currValue);
if (proto.lastInBinding) {
@ -443,10 +443,3 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
return res;
}
}
function isSame(a, b): boolean {
if (a === b) return true;
if (a instanceof String && b instanceof String && a == b) return true;
if ((a !== a) && (b !== b)) return true;
return false;
}

View File

@ -49,8 +49,3 @@ class PregenProtoChangeDetector extends ProtoChangeDetector {
@override
instantiate(dynamic dispatcher) => _instantiateMethod(dispatcher);
}
/// Provided as an optimization to cut down on '!' characters in generated
/// change detectors. See https://github.com/angular/angular/issues/3248 for
/// for details.
bool looseNotIdentical(a, b) => !looseIdentical(a, b);