refactor(compiler): inline view.contentChildren

This commit is contained in:
Tobias Bosch
2016-10-31 10:31:48 -07:00
committed by vsavkin
parent e5fdf4c70a
commit b3e3cd3add
8 changed files with 38 additions and 36 deletions

View File

@ -98,6 +98,9 @@ export class CompileElement extends CompileNode {
this.view.createMethod.addStmt(statement);
this.appElement = o.THIS_EXPR.prop(fieldName);
this.instances.set(resolveIdentifierToken(Identifiers.AppElement).reference, this.appElement);
if (this.hasViewContainer) {
this.view.viewContainerAppElements.push(this.appElement);
}
}
private _createComponentFactoryResolver() {

View File

@ -32,6 +32,7 @@ export class CompileView implements NameResolver {
public nodes: CompileNode[] = [];
// root nodes or AppElements for ViewContainers
public rootNodesOrAppElements: o.Expression[] = [];
public viewContainerAppElements: o.Expression[] = [];
public createMethod: CompileMethod;
public animationBindingsMethod: CompileMethod;

View File

@ -473,6 +473,8 @@ function createViewClass(
function generateDestroyMethod(view: CompileView): o.Statement[] {
const stmts: o.Statement[] = [];
view.viewContainerAppElements.forEach(
(appElement) => { stmts.push(appElement.callMethod('destroyNestedViews', []).toStmt()); });
view.viewChildren.forEach(
(viewChild) => { stmts.push(viewChild.callMethod('destroy', []).toStmt()); });
stmts.push(...view.destroyMethod.finish());
@ -572,9 +574,11 @@ function generateDetectChangesMethod(view: CompileView): o.Statement[] {
}
stmts.push(...view.animationBindingsMethod.finish());
stmts.push(...view.detectChangesInInputsMethod.finish());
stmts.push(
o.THIS_EXPR.callMethod('detectContentChildrenChanges', [DetectChangesVars.throwOnChange])
.toStmt());
view.viewContainerAppElements.forEach((appElement) => {
stmts.push(
appElement.callMethod('detectChangesInNestedViews', [DetectChangesVars.throwOnChange])
.toStmt());
});
var afterContentStmts = view.updateContentQueriesMethod.finish().concat(
view.afterContentLifecycleCallbacksMethod.finish());
if (afterContentStmts.length > 0) {