refactor(change_detect): Move (de)hydrate methods into superclass

Move the implementation of `(de)hydrate`, `hydrated`, and
`detectChangesInRecords` into `AbstractChangeDetector`.

Add comments clarifying the contract between `AbstractChangeDetector`
and its subclasses.

Closes #3245
This commit is contained in:
Tim Blasi
2015-07-29 10:43:07 -07:00
parent 73b7d99dc4
commit 9c19eb906b
6 changed files with 83 additions and 132 deletions

View File

@ -104,22 +104,11 @@ class _CodegenState {
$_changeDetectorTypeName(dispatcher, protos, directiveRecords)
: super(${_encodeValue(_changeDetectorDefId)},
dispatcher, protos, directiveRecords) {
dispatcher, protos, directiveRecords, '$_changeDetectionMode') {
dehydrateDirectives(false);
}
void detectChangesInRecords(throwOnChange) {
if (!hydrated()) {
$_UTIL.throwDehydrated();
}
try {
__detectChangesInRecords(throwOnChange);
} catch (e, s) {
throwError(${_names.getCurrentProtoName()}, e, s);
}
}
void __detectChangesInRecords(throwOnChange) {
void detectChangesInRecordsInternal(throwOnChange) {
${_names.getCurrentProtoName()} = null;
${_names.genInitLocals()}
@ -137,28 +126,10 @@ class _CodegenState {
${_getCallOnAllChangesDoneBody()}
}
void hydrate(
$_contextTypeName context, locals, directives, pipes) {
${_names.getModeName()} = '$_changeDetectionMode';
${_names.getFieldName(CONTEXT_INDEX)} = context;
${_names.getLocalsAccessorName()} = locals;
hydrateDirectives(directives);
${_names.getAlreadyCheckedName()} = false;
${_names.getPipesAccessorName()} = pipes;
}
${_maybeGenHydrateDirectives()}
void dehydrate() {
dehydrateDirectives(true);
${_names.getLocalsAccessorName()} = null;
${_names.getPipesAccessorName()} = null;
}
${_maybeGenDehydrateDirectives()}
hydrated() => ${_names.getFieldName(CONTEXT_INDEX)} != null;
static $_GEN_PREFIX.ProtoChangeDetector
$PROTO_CHANGE_DETECTOR_FACTORY_METHOD(
$_GEN_PREFIX.ChangeDetectorDefinition def) {