refactor(compiler): remove AppElement.initComponent

This commit is contained in:
Tobias Bosch
2016-11-01 08:21:39 -07:00
committed by vikerman
parent 953cb50fa5
commit 13533d2a30
14 changed files with 80 additions and 53 deletions

View File

@ -39,7 +39,7 @@ export class CompileElement extends CompileNode {
return new CompileElement(null, null, null, null, null, null, [], [], false, false, [], []);
}
private _compViewExpr: o.Expression = null;
public compViewExpr: o.Expression = null;
public appElement: o.ReadPropExpr;
public elementRef: o.Expression;
public injector: o.Expression;
@ -131,7 +131,7 @@ export class CompileElement extends CompileNode {
}
setComponentView(compViewExpr: o.Expression) {
this._compViewExpr = compViewExpr;
this.compViewExpr = compViewExpr;
this.contentNodesByNgContentIndex =
new Array(this.component.template.ngContentSelectors.length);
for (var i = 0; i < this.contentNodesByNgContentIndex.length; i++) {
@ -254,12 +254,6 @@ export class CompileElement extends CompileNode {
queryWithRead.query.addValue(value, this.view);
}
});
if (isPresent(this.component)) {
var compExpr = isPresent(this.getComponent()) ? this.getComponent() : o.NULL_EXPR;
this.view.createMethod.addStmt(
this.appElement.callMethod('initComponent', [compExpr, this._compViewExpr]).toStmt());
}
}
afterChildren(childNodeCount: number) {
@ -340,7 +334,7 @@ export class CompileElement extends CompileNode {
if (dep.token.reference ===
resolveIdentifierToken(Identifiers.ChangeDetectorRef).reference) {
if (requestingProviderType === ProviderAstType.Component) {
return this._compViewExpr.prop('ref');
return this.compViewExpr.prop('ref');
} else {
return getPropertyInView(o.THIS_EXPR.prop('ref'), this.view, this.view.componentView);
}

View File

@ -83,8 +83,7 @@ function generateHandleEventMethod(
const hasComponentHostListener =
directives.some((dirAst) => dirAst.hostEvents.some((event) => dirAst.directive.isComponent));
const markPathToRootStart =
hasComponentHostListener ? compileElement.appElement.prop('componentView') : o.THIS_EXPR;
const markPathToRootStart = hasComponentHostListener ? compileElement.compViewExpr : o.THIS_EXPR;
const handleEventStmts = new CompileMethod(compileElement.view);
handleEventStmts.resetDebugInfo(compileElement.nodeIndex, compileElement.sourceAst);
handleEventStmts.push(markPathToRootStart.callMethod('markPathToRootAsCheckOnce', []).toStmt());

View File

@ -61,7 +61,7 @@ export function bindDirectiveWrapperLifecycleCallbacks(
DirectiveWrapperExpressions.ngOnDestroy(dir.directive, directiveWrapperIntance));
compileElement.view.detachMethod.addStmts(DirectiveWrapperExpressions.ngOnDetach(
dir.hostProperties, directiveWrapperIntance, o.THIS_EXPR,
compileElement.component ? compileElement.appElement.prop('componentView') : o.THIS_EXPR,
compileElement.compViewExpr ? compileElement.compViewExpr : o.THIS_EXPR,
compileElement.renderNode));
}

View File

@ -110,7 +110,7 @@ export function bindDirectiveHostProps(
compileElement.view.detectChangesRenderPropertiesMethod.addStmts(
DirectiveWrapperExpressions.checkHost(
directiveAst.hostProperties, directiveWrapperInstance, o.THIS_EXPR,
compileElement.component ? compileElement.appElement.prop('componentView') : o.THIS_EXPR,
compileElement.compViewExpr ? compileElement.compViewExpr : o.THIS_EXPR,
compileElement.renderNode, DetectChangesVars.throwOnChange, runtimeSecurityCtxExprs));
}
@ -147,9 +147,9 @@ export function bindDirectiveInputs(
directiveWrapperInstance, o.THIS_EXPR, compileElement.renderNode,
DetectChangesVars.throwOnChange);
const directiveDetectChangesStmt = isOnPushComp ?
new o.IfStmt(directiveDetectChangesExpr, [compileElement.appElement.prop('componentView')
.callMethod('markAsCheckOnce', [])
.toStmt()]) :
new o.IfStmt(
directiveDetectChangesExpr,
[compileElement.compViewExpr.callMethod('markAsCheckOnce', []).toStmt()]) :
directiveDetectChangesExpr.toStmt();
detectChangesInInputsMethod.addStmt(directiveDetectChangesStmt);
}

View File

@ -457,7 +457,7 @@ function createViewClass(
var viewMethods = [
new o.ClassMethod(
'createInternal', [new o.FnParam(rootSelectorVar.name, o.STRING_TYPE)],
generateCreateMethod(view), o.importType(resolveIdentifier(Identifiers.AppElement))),
generateCreateMethod(view), o.importType(resolveIdentifier(Identifiers.ComponentRef))),
new o.ClassMethod(
'injectorGetInternal',
[
@ -562,7 +562,10 @@ function generateCreateMethod(view: CompileView): o.Statement[] {
}
var resultExpr: o.Expression;
if (view.viewType === ViewType.HOST) {
resultExpr = (<CompileElement>view.nodes[0]).appElement;
const hostEl = <CompileElement>view.nodes[0];
resultExpr = o.importExpr(resolveIdentifier(Identifiers.ComponentRef_)).instantiate([
o.literal(hostEl.nodeIndex), o.THIS_EXPR, hostEl.renderNode, hostEl.getComponent()
]);
} else {
resultExpr = o.NULL_EXPR;
}