refactor(compiler): rename `AppElement` into `ViewContainer`

This commit is contained in:
Tobias Bosch 2016-11-01 11:12:25 -07:00 committed by vikerman
parent 74ede9aa9b
commit e7c00be19d
18 changed files with 65 additions and 61 deletions

View File

@ -9,7 +9,7 @@
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, ComponentRef_, 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, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, ComponentRef_, DebugAppView, DebugContext, NgModuleInjector, NoOpAnimationPlayer, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewContainer, 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');
@ -41,10 +41,10 @@ export class Identifiers {
moduleUrl: APP_VIEW_MODULE_URL,
runtime: DebugAppView
};
static AppElement: IdentifierSpec = {
name: 'AppElement',
moduleUrl: assetUrl('core', 'linker/element'),
runtime: AppElement
static ViewContainer: IdentifierSpec = {
name: 'ViewContainer',
moduleUrl: assetUrl('core', 'linker/view_container'),
runtime: ViewContainer
};
static ElementRef: IdentifierSpec = {
name: 'ElementRef',

View File

@ -17,8 +17,8 @@ export const LifecycleHooks: typeof r.LifecycleHooks = r.LifecycleHooks;
export const LIFECYCLE_HOOKS_VALUES: typeof r.LIFECYCLE_HOOKS_VALUES = r.LIFECYCLE_HOOKS_VALUES;
export type ReflectorReader = typeof r._ReflectorReader;
export const ReflectorReader: typeof r.ReflectorReader = r.ReflectorReader;
export type AppElement = typeof r._AppElement;
export const AppElement: typeof r.AppElement = r.AppElement;
export type ViewContainer = typeof r._ViewContainer;
export const ViewContainer: typeof r.ViewContainer = r.ViewContainer;
export const CodegenComponentFactoryResolver: typeof r.CodegenComponentFactoryResolver =
r.CodegenComponentFactoryResolver;
export const ComponentRef_: typeof r.ComponentRef_ = r.ComponentRef_;

View File

@ -40,7 +40,7 @@ export class CompileElement extends CompileNode {
}
public compViewExpr: o.Expression = null;
public appElement: o.ReadPropExpr;
public viewContainer: o.ReadPropExpr;
public elementRef: o.Expression;
public injector: o.Expression;
public instances = new Map<any, o.Expression>();
@ -74,30 +74,31 @@ export class CompileElement extends CompileNode {
this.instances.set(
resolveIdentifierToken(Identifiers.Renderer).reference, o.THIS_EXPR.prop('renderer'));
if (this.hasViewContainer) {
this._createAppElement();
this._createViewContainer();
}
if (this.component) {
this._createComponentFactoryResolver();
}
}
private _createAppElement() {
var fieldName = `_appEl_${this.nodeIndex}`;
private _createViewContainer() {
var fieldName = `_vc_${this.nodeIndex}`;
var parentNodeIndex = this.isRootElement() ? null : this.parent.nodeIndex;
// private is fine here as no child view will reference an AppElement
// private is fine here as no child view will reference a ViewContainer
this.view.fields.push(new o.ClassField(
fieldName, o.importType(resolveIdentifier(Identifiers.AppElement)),
fieldName, o.importType(resolveIdentifier(Identifiers.ViewContainer)),
[o.StmtModifier.Private]));
var statement =
o.THIS_EXPR.prop(fieldName)
.set(o.importExpr(resolveIdentifier(Identifiers.AppElement)).instantiate([
.set(o.importExpr(resolveIdentifier(Identifiers.ViewContainer)).instantiate([
o.literal(this.nodeIndex), o.literal(parentNodeIndex), o.THIS_EXPR, this.renderNode
]))
.toStmt();
this.view.createMethod.addStmt(statement);
this.appElement = o.THIS_EXPR.prop(fieldName);
this.instances.set(resolveIdentifierToken(Identifiers.AppElement).reference, this.appElement);
this.view.appElements.push(this.appElement);
this.viewContainer = o.THIS_EXPR.prop(fieldName);
this.instances.set(
resolveIdentifierToken(Identifiers.ViewContainer).reference, this.viewContainer);
this.view.viewContainers.push(this.viewContainer);
}
private _createComponentFactoryResolver() {
@ -159,7 +160,7 @@ export class CompileElement extends CompileNode {
if (this.hasViewContainer) {
this.instances.set(
resolveIdentifierToken(Identifiers.ViewContainerRef).reference,
this.appElement.prop('vcRef'));
this.viewContainer.prop('vcRef'));
}
this._resolvedProviders = new Map<any, ProviderAst>();

View File

@ -91,7 +91,7 @@ function createQueryValues(viewValues: ViewQueryValues): o.Expression[] {
return ListWrapper.flatten(viewValues.values.map((entry) => {
if (entry instanceof ViewQueryValues) {
return mapNestedViews(
entry.view.declarationElement.appElement, entry.view, createQueryValues(entry));
entry.view.declarationElement.viewContainer, entry.view, createQueryValues(entry));
} else {
return <o.Expression>entry;
}
@ -99,11 +99,10 @@ function createQueryValues(viewValues: ViewQueryValues): o.Expression[] {
}
function mapNestedViews(
declarationAppElement: o.Expression, view: CompileView,
expressions: o.Expression[]): o.Expression {
viewContainer: o.Expression, view: CompileView, expressions: o.Expression[]): o.Expression {
var adjustedExpressions: o.Expression[] = expressions.map(
(expr) => o.replaceVarInExpression(o.THIS_EXPR.name, o.variable('nestedView'), expr));
return declarationAppElement.callMethod('mapNestedViews', [
return viewContainer.callMethod('mapNestedViews', [
o.variable(view.className),
o.fn(
[new o.FnParam('nestedView', view.classType)],

View File

@ -46,7 +46,7 @@ export class CompileView implements NameResolver {
public rootNodes: CompileViewRootNode[] = [];
public lastRenderNode: o.Expression = o.NULL_EXPR;
public appElements: o.Expression[] = [];
public viewContainers: o.Expression[] = [];
public createMethod: CompileMethod;
public animationBindingsMethod: CompileMethod;

View File

@ -72,21 +72,20 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
var projectedNode = _getOuterContainerOrSelf(node);
var parent = projectedNode.parent;
var ngContentIndex = (<any>projectedNode.sourceAst).ngContentIndex;
var vcAppEl =
(node instanceof CompileElement && node.hasViewContainer) ? node.appElement : null;
var viewContainer =
(node instanceof CompileElement && node.hasViewContainer) ? node.viewContainer : null;
if (this._isRootNode(parent)) {
// store appElement as root node only for ViewContainers
if (this.view.viewType !== ViewType.COMPONENT) {
this.view.rootNodes.push(new CompileViewRootNode(
vcAppEl ? CompileViewRootNodeType.ViewContainer : CompileViewRootNodeType.Node,
vcAppEl || node.renderNode));
viewContainer ? CompileViewRootNodeType.ViewContainer : CompileViewRootNodeType.Node,
viewContainer || node.renderNode));
}
} else if (isPresent(parent.component) && isPresent(ngContentIndex)) {
parent.addContentNode(
ngContentIndex,
new CompileViewRootNode(
vcAppEl ? CompileViewRootNodeType.ViewContainer : CompileViewRootNodeType.Node,
vcAppEl || node.renderNode));
viewContainer ? CompileViewRootNodeType.ViewContainer : CompileViewRootNodeType.Node,
viewContainer || node.renderNode));
}
}
@ -494,8 +493,9 @@ function createViewClass(
function generateDestroyMethod(view: CompileView): o.Statement[] {
const stmts: o.Statement[] = [];
view.appElements.forEach(
(appElement) => { stmts.push(appElement.callMethod('destroyNestedViews', []).toStmt()); });
view.viewContainers.forEach((viewContainer) => {
stmts.push(viewContainer.callMethod('destroyNestedViews', []).toStmt());
});
view.viewChildren.forEach(
(viewChild) => { stmts.push(viewChild.callMethod('destroy', []).toStmt()); });
stmts.push(...view.destroyMethod.finish());
@ -600,9 +600,9 @@ function generateDetectChangesMethod(view: CompileView): o.Statement[] {
}
stmts.push(...view.animationBindingsMethod.finish());
stmts.push(...view.detectChangesInInputsMethod.finish());
view.appElements.forEach((appElement) => {
view.viewContainers.forEach((viewContainer) => {
stmts.push(
appElement.callMethod('detectChangesInNestedViews', [DetectChangesVars.throwOnChange])
viewContainer.callMethod('detectChangesInNestedViews', [DetectChangesVars.throwOnChange])
.toStmt());
});
var afterContentStmts = view.updateContentQueriesMethod.finish().concat(

View File

@ -23,11 +23,11 @@ import {ComponentStillLoadingError} from './linker/compiler';
import * as component_factory from './linker/component_factory';
import * as component_factory_resolver from './linker/component_factory_resolver';
import * as debug_context from './linker/debug_context';
import * as element from './linker/element';
import * as ng_module_factory from './linker/ng_module_factory';
import * as ng_module_factory_loader from './linker/ng_module_factory_loader';
import * as template_ref from './linker/template_ref';
import * as view from './linker/view';
import * as view_container from './linker/view_container';
import * as view_type from './linker/view_type';
import * as view_utils from './linker/view_utils';
import * as lifecycle_hooks from './metadata/lifecycle_hooks';
@ -59,7 +59,7 @@ export var __core_private__: {
typeof component_factory_resolver.CodegenComponentFactoryResolver,
ComponentRef_: typeof component_factory.ComponentRef_,
_CodegenComponentFactoryResolver?: component_factory_resolver.CodegenComponentFactoryResolver,
AppElement: typeof element.AppElement, _AppElement?: element.AppElement,
ViewContainer: typeof view_container.ViewContainer, _ViewContainer?: view_container.ViewContainer,
AppView: typeof view.AppView, _AppView?: view.AppView<any>,
DebugAppView: typeof view.DebugAppView, _DebugAppView?: view.DebugAppView<any>,
NgModuleInjector: typeof ng_module_factory.NgModuleInjector,
@ -115,7 +115,7 @@ export var __core_private__: {
ReflectorReader: reflector_reader.ReflectorReader,
CodegenComponentFactoryResolver: component_factory_resolver.CodegenComponentFactoryResolver,
ComponentRef_: component_factory.ComponentRef_,
AppElement: element.AppElement,
ViewContainer: view_container.ViewContainer,
AppView: view.AppView,
DebugAppView: view.DebugAppView,
NgModuleInjector: ng_module_factory.NgModuleInjector,

View File

@ -11,13 +11,14 @@ import {Injector} from '../di/injector';
import {unimplemented} from '../facade/errors';
import {Type} from '../type';
import {AppElement} from './element';
import {ElementRef} from './element_ref';
import {AppView} from './view';
import {ViewContainer} from './view_container';
import {ViewRef} from './view_ref';
import {ViewUtils} from './view_utils';
/**
* Represents an instance of a Component created via a {@link ComponentFactory}.
*

View File

@ -6,11 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AppElement} from './element';
import {ElementRef} from './element_ref';
import {AppView} from './view';
import {ViewContainer} from './view_container';
import {EmbeddedViewRef} from './view_ref';
/**
* Represents an Embedded Template that can be used to instantiate Embedded Views.
*

View File

@ -16,9 +16,9 @@ import {RenderComponentType, RenderDebugInfo, Renderer} from '../render/api';
import {AnimationViewContext} from './animation_view_context';
import {ComponentRef} from './component_factory';
import {DebugContext, StaticNodeDebugInfo} from './debug_context';
import {AppElement} from './element';
import {ElementInjector} from './element_injector';
import {ExpressionChangedAfterItHasBeenCheckedError, ViewDestroyedError, ViewWrappedError} from './errors';
import {ViewContainer} from './view_container';
import {ViewRef_} from './view_ref';
import {ViewType} from './view_type';
import {ViewUtils, addToArray} from './view_utils';
@ -39,7 +39,7 @@ export abstract class AppView<T> {
lastRootNode: any;
allNodes: any[];
disposables: Function[];
viewContainerElement: AppElement = null;
viewContainerElement: ViewContainer = null;
numberOfChecks: number = 0;
@ -235,14 +235,14 @@ export abstract class AppView<T> {
*/
detectChangesInternal(throwOnChange: boolean): void {}
markContentChildAsMoved(renderAppElement: AppElement): void { this.dirtyParentQueriesInternal(); }
markContentChildAsMoved(viewContainer: ViewContainer): void { this.dirtyParentQueriesInternal(); }
addToContentChildren(renderAppElement: AppElement): void {
this.viewContainerElement = renderAppElement;
addToContentChildren(viewContainer: ViewContainer): void {
this.viewContainerElement = viewContainer;
this.dirtyParentQueriesInternal();
}
removeFromContentChildren(renderAppElement: AppElement): void {
removeFromContentChildren(viewContainer: ViewContainer): void {
this.dirtyParentQueriesInternal();
this.viewContainerElement = null;
}

View File

@ -17,10 +17,10 @@ import {ViewType} from './view_type';
/**
* An AppElement is created for elements that have a ViewContainerRef
* A ViewContainer is created for elements that have a ViewContainerRef
* to keep track of the nested views.
*/
export class AppElement {
export class ViewContainer {
public nestedViews: AppView<any>[];
constructor(

View File

@ -10,13 +10,15 @@ import {Injector} from '../di/injector';
import {unimplemented} from '../facade/errors';
import {isPresent} from '../facade/lang';
import {WtfScopeFn, wtfCreateScope, wtfLeave} from '../profile/profile';
import {ComponentFactory, ComponentRef} from './component_factory';
import {AppElement} from './element';
import {ElementRef} from './element_ref';
import {TemplateRef} from './template_ref';
import {ViewContainer} from './view_container';
import {EmbeddedViewRef, ViewRef, ViewRef_} from './view_ref';
/**
* Represents a container where one or more Views can be attached.
*
@ -127,7 +129,7 @@ export abstract class ViewContainerRef {
}
export class ViewContainerRef_ implements ViewContainerRef {
constructor(private _element: AppElement) {}
constructor(private _element: ViewContainer) {}
get(index: number): ViewRef { return this._element.nestedViews[index].ref; }
get length(): number {

View File

@ -15,9 +15,9 @@ import {ViewEncapsulation} from '../metadata/view';
import {RenderComponentType, RenderDebugInfo, Renderer, RootRenderer} from '../render/api';
import {Sanitizer} from '../security';
import {AppElement} from './element';
import {ExpressionChangedAfterItHasBeenCheckedError} from './errors';
import {AppView} from './view';
import {ViewContainer} from './view_container';
@Injectable()
export class ViewUtils {

View File

@ -9,9 +9,9 @@ import * as import10 from '@angular/common/src/directives/ng_if';
import * as import7 from '@angular/core/src/change_detection/change_detection';
import * as import5 from '@angular/core/src/di/injector';
import * as import9 from '@angular/core/src/linker/component_factory';
import * as import2 from '@angular/core/src/linker/element';
import * as import11 from '@angular/core/src/linker/template_ref';
import * as import1 from '@angular/core/src/linker/view';
import * as import2 from '@angular/core/src/linker/view_container';
import * as import6 from '@angular/core/src/linker/view_type';
import * as import4 from '@angular/core/src/linker/view_utils';
import * as import8 from '@angular/core/src/metadata/view';

View File

@ -8,9 +8,9 @@ import * as import10 from '@angular/common/src/directives/ng_if';
import * as import7 from '@angular/core/src/change_detection/change_detection';
import * as import5 from '@angular/core/src/di/injector';
import * as import9 from '@angular/core/src/linker/component_factory';
import * as import2 from '@angular/core/src/linker/element';
import * as import11 from '@angular/core/src/linker/template_ref';
import * as import1 from '@angular/core/src/linker/view';
import * as import2 from '@angular/core/src/linker/view_container';
import * as import6 from '@angular/core/src/linker/view_type';
import * as import4 from '@angular/core/src/linker/view_utils';
import * as import8 from '@angular/core/src/metadata/view';
@ -23,7 +23,7 @@ import {_View_TreeComponent0} from './tree.ngfactory';
var renderType_TreeComponent_Host: import0.RenderComponentType = (null as any);
class _View_TreeComponent_Host0 extends import1.AppView<any> {
_el_0: any;
_vc_0: import2.AppElement;
_vc_0: import2.ViewContainer;
_TreeComponent_0_4: _View_TreeComponent0;
constructor(
viewUtils: import4.ViewUtils, parentInjector: import5.Injector,
@ -36,7 +36,7 @@ class _View_TreeComponent_Host0 extends import1.AppView<any> {
createInternal(rootSelector: string): import9.ComponentRef<any> {
this._el_0 = import4.selectOrCreateRenderHostElement(
this.renderer, 'tree', import4.EMPTY_INLINE_ARRAY, rootSelector, (null as any));
this._vc_0 = new import2.AppElement(0, (null as any), this, this._el_0);
this._vc_0 = new import2.ViewContainer(0, (null as any), this, this._el_0);
this._TreeComponent_0_4 = new _View_TreeComponent0(this._el_0);
this.init([].concat([this._el_0]), [this._el_0], []);
return new import9.ComponentRef_(0, this, this._el_0, this._TreeComponent_0_4.context);

View File

@ -8,8 +8,8 @@
import * as import7 from '@angular/core/src/change_detection/change_detection';
import * as import5 from '@angular/core/src/di/injector';
import * as import9 from '@angular/core/src/linker/component_factory';
import * as import2 from '@angular/core/src/linker/element';
import * as import1 from '@angular/core/src/linker/view';
import * as import2 from '@angular/core/src/linker/view_container';
import * as import6 from '@angular/core/src/linker/view_type';
import * as import4 from '@angular/core/src/linker/view_utils';
import * as import8 from '@angular/core/src/metadata/view';

View File

@ -8,8 +8,8 @@
import * as import7 from '@angular/core/src/change_detection/change_detection';
import * as import5 from '@angular/core/src/di/injector';
import * as import9 from '@angular/core/src/linker/component_factory';
import * as import2 from '@angular/core/src/linker/element';
import * as import1 from '@angular/core/src/linker/view';
import * as import2 from '@angular/core/src/linker/view_container';
import * as import6 from '@angular/core/src/linker/view_type';
import * as import4 from '@angular/core/src/linker/view_utils';
import * as import8 from '@angular/core/src/metadata/view';

View File

@ -8,9 +8,9 @@ import * as import10 from '@angular/common/src/directives/ng_if';
import * as import7 from '@angular/core/src/change_detection/change_detection';
import * as import5 from '@angular/core/src/di/injector';
import * as import9 from '@angular/core/src/linker/component_factory';
import * as import2 from '@angular/core/src/linker/element';
import * as import11 from '@angular/core/src/linker/template_ref';
import * as import1 from '@angular/core/src/linker/view';
import * as import2 from '@angular/core/src/linker/view_container';
import * as import6 from '@angular/core/src/linker/view_type';
import * as import4 from '@angular/core/src/linker/view_utils';
import * as import8 from '@angular/core/src/metadata/view';
@ -25,7 +25,7 @@ import * as import13 from './tree_branch.ngfactory';
var renderType_TreeRootComponent_Host: import0.RenderComponentType = (null as any);
class _View_TreeRootComponent_Host0 extends import1.AppView<any> {
_el_0: any;
/*private*/ _appEl_0: import2.AppElement;
/*private*/ _appEl_0: import2.ViewContainer;
_TreeRootComponent_0_4: import3.TreeRootComponent;
_TreeRootComponent_0_4_View: any;
constructor(
@ -39,7 +39,7 @@ class _View_TreeRootComponent_Host0 extends import1.AppView<any> {
createInternal(rootSelector: string): import9.ComponentRef<any> {
this._el_0 = import4.selectOrCreateRenderHostElement(
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.ViewContainer(0, (null as any), this, this._el_0);
this._TreeRootComponent_0_4_View =
viewFactory_TreeRootComponent0(this.viewUtils, this.injector(0), this, 0, this._el_0);
this._TreeRootComponent_0_4 = new import3.TreeRootComponent();
@ -76,7 +76,7 @@ const styles_TreeRootComponent: any[] = [];
var renderType_TreeRootComponent: import0.RenderComponentType = (null as any);
class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent> {
_anchor_0: any;
/*private*/ _appEl_0: import2.AppElement;
/*private*/ _appEl_0: import2.ViewContainer;
_TemplateRef_0_5: any;
_NgIf_0_6: import10.NgIf;
/*private*/ _expr_0: any;
@ -91,7 +91,7 @@ class _View_TreeRootComponent0 extends import1.AppView<import3.TreeRootComponent
createInternal(rootSelector: string): import9.ComponentRef<any> {
const parentRenderNode: any = this.renderer.createViewRoot(this.parentElement);
this._anchor_0 = this.renderer.createTemplateAnchor(parentRenderNode, (null as any));
this._appEl_0 = new import2.AppElement(0, (null as any), this, this._anchor_0);
this._appEl_0 = new import2.ViewContainer(0, (null as any), this, this._anchor_0);
this._TemplateRef_0_5 = new import11.TemplateRef_(this, 0, this._anchor_0);
this._NgIf_0_6 = new import10.NgIf(this._appEl_0.vcRef, this._TemplateRef_0_5);
this._expr_0 = import7.UNINITIALIZED;