Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): move ViewEncapsulation and ViewType to the right … #4526

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/angular2/src/core/compiler/command_compiler.ts
Expand Up @@ -30,7 +30,7 @@ import {
import {CompileTypeMetadata, CompileDirectiveMetadata} from './directive_metadata';
import {SourceExpressions, SourceExpression, moduleRef} from './source_module';

import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {
shimHostAttribute,
shimContentAttribute,
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/compiler/directive_metadata.ts
Expand Up @@ -12,7 +12,7 @@ import {
ChangeDetectionStrategy,
CHANGE_DECTION_STRATEGY_VALUES
} from 'angular2/src/core/change_detection/change_detection';
import {ViewEncapsulation, VIEW_ENCAPSULATION_VALUES} from 'angular2/src/core/render/api';
import {ViewEncapsulation, VIEW_ENCAPSULATION_VALUES} from 'angular2/src/core/metadata/view';
import {CssSelector} from 'angular2/src/core/compiler/selector';
import {splitAtColon} from './util';
import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/linker/interfaces';
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/compiler/style_compiler.ts
@@ -1,6 +1,6 @@
import {CompileTypeMetadata, CompileTemplateMetadata} from './directive_metadata';
import {SourceModule, SourceExpression, moduleRef} from './source_module';
import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {XHR} from 'angular2/src/core/compiler/xhr';
import {StringWrapper, isBlank} from 'angular2/src/core/facade/lang';
import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
Expand Down
3 changes: 2 additions & 1 deletion modules/angular2/src/core/compiler/template_normalizer.ts
Expand Up @@ -11,7 +11,8 @@ import {XHR} from 'angular2/src/core/compiler/xhr';
import {UrlResolver} from 'angular2/src/core/compiler/url_resolver';
import {resolveStyleUrls} from './style_url_resolver';
import {Injectable} from 'angular2/src/core/di';
import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';


import {
HtmlAstVisitor,
Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/core/linker/proto_view_factory.ts
@@ -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';
Expand Down
16 changes: 14 additions & 2 deletions modules/angular2/src/core/linker/view.ts
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 5 additions & 6 deletions modules/angular2/src/core/linker/view_manager.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions modules/angular2/src/core/linker/view_manager_utils.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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] =
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/core/metadata.dart
Expand Up @@ -8,7 +8,7 @@ import './metadata/view.dart';

export './metadata/di.dart';
export './metadata/directives.dart';
export './metadata/view.dart';
export './metadata/view.dart' hide VIEW_ENCAPSULATION_VALUES;

/**
* See: [DirectiveMetadata] for docs.
Expand Down
33 changes: 31 additions & 2 deletions modules/angular2/src/core/metadata/view.ts
@@ -1,7 +1,36 @@
import {CONST, Type} from 'angular2/src/core/facade/lang';
import {ViewEncapsulation} from 'angular2/src/core/render/api';

export {ViewEncapsulation} from 'angular2/src/core/render/api';
/**
* Defines template and style encapsulation options available for Component's {@link View}.
*
* See {@link ViewMetadata#encapsulation}.
*/
export enum ViewEncapsulation {
/**
* Emulate `Native` scoping of styles by adding an attribute containing surrogate id to the Host
* Element and pre-processing the style rules provided via
* {@link ViewMetadata#styles} or {@link ViewMetadata#stylesUrls}, and adding the new Host Element
* attribute to all selectors.
*
* This is the default option.
*/
Emulated,
/**
* Use the native encapsulation mechanism of the renderer.
*
* For the DOM this means using [Shadow DOM](https://w3c.github.io/webcomponents/spec/shadow/) and
* creating a ShadowRoot for Component's Host Element.
*/
Native,
/**
* Don't provide any template or style encapsulation.
*/
None
}

export var VIEW_ENCAPSULATION_VALUES =
[ViewEncapsulation.Emulated, ViewEncapsulation.Native, ViewEncapsulation.None];


/**
* Metadata properties available for configuring Views.
Expand Down
45 changes: 0 additions & 45 deletions modules/angular2/src/core/render/api.ts
@@ -1,18 +1,5 @@
import {Map} from 'angular2/src/core/facade/collection';

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
}


/**
* Represents an Angular ProtoView in the Rendering Context.
*
Expand Down Expand Up @@ -89,38 +76,6 @@ export class RenderFragmentRef {}
// TODO(i): refactor into an interface
export class RenderViewRef {}


/**
* Defines template and style encapsulation options available for Component's {@link View}.
*
* See {@link ViewMetadata#encapsulation}.
*/
export enum ViewEncapsulation {
/**
* Emulate `Native` scoping of styles by adding an attribute containing surrogate id to the Host
* Element and pre-processing the style rules provided via
* {@link ViewMetadata#styles} or {@link ViewMetadata#stylesUrls}, and adding the new Host Element
* attribute to all selectors.
*
* This is the default option.
*/
Emulated,
/**
* Use the native encapsulation mechanism of the renderer.
*
* For the DOM this means using [Shadow DOM](https://w3c.github.io/webcomponents/spec/shadow/) and
* creating a ShadowRoot for Component's Host Element.
*/
Native,
/**
* Don't provide any template or style encapsulation.
*/
None
}

export var VIEW_ENCAPSULATION_VALUES =
[ViewEncapsulation.Emulated, ViewEncapsulation.Native, ViewEncapsulation.None];

export interface RenderTemplateCmd { visit(visitor: RenderCommandVisitor, context: any): any; }

export interface RenderBeginCmd extends RenderTemplateCmd {
Expand Down
19 changes: 1 addition & 18 deletions modules/angular2/src/web_workers/shared/serializer.ts
Expand Up @@ -13,8 +13,6 @@ import {
RenderViewRef,
RenderFragmentRef,
RenderElementRef,
ViewType,
ViewEncapsulation,
RenderTemplateCmd,
RenderCommandVisitor,
RenderTextCmd,
Expand Down Expand Up @@ -46,23 +44,8 @@ export const PRIMITIVE: Type = String;

@Injectable()
export class Serializer {
private _enumRegistry: Map<any, Map<number, any>>;
constructor(private _protoViewStore: RenderProtoViewRefStore,
private _renderViewStore: RenderViewWithFragmentsStore) {
this._enumRegistry = new Map<any, Map<number, any>>();

var viewTypeMap = new Map<number, any>();
viewTypeMap[0] = ViewType.HOST;
viewTypeMap[1] = ViewType.COMPONENT;
viewTypeMap[2] = ViewType.EMBEDDED;
this._enumRegistry.set(ViewType, viewTypeMap);

var viewEncapsulationMap = new Map<number, any>();
viewEncapsulationMap[0] = ViewEncapsulation.Emulated;
viewEncapsulationMap[1] = ViewEncapsulation.Native;
viewEncapsulationMap[2] = ViewEncapsulation.None;
this._enumRegistry.set(ViewEncapsulation, viewEncapsulationMap);
}
private _renderViewStore: RenderViewWithFragmentsStore) {}

serialize(obj: any, type: Type): Object {
if (!isPresent(obj)) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ import {
CompileTemplateMetadata
} from 'angular2/src/core/compiler/directive_metadata';
import {SourceModule, SourceExpression, moduleRef} from 'angular2/src/core/compiler/source_module';
import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {evalModule} from './eval_module';
import {
escapeSingleQuoteString,
Expand Down
Expand Up @@ -17,7 +17,7 @@ import {
CompileTypeMetadata,
CompileTemplateMetadata
} from 'angular2/src/core/compiler/directive_metadata';
import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {ChangeDetectionStrategy} from 'angular2/src/core/change_detection';
import {LifecycleHooks} from 'angular2/src/core/linker/interfaces';

Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/test/core/compiler/style_compiler_spec.ts
Expand Up @@ -27,7 +27,7 @@ import {
CompileTypeMetadata
} from 'angular2/src/core/compiler/directive_metadata';
import {SourceExpression, SourceModule} from 'angular2/src/core/compiler/source_module';
import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';
import {TEST_BINDINGS} from './test_bindings';
import {
codeGenValueFn,
Expand Down
Expand Up @@ -26,7 +26,7 @@ import {evalModule} from './eval_module';
import {SourceModule, moduleRef} from 'angular2/src/core/compiler/source_module';
import {XHR} from 'angular2/src/core/compiler/xhr';
import {MockXHR} from 'angular2/src/core/compiler/xhr_mock';
import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';

import {Locals} from 'angular2/src/core/change_detection/change_detection';

Expand Down
Expand Up @@ -17,7 +17,7 @@ import {
CompileTypeMetadata,
CompileTemplateMetadata
} from 'angular2/src/core/compiler/directive_metadata';
import {ViewEncapsulation} from 'angular2/src/core/render/api';
import {ViewEncapsulation} from 'angular2/src/core/metadata/view';

import {TemplateNormalizer} from 'angular2/src/core/compiler/template_normalizer';
import {XHR} from 'angular2/src/core/compiler/xhr';
Expand Down
3 changes: 1 addition & 2 deletions modules/angular2/test/core/linker/view_manager_spec.ts
Expand Up @@ -16,7 +16,7 @@ import {
import {SpyRenderer, SpyAppViewPool, SpyAppViewListener, SpyProtoViewFactory} from '../spies';
import {Injector, bind} from 'angular2/core';

import {AppProtoView, AppView, AppViewContainer} from 'angular2/src/core/linker/view';
import {AppProtoView, AppView, AppViewContainer, ViewType} from 'angular2/src/core/linker/view';
import {ProtoViewRef, ViewRef, internalView} from 'angular2/src/core/linker/view_ref';
import {ElementRef} from 'angular2/src/core/linker/element_ref';
import {TemplateRef} from 'angular2/src/core/linker/template_ref';
Expand All @@ -25,7 +25,6 @@ import {
RenderViewRef,
RenderProtoViewRef,
RenderFragmentRef,
ViewType,
RenderViewWithFragments
} from 'angular2/src/core/render/api';
import {AppViewManager} from 'angular2/src/core/linker/view_manager';
Expand Down
9 changes: 7 additions & 2 deletions modules/angular2/test/core/linker/view_manager_utils_spec.ts
Expand Up @@ -26,7 +26,12 @@ import {
import {Injector, bind} from 'angular2/core';
import {isBlank, isPresent} from 'angular2/src/core/facade/lang';

import {AppProtoView, AppView, AppProtoViewMergeInfo} from 'angular2/src/core/linker/view';
import {
AppProtoView,
AppView,
AppProtoViewMergeInfo,
ViewType
} from 'angular2/src/core/linker/view';
import {ElementBinder} from 'angular2/src/core/linker/element_binder';
import {
DirectiveBinding,
Expand All @@ -37,7 +42,7 @@ import {
import {DirectiveResolver} from 'angular2/src/core/linker/directive_resolver';
import {Component} from 'angular2/src/core/metadata';
import {AppViewManagerUtils} from 'angular2/src/core/linker/view_manager_utils';
import {ViewType, RenderViewWithFragments} from 'angular2/src/core/render/render';
import {RenderViewWithFragments} from 'angular2/src/core/render/render';

export function main() {
// TODO(tbosch): add more tests here!
Expand Down