refactor(compiler): inline view.viewChildren in generated code
This commit is contained in:
parent
97471d74b6
commit
e5fdf4c70a
@ -27,6 +27,8 @@ export class CompileView implements NameResolver {
|
|||||||
public viewType: ViewType;
|
public viewType: ViewType;
|
||||||
public viewQueries: Map<any, CompileQuery[]>;
|
public viewQueries: Map<any, CompileQuery[]>;
|
||||||
|
|
||||||
|
public viewChildren: o.Expression[] = [];
|
||||||
|
|
||||||
public nodes: CompileNode[] = [];
|
public nodes: CompileNode[] = [];
|
||||||
// root nodes or AppElements for ViewContainers
|
// root nodes or AppElements for ViewContainers
|
||||||
public rootNodesOrAppElements: o.Expression[] = [];
|
public rootNodesOrAppElements: o.Expression[] = [];
|
||||||
|
@ -194,21 +194,25 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
|||||||
parent, this.view, nodeIndex, renderNode, ast, component, directives, ast.providers,
|
parent, this.view, nodeIndex, renderNode, ast, component, directives, ast.providers,
|
||||||
ast.hasViewContainer, false, ast.references, this.targetDependencies);
|
ast.hasViewContainer, false, ast.references, this.targetDependencies);
|
||||||
this.view.nodes.push(compileElement);
|
this.view.nodes.push(compileElement);
|
||||||
var compViewExpr: o.ReadVarExpr = null;
|
var compViewExpr: o.ReadPropExpr = null;
|
||||||
if (isPresent(component)) {
|
if (isPresent(component)) {
|
||||||
let nestedComponentIdentifier =
|
let nestedComponentIdentifier =
|
||||||
new CompileIdentifierMetadata({name: getViewFactoryName(component, 0)});
|
new CompileIdentifierMetadata({name: getViewFactoryName(component, 0)});
|
||||||
this.targetDependencies.push(
|
this.targetDependencies.push(
|
||||||
new ViewFactoryDependency(component.type, nestedComponentIdentifier));
|
new ViewFactoryDependency(component.type, nestedComponentIdentifier));
|
||||||
|
|
||||||
compViewExpr = o.variable(`compView_${nodeIndex}`); // fix highlighting: `
|
compViewExpr = o.THIS_EXPR.prop(`compView_${nodeIndex}`); // fix highlighting: `
|
||||||
|
this.view.fields.push(new o.ClassField(
|
||||||
|
compViewExpr.name,
|
||||||
|
o.importType(resolveIdentifier(Identifiers.AppView), [o.importType(component.type)])));
|
||||||
|
this.view.viewChildren.push(compViewExpr);
|
||||||
compileElement.setComponentView(compViewExpr);
|
compileElement.setComponentView(compViewExpr);
|
||||||
this.view.createMethod.addStmt(
|
this.view.createMethod.addStmt(
|
||||||
compViewExpr
|
compViewExpr
|
||||||
.set(o.importExpr(nestedComponentIdentifier).callFn([
|
.set(o.importExpr(nestedComponentIdentifier).callFn([
|
||||||
ViewProperties.viewUtils, compileElement.injector, compileElement.appElement
|
ViewProperties.viewUtils, compileElement.injector, compileElement.appElement
|
||||||
]))
|
]))
|
||||||
.toDeclStmt());
|
.toStmt());
|
||||||
}
|
}
|
||||||
compileElement.beforeChildren();
|
compileElement.beforeChildren();
|
||||||
this._addRootNodeAndProject(compileElement);
|
this._addRootNodeAndProject(compileElement);
|
||||||
@ -452,7 +456,7 @@ function createViewClass(
|
|||||||
'detectChangesInternal', [new o.FnParam(DetectChangesVars.throwOnChange.name, o.BOOL_TYPE)],
|
'detectChangesInternal', [new o.FnParam(DetectChangesVars.throwOnChange.name, o.BOOL_TYPE)],
|
||||||
generateDetectChangesMethod(view)),
|
generateDetectChangesMethod(view)),
|
||||||
new o.ClassMethod('dirtyParentQueriesInternal', [], view.dirtyParentQueriesMethod.finish()),
|
new o.ClassMethod('dirtyParentQueriesInternal', [], view.dirtyParentQueriesMethod.finish()),
|
||||||
new o.ClassMethod('destroyInternal', [], view.destroyMethod.finish()),
|
new o.ClassMethod('destroyInternal', [], generateDestroyMethod(view)),
|
||||||
new o.ClassMethod('detachInternal', [], view.detachMethod.finish())
|
new o.ClassMethod('detachInternal', [], view.detachMethod.finish())
|
||||||
].filter((method) => method.body.length > 0);
|
].filter((method) => method.body.length > 0);
|
||||||
var superClass = view.genConfig.genDebugInfo ? Identifiers.DebugAppView : Identifiers.AppView;
|
var superClass = view.genConfig.genDebugInfo ? Identifiers.DebugAppView : Identifiers.AppView;
|
||||||
@ -467,6 +471,14 @@ function createViewClass(
|
|||||||
return viewClass;
|
return viewClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateDestroyMethod(view: CompileView): o.Statement[] {
|
||||||
|
const stmts: o.Statement[] = [];
|
||||||
|
view.viewChildren.forEach(
|
||||||
|
(viewChild) => { stmts.push(viewChild.callMethod('destroy', []).toStmt()); });
|
||||||
|
stmts.push(...view.destroyMethod.finish());
|
||||||
|
return stmts;
|
||||||
|
}
|
||||||
|
|
||||||
function createViewFactory(
|
function createViewFactory(
|
||||||
view: CompileView, viewClass: o.ClassStmt, renderCompTypeVar: o.ReadVarExpr): o.Statement {
|
view: CompileView, viewClass: o.ClassStmt, renderCompTypeVar: o.ReadVarExpr): o.Statement {
|
||||||
var viewFactoryArgs = [
|
var viewFactoryArgs = [
|
||||||
@ -569,8 +581,9 @@ function generateDetectChangesMethod(view: CompileView): o.Statement[] {
|
|||||||
stmts.push(new o.IfStmt(o.not(DetectChangesVars.throwOnChange), afterContentStmts));
|
stmts.push(new o.IfStmt(o.not(DetectChangesVars.throwOnChange), afterContentStmts));
|
||||||
}
|
}
|
||||||
stmts.push(...view.detectChangesRenderPropertiesMethod.finish());
|
stmts.push(...view.detectChangesRenderPropertiesMethod.finish());
|
||||||
stmts.push(o.THIS_EXPR.callMethod('detectViewChildrenChanges', [DetectChangesVars.throwOnChange])
|
view.viewChildren.forEach((viewChild) => {
|
||||||
.toStmt());
|
stmts.push(viewChild.callMethod('detectChanges', [DetectChangesVars.throwOnChange]).toStmt());
|
||||||
|
});
|
||||||
var afterViewStmts =
|
var afterViewStmts =
|
||||||
view.updateViewQueriesMethod.finish().concat(view.afterViewLifecycleCallbacksMethod.finish());
|
view.updateViewQueriesMethod.finish().concat(view.afterViewLifecycleCallbacksMethod.finish());
|
||||||
if (afterViewStmts.length > 0) {
|
if (afterViewStmts.length > 0) {
|
||||||
|
@ -34,7 +34,6 @@ export abstract class AppView<T> {
|
|||||||
allNodes: any[];
|
allNodes: any[];
|
||||||
disposables: Function[];
|
disposables: Function[];
|
||||||
contentChildren: AppView<any>[] = [];
|
contentChildren: AppView<any>[] = [];
|
||||||
viewChildren: AppView<any>[] = [];
|
|
||||||
viewContainerElement: AppElement = null;
|
viewContainerElement: AppElement = null;
|
||||||
|
|
||||||
numberOfChecks: number = 0;
|
numberOfChecks: number = 0;
|
||||||
@ -102,9 +101,6 @@ export abstract class AppView<T> {
|
|||||||
this.allNodes = allNodes;
|
this.allNodes = allNodes;
|
||||||
this.disposables = disposables;
|
this.disposables = disposables;
|
||||||
if (this.type === ViewType.COMPONENT) {
|
if (this.type === ViewType.COMPONENT) {
|
||||||
// Note: the render nodes have been attached to their host element
|
|
||||||
// in the ViewFactory already.
|
|
||||||
this.declarationAppElement.parentView.viewChildren.push(this);
|
|
||||||
this.dirtyParentQueriesInternal();
|
this.dirtyParentQueriesInternal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,10 +141,6 @@ export abstract class AppView<T> {
|
|||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
children[i]._destroyRecurse();
|
children[i]._destroyRecurse();
|
||||||
}
|
}
|
||||||
children = this.viewChildren;
|
|
||||||
for (var i = 0; i < children.length; i++) {
|
|
||||||
children[i]._destroyRecurse();
|
|
||||||
}
|
|
||||||
this.destroyLocal();
|
this.destroyLocal();
|
||||||
|
|
||||||
this.cdMode = ChangeDetectorStatus.Destroyed;
|
this.cdMode = ChangeDetectorStatus.Destroyed;
|
||||||
@ -214,7 +206,8 @@ export abstract class AppView<T> {
|
|||||||
detectChanges(throwOnChange: boolean): void {
|
detectChanges(throwOnChange: boolean): void {
|
||||||
var s = _scope_check(this.clazz);
|
var s = _scope_check(this.clazz);
|
||||||
if (this.cdMode === ChangeDetectorStatus.Checked ||
|
if (this.cdMode === ChangeDetectorStatus.Checked ||
|
||||||
this.cdMode === ChangeDetectorStatus.Errored)
|
this.cdMode === ChangeDetectorStatus.Errored ||
|
||||||
|
this.cdMode === ChangeDetectorStatus.Detached)
|
||||||
return;
|
return;
|
||||||
if (this.cdMode === ChangeDetectorStatus.Destroyed) {
|
if (this.cdMode === ChangeDetectorStatus.Destroyed) {
|
||||||
this.throwDestroyedError('detectChanges');
|
this.throwDestroyedError('detectChanges');
|
||||||
@ -231,7 +224,6 @@ export abstract class AppView<T> {
|
|||||||
*/
|
*/
|
||||||
detectChangesInternal(throwOnChange: boolean): void {
|
detectChangesInternal(throwOnChange: boolean): void {
|
||||||
this.detectContentChildrenChanges(throwOnChange);
|
this.detectContentChildrenChanges(throwOnChange);
|
||||||
this.detectViewChildrenChanges(throwOnChange);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
detectContentChildrenChanges(throwOnChange: boolean) {
|
detectContentChildrenChanges(throwOnChange: boolean) {
|
||||||
@ -242,14 +234,6 @@ export abstract class AppView<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
detectViewChildrenChanges(throwOnChange: boolean) {
|
|
||||||
for (var i = 0; i < this.viewChildren.length; ++i) {
|
|
||||||
var child = this.viewChildren[i];
|
|
||||||
if (child.cdMode === ChangeDetectorStatus.Detached) continue;
|
|
||||||
child.detectChanges(throwOnChange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
markContentChildAsMoved(renderAppElement: AppElement): void { this.dirtyParentQueriesInternal(); }
|
markContentChildAsMoved(renderAppElement: AppElement): void { this.dirtyParentQueriesInternal(); }
|
||||||
|
|
||||||
addToContentChildren(renderAppElement: AppElement): void {
|
addToContentChildren(renderAppElement: AppElement): void {
|
||||||
|
@ -38,7 +38,7 @@ class _View_TreeComponent_Host0 extends import1.AppView<any> {
|
|||||||
this._vc_0 = new import2.AppElement(0, (null as any), this, this._el_0);
|
this._vc_0 = new import2.AppElement(0, (null as any), this, this._el_0);
|
||||||
this._TreeComponent_0_4 = new _View_TreeComponent0(this._el_0);
|
this._TreeComponent_0_4 = new _View_TreeComponent0(this._el_0);
|
||||||
this._vc_0.initComponent(this._TreeComponent_0_4.context, [], <any>this._TreeComponent_0_4);
|
this._vc_0.initComponent(this._TreeComponent_0_4.context, [], <any>this._TreeComponent_0_4);
|
||||||
this.init([].concat([this._el_0]), [this._el_0], [], []);
|
this.init([].concat([this._el_0]), [this._el_0], []);
|
||||||
return this._vc_0;
|
return this._vc_0;
|
||||||
}
|
}
|
||||||
detectChangesInternal(throwOnChange: boolean): void {
|
detectChangesInternal(throwOnChange: boolean): void {
|
||||||
|
@ -27,6 +27,7 @@ class _View_TreeRootComponent_Host0 extends import1.AppView<any> {
|
|||||||
_el_0: any;
|
_el_0: any;
|
||||||
/*private*/ _appEl_0: import2.AppElement;
|
/*private*/ _appEl_0: import2.AppElement;
|
||||||
_TreeRootComponent_0_4: import3.TreeRootComponent;
|
_TreeRootComponent_0_4: import3.TreeRootComponent;
|
||||||
|
_TreeRootComponent_0_4_View: any;
|
||||||
constructor(
|
constructor(
|
||||||
viewUtils: import4.ViewUtils, parentInjector: import5.Injector,
|
viewUtils: import4.ViewUtils, parentInjector: import5.Injector,
|
||||||
declarationEl: import2.AppElement) {
|
declarationEl: import2.AppElement) {
|
||||||
@ -38,14 +39,19 @@ class _View_TreeRootComponent_Host0 extends import1.AppView<any> {
|
|||||||
this._el_0 = import4.selectOrCreateRenderHostElement(
|
this._el_0 = import4.selectOrCreateRenderHostElement(
|
||||||
this.renderer, 'tree', import4.EMPTY_INLINE_ARRAY, rootSelector, (null as any));
|
this.renderer, 'tree', import4.EMPTY_INLINE_ARRAY, rootSelector, (null as any));
|
||||||
this._appEl_0 = new import2.AppElement(0, (null as any), this, this._el_0);
|
this._appEl_0 = new import2.AppElement(0, (null as any), this, this._el_0);
|
||||||
var compView_0: any =
|
this._TreeRootComponent_0_4_View =
|
||||||
viewFactory_TreeRootComponent0(this.viewUtils, this.injector(0), this._appEl_0);
|
viewFactory_TreeRootComponent0(this.viewUtils, this.injector(0), this._appEl_0);
|
||||||
this._TreeRootComponent_0_4 = new import3.TreeRootComponent();
|
this._TreeRootComponent_0_4 = new import3.TreeRootComponent();
|
||||||
this._appEl_0.initComponent(this._TreeRootComponent_0_4, [], compView_0);
|
this._appEl_0.initComponent(this._TreeRootComponent_0_4, [], this._TreeRootComponent_0_4_View);
|
||||||
compView_0.create(this._TreeRootComponent_0_4, this.projectableNodes, (null as any));
|
this._TreeRootComponent_0_4_View.create(
|
||||||
this.init([].concat([this._el_0]), [this._el_0], [], []);
|
this._TreeRootComponent_0_4, this.projectableNodes, (null as any));
|
||||||
|
this.init([].concat([this._el_0]), [this._el_0], []);
|
||||||
return this._appEl_0;
|
return this._appEl_0;
|
||||||
}
|
}
|
||||||
|
detectChangesInternal(throwOnChange: boolean): void {
|
||||||
|
this._TreeRootComponent_0_4_View.detectChangesInternal(throwOnChange);
|
||||||
|
}
|
||||||
|
destroyInternal(): void { this._TreeRootComponent_0_4_View.destroyInternal(); }
|
||||||
injectorGetInternal(token: any, requestNodeIndex: number, notFoundResult: any): any {
|
injectorGetInternal(token: any, requestNodeIndex: number, notFoundResult: any): any {
|
||||||
if (((token === import3.TreeRootComponent) && (0 === requestNodeIndex))) {
|
if (((token === import3.TreeRootComponent) && (0 === requestNodeIndex))) {
|
||||||
return this._TreeRootComponent_0_4;
|
return this._TreeRootComponent_0_4;
|
||||||
@ -89,7 +95,7 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
|
|||||||
new import11.TemplateRef_(this._appEl_0, viewFactory_TreeRootComponent1);
|
new import11.TemplateRef_(this._appEl_0, viewFactory_TreeRootComponent1);
|
||||||
this._NgIf_0_6 = new import10.NgIf(this._appEl_0.vcRef, this._TemplateRef_0_5);
|
this._NgIf_0_6 = new import10.NgIf(this._appEl_0.vcRef, this._TemplateRef_0_5);
|
||||||
this._expr_0 = import7.UNINITIALIZED;
|
this._expr_0 = import7.UNINITIALIZED;
|
||||||
this.init([], [this._anchor_0], [], []);
|
this.init([], [this._anchor_0], []);
|
||||||
return (null as any);
|
return (null as any);
|
||||||
}
|
}
|
||||||
injectorGetInternal(token: any, requestNodeIndex: number, notFoundResult: any): any {
|
injectorGetInternal(token: any, requestNodeIndex: number, notFoundResult: any): any {
|
||||||
@ -108,7 +114,6 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
|
|||||||
this._expr_0 = currVal_0;
|
this._expr_0 = currVal_0;
|
||||||
}
|
}
|
||||||
this.detectContentChildrenChanges(throwOnChange);
|
this.detectContentChildrenChanges(throwOnChange);
|
||||||
this.detectViewChildrenChanges(throwOnChange);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function viewFactory_TreeRootComponent0(
|
export function viewFactory_TreeRootComponent0(
|
||||||
@ -134,7 +139,7 @@ class _View_TreeRootComponent1 extends import1.AppView<any> {
|
|||||||
createInternal(rootSelector: string): import2.AppElement {
|
createInternal(rootSelector: string): import2.AppElement {
|
||||||
this._el_0 = this.renderer.createElement((null as any), 'tree0', (null as any));
|
this._el_0 = this.renderer.createElement((null as any), 'tree0', (null as any));
|
||||||
this._TreeComponent0_0_4View = new import13.View_TreeTreeComponent(maxDepth - 1, this._el_0);
|
this._TreeComponent0_0_4View = new import13.View_TreeTreeComponent(maxDepth - 1, this._el_0);
|
||||||
this.init([].concat([this._el_0]), [this._el_0], [], []);
|
this.init([].concat([this._el_0]), [this._el_0], []);
|
||||||
return (null as any);
|
return (null as any);
|
||||||
}
|
}
|
||||||
destroyInternal() { this._TreeComponent0_0_4View.destroyInternal(); }
|
destroyInternal() { this._TreeComponent0_0_4View.destroyInternal(); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user