fix(core): Add an error state for ChangeDetectors that is set when bindings or lifecycle events throw exceptions and prevents further detection.
- Changes the `alreadyChecked` flag of AbstractChangeDetector to a new `state` flag. - Changes all checks of alreadyChecked to check that the state is NeverChecked. - Set state to Errored if an error is thrown during detection. - Skip change detection for a detector and its children when the state is Errored. - Add a test to validate this fixes issue #4323. Closes #4953
This commit is contained in:
@ -121,7 +121,7 @@ class _CodegenState {
|
||||
|
||||
var names = new CodegenNameUtil(
|
||||
protoRecords, eventBindings, def.directiveRecords, '$genPrefix$_UTIL');
|
||||
var logic = new CodegenLogicUtil(names, '$genPrefix$_UTIL', def.strategy);
|
||||
var logic = new CodegenLogicUtil(names, '$genPrefix$_UTIL', '$genPrefix$_STATE', def.strategy);
|
||||
return new _CodegenState._(
|
||||
genPrefix,
|
||||
def.id,
|
||||
@ -503,7 +503,7 @@ class _CodegenState {
|
||||
|
||||
String _genOnInit(ProtoRecord r) {
|
||||
var br = r.bindingRecord;
|
||||
return 'if (!throwOnChange && !${_names.getAlreadyCheckedName()}) '
|
||||
return 'if (!throwOnChange && ${_names.getStateName()} == ${_genPrefix}$_STATE.NeverChecked) '
|
||||
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.onInit();';
|
||||
}
|
||||
|
||||
@ -539,3 +539,4 @@ const _GEN_PROPERTY_BINDING_TARGETS_NAME =
|
||||
'${_GEN_PREFIX}_propertyBindingTargets';
|
||||
const _GEN_DIRECTIVE_INDICES_NAME = '${_GEN_PREFIX}_directiveIndices';
|
||||
const _UTIL = 'ChangeDetectionUtil';
|
||||
const _STATE = 'ChangeDetectorState';
|
||||
|
Reference in New Issue
Block a user