refactor(core): move ViewEncapsulation and ViewType to the right places

Closes #4526
This commit is contained in:
Tobias Bosch
2015-10-05 10:10:07 -07:00
parent 0299d4af00
commit 0b3e4fa090
20 changed files with 77 additions and 95 deletions

View File

@ -1,14 +1,14 @@
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {isPresent, isBlank, Type, isArray, isNumber} from 'angular2/src/core/facade/lang';
import {ViewType, RenderProtoViewRef} from 'angular2/src/core/render/api';
import {RenderProtoViewRef} from 'angular2/src/core/render/api';
import {Injectable, Binding, resolveForwardRef, Inject} from 'angular2/src/core/di';
import {PipeBinding} from '../pipes/pipe_binding';
import {ProtoPipes} from '../pipes/pipes';
import {AppProtoView, AppProtoViewMergeInfo} from './view';
import {AppProtoView, AppProtoViewMergeInfo, ViewType} from './view';
import {ElementBinder} from './element_binder';
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
import {DirectiveResolver} from './directive_resolver';

View File

@ -38,6 +38,18 @@ export {DebugContext} from 'angular2/src/core/change_detection/interfaces';
const REFLECT_PREFIX: string = 'ng-reflect-';
export enum ViewType {
// A view that contains the host element with bound component directive.
// Contains a COMPONENT view
HOST,
// The view of the component
// Can contain 0 to n EMBEDDED views
COMPONENT,
// A view that is embedded into another View via a <template> element
// inside of a COMPONENT view
EMBEDDED
}
export class AppViewContainer {
// The order in this list matches the DOM order.
views: AppView[] = [];
@ -307,8 +319,8 @@ export class AppProtoView {
textBindingCount = null;
render: renderApi.RenderProtoViewRef = null;
constructor(public templateCmds: TemplateCmd[], public type: renderApi.ViewType,
public isMergable: boolean, public changeDetectorFactory: Function,
constructor(public templateCmds: TemplateCmd[], public type: ViewType, public isMergable: boolean,
public changeDetectorFactory: Function,
public templateVariableBindings: Map<string, string>, public pipes: ProtoPipes) {
this.ref = new ProtoViewRef(this);
}

View File

@ -17,8 +17,7 @@ import {
Renderer,
RenderViewRef,
RenderFragmentRef,
RenderViewWithFragments,
ViewType
RenderViewWithFragments
} from 'angular2/src/core/render/api';
import {AppViewManagerUtils} from './view_manager_utils';
import {AppViewPool} from './view_pool';
@ -57,7 +56,7 @@ export class AppViewManager {
*/
getHostElement(hostViewRef: HostViewRef): ElementRef {
var hostView = internalView(<ViewRef>hostViewRef);
if (hostView.proto.type !== ViewType.HOST) {
if (hostView.proto.type !== viewModule.ViewType.HOST) {
throw new BaseException('This operation is only allowed on host views');
}
return hostView.elementRefs[hostView.elementOffset];
@ -205,7 +204,7 @@ export class AppViewManager {
templateRef: TemplateRef): ViewRef {
var s = this._createEmbeddedViewInContainerScope();
var protoView = internalProtoView(templateRef.protoViewRef);
if (protoView.type !== ViewType.EMBEDDED) {
if (protoView.type !== viewModule.ViewType.EMBEDDED) {
throw new BaseException('This method can only be called with embedded ProtoViews!');
}
this._protoViewFactory.initializeProtoViewIfNeeded(protoView);
@ -236,7 +235,7 @@ export class AppViewManager {
imperativelyCreatedInjector: ResolvedBinding[]): HostViewRef {
var s = this._createHostViewInContainerScope();
var protoView = internalProtoView(protoViewRef);
if (protoView.type !== ViewType.HOST) {
if (protoView.type !== viewModule.ViewType.HOST) {
throw new BaseException('This method can only be called with host ProtoViews!');
}
this._protoViewFactory.initializeProtoViewIfNeeded(protoView);
@ -258,7 +257,7 @@ export class AppViewManager {
var contextBoundElementIndex = context.boundElementIndex;
var embeddedFragmentView = contextView.getNestedView(contextBoundElementIndex);
var view;
if (protoView.type === ViewType.EMBEDDED && isPresent(embeddedFragmentView) &&
if (protoView.type === viewModule.ViewType.EMBEDDED && isPresent(embeddedFragmentView) &&
!embeddedFragmentView.hydrated()) {
// Case 1: instantiate the first view of a template that has been merged into a parent
view = embeddedFragmentView;

View File

@ -9,7 +9,6 @@ import {TemplateRef} from './template_ref';
import {Renderer, RenderViewWithFragments} from 'angular2/src/core/render/api';
import {Locals} from 'angular2/src/core/change_detection/change_detection';
import {Pipes} from 'angular2/src/core/pipes/pipes';
import {RenderViewRef, RenderFragmentRef, ViewType} from 'angular2/src/core/render/api';
@Injectable()
export class AppViewManagerUtils {
@ -50,7 +49,7 @@ export class AppViewManagerUtils {
.nestedProtoView :
mergedParentViewProto;
var renderFragment = null;
if (viewOffset === 0 || protoView.type === ViewType.EMBEDDED) {
if (viewOffset === 0 || protoView.type === viewModule.ViewType.EMBEDDED) {
renderFragment = renderFragments[fragmentIdx++];
}
var currentView = new viewModule.AppView(renderer, protoView, viewOffset, elementOffset,
@ -93,7 +92,7 @@ export class AppViewManagerUtils {
// preBuiltObjects
if (isPresent(elementInjector)) {
var templateRef = isPresent(binder.nestedProtoView) &&
binder.nestedProtoView.type === ViewType.EMBEDDED ?
binder.nestedProtoView.type === viewModule.ViewType.EMBEDDED ?
new TemplateRef(el) :
null;
preBuiltObjects[boundElementIndex] =
@ -102,7 +101,7 @@ export class AppViewManagerUtils {
}
currentView.init(protoView.changeDetectorFactory(currentView), elementInjectors,
rootElementInjectors, preBuiltObjects, views, elementRefs, viewContainers);
if (isPresent(parentView) && protoView.type === ViewType.COMPONENT) {
if (isPresent(parentView) && protoView.type === viewModule.ViewType.COMPONENT) {
parentView.changeDetector.addShadowDomChild(currentView.changeDetector);
}
elementOffset += protoView.elementBinders.length;
@ -180,7 +179,7 @@ export class AppViewManagerUtils {
while (viewIdx <= endViewOffset) {
var currView = initView.views[viewIdx];
var currProtoView = currView.proto;
if (currView !== initView && currView.proto.type === ViewType.EMBEDDED) {
if (currView !== initView && currView.proto.type === viewModule.ViewType.EMBEDDED) {
// Don't hydrate components of embedded fragment views.
viewIdx += currView.proto.mergeInfo.viewCount;
} else {