diff --git a/packages/core/src/render3/bindings.ts b/packages/core/src/render3/bindings.ts index 0fe18bc2ee2f7..989c410ba9924 100644 --- a/packages/core/src/render3/bindings.ts +++ b/packages/core/src/render3/bindings.ts @@ -12,8 +12,6 @@ import {throwErrorIfNoChangesMode} from './errors'; import {LView} from './interfaces/view'; import {getCheckNoChangesMode} from './state'; import {NO_CHANGE} from './tokens'; -import {isDifferent} from './util/misc_utils'; - // TODO(misko): consider inlining @@ -36,9 +34,11 @@ export function bindingUpdated(lView: LView, bindingIndex: number, value: any): ngDevMode && assertNotSame(value, NO_CHANGE, 'Incoming value should never be NO_CHANGE.'); ngDevMode && assertLessThan(bindingIndex, lView.length, `Slot should have been initialized to NO_CHANGE`); - const oldValue = lView[bindingIndex]; - if (isDifferent(oldValue, value)) { + + if (Object.is(oldValue, value)) { + return false; + } else { if (ngDevMode && getCheckNoChangesMode()) { // View engine didn't report undefined values as changed on the first checkNoChanges pass // (before the change detection was run). @@ -50,8 +50,6 @@ export function bindingUpdated(lView: LView, bindingIndex: number, value: any): lView[bindingIndex] = value; return true; } - - return false; } /** Updates 2 bindings if changed, then returns whether either was updated. */ diff --git a/packages/core/src/render3/styling_next/util.ts b/packages/core/src/render3/styling_next/util.ts index 209b51f30d24f..2bc267661fb4c 100644 --- a/packages/core/src/render3/styling_next/util.ts +++ b/packages/core/src/render3/styling_next/util.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ import {TNode, TNodeFlags} from '../interfaces/node'; -import {isDifferent} from '../util/misc_utils'; import {StylingMapArray, StylingMapArrayIndex, TStylingConfigFlags, TStylingContext, TStylingContextIndex, TStylingContextPropConfigFlags} from './interfaces'; @@ -160,7 +159,7 @@ export function hasValueChanged( if (compareValueB instanceof String) { compareValueB = compareValueB.toString(); } - return isDifferent(compareValueA, compareValueB); + return !Object.is(compareValueA, compareValueB); } /** diff --git a/packages/core/src/render3/util/misc_utils.ts b/packages/core/src/render3/util/misc_utils.ts index aa7680e3645d6..9ff7eb08c31ff 100644 --- a/packages/core/src/render3/util/misc_utils.ts +++ b/packages/core/src/render3/util/misc_utils.ts @@ -8,18 +8,6 @@ import {global} from '../../util/global'; import {RElement} from '../interfaces/renderer'; -import {NO_CHANGE} from '../tokens'; - -/** - * Returns whether the values are different from a change detection stand point. - * - * Constraints are relaxed in checkNoChanges mode. See `devModeEqual` for details. - */ -export function isDifferent(a: any, b: any): boolean { - // NaN is the only value that is not equal to itself so the first - // test checks if both a and b are not NaN - return !(a !== a && b !== b) && a !== b; -} /** * Used for stringify render output in Ivy. diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index fe2d63d0a026b..59561d7d399e0 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -1010,9 +1010,6 @@ { "name": "isDevMode" }, - { - "name": "isDifferent" - }, { "name": "isFactory" }, diff --git a/packages/core/test/render3/util_spec.ts b/packages/core/test/render3/util_spec.ts deleted file mode 100644 index 5b8673e8bf9b3..0000000000000 --- a/packages/core/test/render3/util_spec.ts +++ /dev/null @@ -1,68 +0,0 @@ -/** - * @license - * Copyright Google Inc. All Rights Reserved. - * - * Use of this source code is governed by an MIT-style license that can be - * found in the LICENSE file at https://angular.io/license - */ - -import {devModeEqual} from '@angular/core/src/change_detection/change_detection_util'; -import {isDifferent} from '../../src/render3/util/misc_utils'; - -describe('util', () => { - - describe('isDifferent', () => { - - describe('checkNoChangeMode = false', () => { - it('should mark non-equal arguments as different', () => { - expect(isDifferent({}, {})).toBeTruthy(); - expect(isDifferent('foo', 'bar')).toBeTruthy(); - expect(isDifferent(0, 1)).toBeTruthy(); - }); - - it('should not mark equal arguments as different', () => { - const obj = {}; - expect(isDifferent(obj, obj)).toBeFalsy(); - expect(isDifferent('foo', 'foo')).toBeFalsy(); - expect(isDifferent(1, 1)).toBeFalsy(); - }); - - it('should not mark NaN as different', () => { expect(isDifferent(NaN, NaN)).toBeFalsy(); }); - - it('should mark NaN with other values as different', () => { - expect(isDifferent(NaN, 'foo')).toBeTruthy(); - expect(isDifferent(5, NaN)).toBeTruthy(); - }); - }); - - describe('checkNoChangeMode = true', () => { - // Assert relaxed constraint in checkNoChangeMode - it('should not mark non-equal arrays, object and function as different', () => { - expect(!devModeEqual([], [])).toBeFalsy(); - expect(!devModeEqual(() => 0, () => 0)).toBeFalsy(); - expect(!devModeEqual({}, {})).toBeFalsy(); - }); - - it('should mark non-equal arguments as different', () => { - expect(!devModeEqual('foo', 'bar')).toBeTruthy(); - expect(!devModeEqual(0, 1)).toBeTruthy(); - }); - - it('should not mark equal arguments as different', () => { - const obj = {}; - expect(isDifferent(obj, obj)).toBeFalsy(); - expect(isDifferent('foo', 'foo')).toBeFalsy(); - expect(isDifferent(1, 1)).toBeFalsy(); - }); - - it('should not mark NaN as different', () => { expect(isDifferent(NaN, NaN)).toBeFalsy(); }); - - it('should mark NaN with other values as different', () => { - expect(isDifferent(NaN, 'foo')).toBeTruthy(); - expect(isDifferent(5, NaN)).toBeTruthy(); - }); - }); - - }); - -});