fix(ivy): unify checkNoChanges logic with the view engine (#28366)
This commit unifies handling of the "check no changes" mode between ngIvy and the view engine. More specifically: - check no changes can be invoked before change detection in ivy; - `undefined` values are considered equal `NO_CHANGES` for the "check no changes" mode purposes. Chanes in this commit enables several tests that were previously running only in ivy or only in the view engine. PR Close #28366
This commit is contained in:

committed by
Jason Aden

parent
3d5a919ac5
commit
99886bd159
@ -7,11 +7,10 @@
|
||||
*/
|
||||
|
||||
import {devModeEqual} from '../change_detection/change_detection_util';
|
||||
|
||||
import {assertDataInRange, assertLessThan, assertNotEqual} from '../util/assert';
|
||||
import {throwErrorIfNoChangesMode} from './errors';
|
||||
import {BINDING_INDEX, LView} from './interfaces/view';
|
||||
import {getCheckNoChangesMode, isCreationMode} from './state';
|
||||
import {LView} from './interfaces/view';
|
||||
import {getCheckNoChangesMode} from './state';
|
||||
import {NO_CHANGE} from './tokens';
|
||||
import {isDifferent} from './util';
|
||||
|
||||
@ -38,20 +37,21 @@ export function bindingUpdated(lView: LView, bindingIndex: number, value: any):
|
||||
ngDevMode &&
|
||||
assertLessThan(bindingIndex, lView.length, `Slot should have been initialized to NO_CHANGE`);
|
||||
|
||||
if (lView[bindingIndex] === NO_CHANGE) {
|
||||
// initial pass
|
||||
lView[bindingIndex] = value;
|
||||
} else if (isDifferent(lView[bindingIndex], value)) {
|
||||
const oldValue = lView[bindingIndex];
|
||||
if (isDifferent(oldValue, value)) {
|
||||
if (ngDevMode && getCheckNoChangesMode()) {
|
||||
if (!devModeEqual(lView[bindingIndex], value)) {
|
||||
throwErrorIfNoChangesMode(isCreationMode(lView), lView[bindingIndex], value);
|
||||
// View engine didn't report undefined values as changed on the first checkNoChanges pass
|
||||
// (before the change detection was run).
|
||||
const oldValueToCompare = oldValue !== NO_CHANGE ? oldValue : undefined;
|
||||
if (!devModeEqual(oldValueToCompare, value)) {
|
||||
throwErrorIfNoChangesMode(oldValue === NO_CHANGE, oldValueToCompare, value);
|
||||
}
|
||||
}
|
||||
lView[bindingIndex] = value;
|
||||
} else {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Updates 2 bindings if changed, then returns whether either was updated. */
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {assertDataInRange, assertDefined, assertGreaterThan, assertLessThan} from '../util/assert';
|
||||
import {global} from '../util/global';
|
||||
|
||||
import {ACTIVE_INDEX, LCONTAINER_LENGTH, LContainer} from './interfaces/container';
|
||||
import {LCONTAINER_LENGTH, LContainer} from './interfaces/container';
|
||||
import {LContext, MONKEY_PATCH_KEY_NAME} from './interfaces/context';
|
||||
import {ComponentDef, DirectiveDef} from './interfaces/definition';
|
||||
import {NO_PARENT_INJECTOR, RelativeInjectorLocation, RelativeInjectorLocationFlags} from './interfaces/injector';
|
||||
|
Reference in New Issue
Block a user