refactor(compiler): remove AppElement.initComponent
This commit is contained in:
@ -6,10 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, AnimationTransitionEvent, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, LOCALE_ID, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, AnimationTransitionEvent, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
|
||||
import {AnimationGroupPlayer, AnimationKeyframe, AnimationSequencePlayer, AnimationStyles, AnimationTransition, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, NgModuleInjector, NoOpAnimationPlayer, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, balanceAnimationKeyframes, clearStyles, collectAndResolveStyles, devModeEqual, prepareFinalAnimationStyles, reflector, registerModuleFactory, renderStyles, view_utils} from './private_import_core';
|
||||
import {AnimationGroupPlayer, AnimationKeyframe, AnimationSequencePlayer, AnimationStyles, AnimationTransition, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, ComponentRef_, DebugAppView, DebugContext, NgModuleInjector, NoOpAnimationPlayer, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, balanceAnimationKeyframes, clearStyles, collectAndResolveStyles, devModeEqual, prepareFinalAnimationStyles, reflector, registerModuleFactory, renderStyles, view_utils} from './private_import_core';
|
||||
|
||||
var APP_VIEW_MODULE_URL = assetUrl('core', 'linker/view');
|
||||
var VIEW_UTILS_MODULE_URL = assetUrl('core', 'linker/view_utils');
|
||||
@ -96,6 +96,16 @@ export class Identifiers {
|
||||
runtime: ComponentFactory,
|
||||
moduleUrl: assetUrl('core', 'linker/component_factory')
|
||||
};
|
||||
static ComponentRef_: IdentifierSpec = {
|
||||
name: 'ComponentRef_',
|
||||
runtime: ComponentRef_,
|
||||
moduleUrl: assetUrl('core', 'linker/component_factory')
|
||||
};
|
||||
static ComponentRef: IdentifierSpec = {
|
||||
name: 'ComponentRef',
|
||||
runtime: ComponentRef,
|
||||
moduleUrl: assetUrl('core', 'linker/component_factory')
|
||||
};
|
||||
static NgModuleFactory: IdentifierSpec = {
|
||||
name: 'NgModuleFactory',
|
||||
runtime: NgModuleFactory,
|
||||
|
@ -21,6 +21,7 @@ export type AppElement = typeof r._AppElement;
|
||||
export const AppElement: typeof r.AppElement = r.AppElement;
|
||||
export const CodegenComponentFactoryResolver: typeof r.CodegenComponentFactoryResolver =
|
||||
r.CodegenComponentFactoryResolver;
|
||||
export const ComponentRef_: typeof r.ComponentRef_ = r.ComponentRef_;
|
||||
export const AppView: typeof r.AppView = r.AppView;
|
||||
export const DebugAppView: typeof r.DebugAppView = r.DebugAppView;
|
||||
export const NgModuleInjector: typeof r.NgModuleInjector = r.NgModuleInjector;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user