refactor(ProtoViewDto): switch to enum
This commit is contained in:
@ -161,8 +161,7 @@ export class Compiler {
|
||||
var protoView = protoViews[0];
|
||||
// TODO(tbosch): we should be caching host protoViews as well!
|
||||
// -> need a separate cache for this...
|
||||
if (renderPv.type === renderApi.ProtoViewDto.COMPONENT_VIEW_TYPE &&
|
||||
isPresent(componentBinding)) {
|
||||
if (renderPv.type === renderApi.ViewType.COMPONENT && isPresent(componentBinding)) {
|
||||
// Populate the cache before compiling the nested components,
|
||||
// so that components can reference themselves in their template.
|
||||
var component = componentBinding.key.token;
|
||||
|
@ -222,10 +222,10 @@ function _getChangeDetectorDefinitions(
|
||||
bindingRecordsCreator.getDirectiveRecords(elementBinders, allRenderDirectiveMetadata);
|
||||
var strategyName = DEFAULT;
|
||||
var typeString;
|
||||
if (pvWithIndex.renderProtoView.type === renderApi.ProtoViewDto.COMPONENT_VIEW_TYPE) {
|
||||
if (pvWithIndex.renderProtoView.type === renderApi.ViewType.COMPONENT) {
|
||||
strategyName = hostComponentMetadata.changeDetection;
|
||||
typeString = 'comp';
|
||||
} else if (pvWithIndex.renderProtoView.type === renderApi.ProtoViewDto.HOST_VIEW_TYPE) {
|
||||
} else if (pvWithIndex.renderProtoView.type === renderApi.ViewType.HOST) {
|
||||
typeString = 'host';
|
||||
} else {
|
||||
typeString = 'embedded';
|
||||
|
@ -92,28 +92,29 @@ export class DirectiveBinder {
|
||||
}
|
||||
}
|
||||
|
||||
export class ProtoViewDto {
|
||||
// A view that contains the host element with bound
|
||||
// component directive.
|
||||
// Contains a view of type #COMPONENT_VIEW_TYPE.
|
||||
static get HOST_VIEW_TYPE() { return 0; }
|
||||
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 views of type #EMBEDDED_VIEW_TYPE
|
||||
static get COMPONENT_VIEW_TYPE() { return 1; }
|
||||
// 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
|
||||
static get EMBEDDED_VIEW_TYPE() { return 2; }
|
||||
// inside of a COMPONENT view
|
||||
EMBEDDED
|
||||
}
|
||||
|
||||
export class ProtoViewDto {
|
||||
render: RenderProtoViewRef;
|
||||
elementBinders: List<ElementBinder>;
|
||||
variableBindings: Map<string, string>;
|
||||
type: number;
|
||||
type: ViewType;
|
||||
|
||||
constructor({render, elementBinders, variableBindings, type}: {
|
||||
render?: RenderProtoViewRef,
|
||||
elementBinders?: List<ElementBinder>,
|
||||
variableBindings?: Map<string, string>,
|
||||
type?: number
|
||||
type?: ViewType
|
||||
}) {
|
||||
this.render = render;
|
||||
this.elementBinders = elementBinders;
|
||||
|
@ -5,7 +5,7 @@ import {CompileElement} from './compile_element';
|
||||
import {CompileControl} from './compile_control';
|
||||
import {CompileStep} from './compile_step';
|
||||
import {ProtoViewBuilder} from '../view/proto_view_builder';
|
||||
import {ProtoViewDto} from '../../api';
|
||||
import {ProtoViewDto, ViewType} from '../../api';
|
||||
|
||||
/**
|
||||
* CompilePipeline for executing CompileSteps recursively for
|
||||
@ -15,10 +15,10 @@ export class CompilePipeline {
|
||||
_control: CompileControl;
|
||||
constructor(steps: List<CompileStep>) { this._control = new CompileControl(steps); }
|
||||
|
||||
process(rootElement, protoViewType: number = null,
|
||||
process(rootElement, protoViewType: ViewType = null,
|
||||
compilationCtxtDescription: string = ''): List<CompileElement> {
|
||||
if (isBlank(protoViewType)) {
|
||||
protoViewType = ProtoViewDto.COMPONENT_VIEW_TYPE;
|
||||
protoViewType = ViewType.COMPONENT;
|
||||
}
|
||||
var results = ListWrapper.create();
|
||||
var rootCompileElement = new CompileElement(rootElement, compilationCtxtDescription);
|
||||
|
@ -7,6 +7,7 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {
|
||||
ViewDefinition,
|
||||
ProtoViewDto,
|
||||
ViewType,
|
||||
DirectiveMetadata,
|
||||
RenderCompiler,
|
||||
RenderProtoViewRef
|
||||
@ -38,8 +39,7 @@ export class DomCompiler extends RenderCompiler {
|
||||
compile(template: ViewDefinition): Promise<ProtoViewDto> {
|
||||
var tplPromise = this._templateLoader.load(template);
|
||||
return PromiseWrapper.then(
|
||||
tplPromise, (el) => this._compileTemplate(template, el, ProtoViewDto.COMPONENT_VIEW_TYPE),
|
||||
(e) => {
|
||||
tplPromise, (el) => this._compileTemplate(template, el, ViewType.COMPONENT), (e) => {
|
||||
throw new BaseException(
|
||||
`Failed to load the template for "${template.componentId}" : ${e}`);
|
||||
});
|
||||
@ -52,11 +52,11 @@ export class DomCompiler extends RenderCompiler {
|
||||
directives: [directiveMetadata]
|
||||
});
|
||||
var element = DOM.createElement(directiveMetadata.selector);
|
||||
return this._compileTemplate(hostViewDef, element, ProtoViewDto.HOST_VIEW_TYPE);
|
||||
return this._compileTemplate(hostViewDef, element, ViewType.HOST);
|
||||
}
|
||||
|
||||
_compileTemplate(viewDef: ViewDefinition, tplElement,
|
||||
protoViewType: number): Promise<ProtoViewDto> {
|
||||
protoViewType: ViewType): Promise<ProtoViewDto> {
|
||||
var subTaskPromises = [];
|
||||
var pipeline = new CompilePipeline(this._stepFactory.createSteps(viewDef, subTaskPromises));
|
||||
var compileElements = pipeline.process(tplElement, protoViewType, viewDef.componentId);
|
||||
|
@ -23,7 +23,7 @@ export class ProtoViewBuilder {
|
||||
variableBindings: Map<string, string> = MapWrapper.create();
|
||||
elements: List<ElementBinderBuilder> = [];
|
||||
|
||||
constructor(public rootElement, public type: number) {}
|
||||
constructor(public rootElement, public type: api.ViewType) {}
|
||||
|
||||
bindElement(element, description = null): ElementBinderBuilder {
|
||||
var builder = new ElementBinderBuilder(this.elements.length, element, description);
|
||||
@ -187,7 +187,7 @@ export class ElementBinderBuilder {
|
||||
if (isPresent(this.nestedProtoView)) {
|
||||
throw new BaseException('Only one nested view per element is allowed');
|
||||
}
|
||||
this.nestedProtoView = new ProtoViewBuilder(rootElement, api.ProtoViewDto.EMBEDDED_VIEW_TYPE);
|
||||
this.nestedProtoView = new ProtoViewBuilder(rootElement, api.ViewType.EMBEDDED);
|
||||
return this.nestedProtoView;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ class _TemplateExtractor {
|
||||
new CompilePipeline(_factory.createSteps(viewDef, subtaskPromises));
|
||||
|
||||
var compileElements = pipeline.process(
|
||||
templateEl, ProtoViewDto.COMPONENT_VIEW_TYPE, viewDef.componentId);
|
||||
templateEl, ViewType.COMPONENT, viewDef.componentId);
|
||||
var protoViewDto = compileElements[0].inheritedProtoView
|
||||
.build(new PropertySetterFactory());
|
||||
|
||||
|
Reference in New Issue
Block a user