refactor: rename annotations to metadata
BREAKING CHANGE (maybe) Well as long as our customers use public API this should not be a breaking change, but we have changed import structure as well as internal names, so it could be breaking. import: angular2/annotations => angular2/metadata Classes: *Annotations => *Metadata renderer.DirectiveMetadata => renderer.RendererDirectiveMetadata renderer.ElementBinder => renderer.RendererElementBinder impl.Directive => impl.DirectiveMetadata impl.Component => impl.ComponentMetadata impl.View => impl.ViewMetadata Closes #3660
This commit is contained in:

committed by
Miško Hevery

parent
5e6317fecc
commit
ea6673947c
@ -20,7 +20,7 @@ import {ProtoViewRef} from './view_ref';
|
||||
import {DirectiveBinding} from './element_injector';
|
||||
import {ViewResolver} from './view_resolver';
|
||||
import {PipeResolver} from './pipe_resolver';
|
||||
import {View} from '../annotations_impl/view';
|
||||
import {ViewMetadata} from 'angular2/metadata';
|
||||
import {ComponentUrlMapper} from './component_url_mapper';
|
||||
import {ProtoViewFactory} from './proto_view_factory';
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
@ -30,7 +30,14 @@ import {wtfStartTimeRange, wtfEndTimeRange} from '../../profile/profile';
|
||||
import {PipeBinding} from '../pipes/pipe_binding';
|
||||
import {DEFAULT_PIPES_TOKEN} from 'angular2/pipes';
|
||||
|
||||
import * as renderApi from 'angular2/src/render/api';
|
||||
import {
|
||||
RenderDirectiveMetadata,
|
||||
ViewDefinition,
|
||||
RenderCompiler,
|
||||
ViewType,
|
||||
RenderProtoViewMergeMapping,
|
||||
RenderProtoViewRef
|
||||
} from 'angular2/src/render/api';
|
||||
|
||||
/**
|
||||
* Cache that stores the AppProtoView of the template of a component.
|
||||
@ -97,8 +104,8 @@ export class Compiler {
|
||||
@Inject(DEFAULT_PIPES_TOKEN) _defaultPipes: Type[],
|
||||
private _compilerCache: CompilerCache, private _viewResolver: ViewResolver,
|
||||
private _componentUrlMapper: ComponentUrlMapper, private _urlResolver: UrlResolver,
|
||||
private _render: renderApi.RenderCompiler,
|
||||
private _protoViewFactory: ProtoViewFactory, appUrl: AppRootUrl) {
|
||||
private _render: RenderCompiler, private _protoViewFactory: ProtoViewFactory,
|
||||
appUrl: AppRootUrl) {
|
||||
this._defaultPipes = _defaultPipes;
|
||||
this._appUrl = appUrl.value;
|
||||
}
|
||||
@ -215,7 +222,7 @@ export class Compiler {
|
||||
componentPath: Map<Type, AppProtoView>): Promise<AppProtoView> {
|
||||
var nestedPVPromises = [];
|
||||
componentPath = MapWrapper.clone(componentPath);
|
||||
if (appProtoViews[0].type === renderApi.ViewType.COMPONENT) {
|
||||
if (appProtoViews[0].type === ViewType.COMPONENT) {
|
||||
componentPath.set(componentType, appProtoViews[0]);
|
||||
}
|
||||
appProtoViews.forEach(appProtoView => {
|
||||
@ -230,7 +237,7 @@ export class Compiler {
|
||||
if (appProtoView.isEmbeddedFragment) {
|
||||
throw new BaseException(
|
||||
`<ng-content> is used within the recursive path of ${stringify(nestedComponentType)}`);
|
||||
} else if (appProtoView.type === renderApi.ViewType.COMPONENT) {
|
||||
} else if (appProtoView.type === ViewType.COMPONENT) {
|
||||
throw new BaseException(
|
||||
`Unconditional component cycle in ${stringify(nestedComponentType)}`);
|
||||
} else {
|
||||
@ -253,18 +260,17 @@ export class Compiler {
|
||||
}
|
||||
|
||||
private _mergeProtoView(appProtoView: AppProtoView): Promise<any> {
|
||||
if (appProtoView.type !== renderApi.ViewType.HOST &&
|
||||
appProtoView.type !== renderApi.ViewType.EMBEDDED) {
|
||||
if (appProtoView.type !== ViewType.HOST && appProtoView.type !== ViewType.EMBEDDED) {
|
||||
return null;
|
||||
}
|
||||
return this._render.mergeProtoViewsRecursively(this._collectMergeRenderProtoViews(appProtoView))
|
||||
.then((mergeResult: renderApi.RenderProtoViewMergeMapping) => {
|
||||
.then((mergeResult: RenderProtoViewMergeMapping) => {
|
||||
appProtoView.mergeMapping = new AppProtoViewMergeMapping(mergeResult);
|
||||
});
|
||||
}
|
||||
|
||||
private _collectMergeRenderProtoViews(
|
||||
appProtoView: AppProtoView): List<renderApi.RenderProtoViewRef | List<any>> {
|
||||
private _collectMergeRenderProtoViews(appProtoView:
|
||||
AppProtoView): List<RenderProtoViewRef | List<any>> {
|
||||
var result = [appProtoView.render];
|
||||
for (var i = 0; i < appProtoView.elementBinders.length; i++) {
|
||||
var binder = appProtoView.elementBinders[i];
|
||||
@ -290,7 +296,7 @@ export class Compiler {
|
||||
return componentElementBinders;
|
||||
}
|
||||
|
||||
private _buildRenderTemplate(component, view, directives): renderApi.ViewDefinition {
|
||||
private _buildRenderTemplate(component, view, directives): ViewDefinition {
|
||||
var componentUrl =
|
||||
this._urlResolver.resolve(this._appUrl, this._componentUrlMapper.getUrl(component));
|
||||
var templateAbsUrl = null;
|
||||
@ -307,7 +313,7 @@ export class Compiler {
|
||||
styleAbsUrls =
|
||||
ListWrapper.map(view.styleUrls, url => this._urlResolver.resolve(componentUrl, url));
|
||||
}
|
||||
return new renderApi.ViewDefinition({
|
||||
return new ViewDefinition({
|
||||
componentId: stringify(component),
|
||||
templateAbsUrl: templateAbsUrl, template: view.template,
|
||||
styleAbsUrls: styleAbsUrls,
|
||||
@ -317,14 +323,14 @@ export class Compiler {
|
||||
});
|
||||
}
|
||||
|
||||
private _flattenPipes(view: View): any[] {
|
||||
private _flattenPipes(view: ViewMetadata): any[] {
|
||||
if (isBlank(view.pipes)) return this._defaultPipes;
|
||||
var pipes = ListWrapper.clone(this._defaultPipes);
|
||||
this._flattenList(view.pipes, pipes);
|
||||
return pipes;
|
||||
}
|
||||
|
||||
private _flattenDirectives(view: View): List<Type> {
|
||||
private _flattenDirectives(view: ViewMetadata): List<Type> {
|
||||
if (isBlank(view.directives)) return [];
|
||||
var directives = [];
|
||||
this._flattenList(view.directives, directives);
|
||||
@ -347,7 +353,7 @@ export class Compiler {
|
||||
}
|
||||
|
||||
private static _assertTypeIsComponent(directiveBinding: DirectiveBinding): void {
|
||||
if (directiveBinding.metadata.type !== renderApi.DirectiveMetadata.COMPONENT_TYPE) {
|
||||
if (directiveBinding.metadata.type !== RenderDirectiveMetadata.COMPONENT_TYPE) {
|
||||
throw new BaseException(
|
||||
`Could not load '${stringify(directiveBinding.key.token)}' because it is not a component.`);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import {Type, isPresent} from 'angular2/src/facade/lang';
|
||||
import {Map, MapWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
/**
|
||||
* Resolve a `Type` from a {@link Component} into a URL.
|
||||
* Resolve a `Type` from a {@link ComponentMetadata} into a URL.
|
||||
*
|
||||
* This interface can be overridden by the application developer to create custom behavior.
|
||||
*
|
||||
|
@ -1,10 +1,10 @@
|
||||
library angular2.src.core.compiler.directive_lifecycle_reflector;
|
||||
|
||||
import 'package:angular2/src/core/annotations_impl/annotations.dart';
|
||||
import 'package:angular2/src/core/metadata.dart';
|
||||
import 'package:angular2/src/core/compiler/interfaces.dart';
|
||||
import 'package:angular2/src/reflection/reflection.dart';
|
||||
|
||||
bool hasLifecycleHook(LifecycleEvent e, type, Directive annotation) {
|
||||
bool hasLifecycleHook(LifecycleEvent e, type, DirectiveMetadata annotation) {
|
||||
if (annotation.lifecycle != null) {
|
||||
return annotation.lifecycle.contains(e);
|
||||
} else {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Type, isPresent} from 'angular2/src/facade/lang';
|
||||
import {LifecycleEvent, Directive} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {LifecycleEvent, DirectiveMetadata} from 'angular2/metadata';
|
||||
|
||||
export function hasLifecycleHook(e: LifecycleEvent, type, annotation: Directive): boolean {
|
||||
export function hasLifecycleHook(e: LifecycleEvent, type, annotation: DirectiveMetadata): boolean {
|
||||
if (isPresent(annotation.lifecycle)) {
|
||||
return annotation.lifecycle.indexOf(e) !== -1;
|
||||
} else {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import {resolveForwardRef, Injectable} from 'angular2/di';
|
||||
import {Type, isPresent, BaseException, stringify} from 'angular2/src/facade/lang';
|
||||
import {Directive} from '../annotations_impl/annotations';
|
||||
import {DirectiveMetadata} from 'angular2/metadata';
|
||||
import {reflector} from 'angular2/src/reflection/reflection';
|
||||
|
||||
/**
|
||||
* Resolve a `Type` for {@link Directive}.
|
||||
* Resolve a `Type` for {@link DirectiveMetadata}.
|
||||
*
|
||||
* This interface can be overridden by the application developer to create custom behavior.
|
||||
*
|
||||
@ -13,14 +13,14 @@ import {reflector} from 'angular2/src/reflection/reflection';
|
||||
@Injectable()
|
||||
export class DirectiveResolver {
|
||||
/**
|
||||
* Return {@link Directive} for a given `Type`.
|
||||
* Return {@link DirectiveMetadata} for a given `Type`.
|
||||
*/
|
||||
resolve(type: Type): Directive {
|
||||
resolve(type: Type): DirectiveMetadata {
|
||||
var annotations = reflector.annotations(resolveForwardRef(type));
|
||||
if (isPresent(annotations)) {
|
||||
for (var i = 0; i < annotations.length; i++) {
|
||||
var annotation = annotations[i];
|
||||
if (annotation instanceof Directive) {
|
||||
if (annotation instanceof DirectiveMetadata) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
|
@ -31,19 +31,19 @@ import {
|
||||
BindingWithVisibility
|
||||
} from 'angular2/src/di/injector';
|
||||
|
||||
import {Attribute, Query} from 'angular2/src/core/annotations_impl/di';
|
||||
import {AttributeMetadata, QueryMetadata} from '../metadata/di';
|
||||
|
||||
import * as viewModule from './view';
|
||||
import * as avmModule from './view_manager';
|
||||
import {ViewContainerRef} from './view_container_ref';
|
||||
import {ElementRef} from './element_ref';
|
||||
import {TemplateRef} from './template_ref';
|
||||
import {Directive, Component, LifecycleEvent} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {DirectiveMetadata, ComponentMetadata, LifecycleEvent} from '../metadata/directives';
|
||||
import {hasLifecycleHook} from './directive_lifecycle_reflector';
|
||||
import {ChangeDetector, ChangeDetectorRef} from 'angular2/src/change_detection/change_detection';
|
||||
import {QueryList} from './query_list';
|
||||
import {reflector} from 'angular2/src/reflection/reflection';
|
||||
import {DirectiveMetadata} from 'angular2/src/render/api';
|
||||
import {RenderDirectiveMetadata} from 'angular2/src/render/api';
|
||||
import {PipeBinding} from '../pipes/pipe_binding';
|
||||
|
||||
var _staticKeys;
|
||||
@ -160,7 +160,7 @@ export class TreeNode<T extends TreeNode<any>> {
|
||||
export class DirectiveDependency extends Dependency {
|
||||
constructor(key: Key, optional: boolean, lowerBoundVisibility: Object,
|
||||
upperBoundVisibility: Object, properties: List<any>, public attributeName: string,
|
||||
public queryDecorator: Query) {
|
||||
public queryDecorator: QueryMetadata) {
|
||||
super(key, optional, lowerBoundVisibility, upperBoundVisibility, properties);
|
||||
this._verify();
|
||||
}
|
||||
@ -181,12 +181,12 @@ export class DirectiveDependency extends Dependency {
|
||||
}
|
||||
|
||||
static _attributeName(properties): string {
|
||||
var p = <Attribute>ListWrapper.find(properties, (p) => p instanceof Attribute);
|
||||
var p = <AttributeMetadata>ListWrapper.find(properties, (p) => p instanceof AttributeMetadata);
|
||||
return isPresent(p) ? p.attributeName : null;
|
||||
}
|
||||
|
||||
static _query(properties): Query {
|
||||
return <Query>ListWrapper.find(properties, (p) => p instanceof Query);
|
||||
static _query(properties): QueryMetadata {
|
||||
return <QueryMetadata>ListWrapper.find(properties, (p) => p instanceof QueryMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ export class DirectiveBinding extends ResolvedBinding {
|
||||
constructor(key: Key, factory: Function, dependencies: List<Dependency>,
|
||||
public resolvedBindings: List<ResolvedBinding>,
|
||||
public resolvedViewBindings: List<ResolvedBinding>,
|
||||
public metadata: DirectiveMetadata) {
|
||||
public metadata: RenderDirectiveMetadata) {
|
||||
super(key, factory, dependencies);
|
||||
}
|
||||
|
||||
@ -218,21 +218,21 @@ export class DirectiveBinding extends ResolvedBinding {
|
||||
|
||||
get changeDetection() { return this.metadata.changeDetection; }
|
||||
|
||||
static createFromBinding(binding: Binding, ann: Directive): DirectiveBinding {
|
||||
static createFromBinding(binding: Binding, ann: DirectiveMetadata): DirectiveBinding {
|
||||
if (isBlank(ann)) {
|
||||
ann = new Directive();
|
||||
ann = new DirectiveMetadata();
|
||||
}
|
||||
|
||||
var rb = binding.resolve();
|
||||
var deps = ListWrapper.map(rb.dependencies, DirectiveDependency.createFrom);
|
||||
var resolvedBindings = isPresent(ann.bindings) ? Injector.resolve(ann.bindings) : [];
|
||||
var resolvedViewBindings = ann instanceof Component && isPresent(ann.viewBindings) ?
|
||||
var resolvedViewBindings = ann instanceof ComponentMetadata && isPresent(ann.viewBindings) ?
|
||||
Injector.resolve(ann.viewBindings) :
|
||||
[];
|
||||
var metadata = DirectiveMetadata.create({
|
||||
var metadata = RenderDirectiveMetadata.create({
|
||||
id: stringify(rb.key.token),
|
||||
type: ann instanceof Component ? DirectiveMetadata.COMPONENT_TYPE :
|
||||
DirectiveMetadata.DIRECTIVE_TYPE,
|
||||
type: ann instanceof ComponentMetadata ? RenderDirectiveMetadata.COMPONENT_TYPE :
|
||||
RenderDirectiveMetadata.DIRECTIVE_TYPE,
|
||||
selector: ann.selector,
|
||||
compileChildren: ann.compileChildren,
|
||||
events: ann.events,
|
||||
@ -246,7 +246,7 @@ export class DirectiveBinding extends ResolvedBinding {
|
||||
callOnInit: hasLifecycleHook(LifecycleEvent.onInit, rb.key.token, ann),
|
||||
callOnAllChangesDone: hasLifecycleHook(LifecycleEvent.onAllChangesDone, rb.key.token, ann),
|
||||
|
||||
changeDetection: ann instanceof Component ? ann.changeDetection : null,
|
||||
changeDetection: ann instanceof ComponentMetadata ? ann.changeDetection : null,
|
||||
|
||||
exportAs: ann.exportAs
|
||||
});
|
||||
@ -264,7 +264,7 @@ export class DirectiveBinding extends ResolvedBinding {
|
||||
return readAttributes;
|
||||
}
|
||||
|
||||
static createFromType(type: Type, annotation: Directive): DirectiveBinding {
|
||||
static createFromType(type: Type, annotation: DirectiveMetadata): DirectiveBinding {
|
||||
var binding = new Binding(type, {toClass: type});
|
||||
return DirectiveBinding.createFromBinding(binding, annotation);
|
||||
}
|
||||
@ -608,7 +608,7 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
||||
if (dirDep.key.id === StaticKeys.instance().changeDetectorRefId) {
|
||||
// We provide the component's view change detector to components and
|
||||
// the surrounding component's change detector to directives.
|
||||
if (dirBin.metadata.type === DirectiveMetadata.COMPONENT_TYPE) {
|
||||
if (dirBin.metadata.type === RenderDirectiveMetadata.COMPONENT_TYPE) {
|
||||
var componentView = this._preBuiltObjects.view.getNestedView(
|
||||
this._preBuiltObjects.elementRef.boundElementIndex);
|
||||
return componentView.changeDetector.ref;
|
||||
@ -713,7 +713,7 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
||||
matched.forEach(s => queryRef.list.add(s));
|
||||
}
|
||||
|
||||
private _createQueryRef(query: Query): void {
|
||||
private _createQueryRef(query: QueryMetadata): void {
|
||||
var queryList = new QueryList<any>();
|
||||
if (isBlank(this._query0)) {
|
||||
this._query0 = new QueryRef(query, queryList, this);
|
||||
@ -726,7 +726,7 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
|
||||
}
|
||||
}
|
||||
|
||||
addDirectivesMatchingQuery(query: Query, list: any[]): void {
|
||||
addDirectivesMatchingQuery(query: QueryMetadata, list: any[]): void {
|
||||
var templateRef = this._preBuiltObjects.templateRef;
|
||||
if (query.selector === TemplateRef && isPresent(templateRef)) {
|
||||
list.push(templateRef);
|
||||
@ -873,7 +873,7 @@ interface _ElementInjectorStrategy {
|
||||
getComponent(): any;
|
||||
isComponentKey(key: Key): boolean;
|
||||
buildQueries(): void;
|
||||
addDirectivesMatchingQuery(q: Query, res: any[]): void;
|
||||
addDirectivesMatchingQuery(q: QueryMetadata, res: any[]): void;
|
||||
getComponentBinding(): DirectiveBinding;
|
||||
hydrate(): void;
|
||||
dehydrate(): void;
|
||||
@ -1006,7 +1006,7 @@ class ElementInjectorInlineStrategy implements _ElementInjectorStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
addDirectivesMatchingQuery(query: Query, list: any[]): void {
|
||||
addDirectivesMatchingQuery(query: QueryMetadata, list: any[]): void {
|
||||
var i = this.injectorStrategy;
|
||||
var p = i.protoStrategy;
|
||||
|
||||
@ -1112,7 +1112,7 @@ class ElementInjectorDynamicStrategy implements _ElementInjectorStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
addDirectivesMatchingQuery(query: Query, list: any[]): void {
|
||||
addDirectivesMatchingQuery(query: QueryMetadata, list: any[]): void {
|
||||
var ist = this.injectorStrategy;
|
||||
var p = ist.protoStrategy;
|
||||
|
||||
@ -1144,7 +1144,7 @@ export class QueryError extends BaseException {
|
||||
}
|
||||
|
||||
export class QueryRef {
|
||||
constructor(public query: Query, public list: QueryList<any>,
|
||||
constructor(public query: QueryMetadata, public list: QueryList<any>,
|
||||
public originator: ElementInjector) {}
|
||||
|
||||
get isViewQuery(): boolean { return this.query.isViewQuery; }
|
||||
|
@ -1,10 +1,10 @@
|
||||
import {resolveForwardRef, Injectable} from 'angular2/di';
|
||||
import {Type, isPresent, BaseException, stringify} from 'angular2/src/facade/lang';
|
||||
import {Pipe} from '../annotations_impl/annotations';
|
||||
import {PipeMetadata} from '../metadata/directives';
|
||||
import {reflector} from 'angular2/src/reflection/reflection';
|
||||
|
||||
/**
|
||||
* Resolve a `Type` for {@link Pipe}.
|
||||
* Resolve a `Type` for {@link PipeMetadata}.
|
||||
*
|
||||
* This interface can be overridden by the application developer to create custom behavior.
|
||||
*
|
||||
@ -13,14 +13,14 @@ import {reflector} from 'angular2/src/reflection/reflection';
|
||||
@Injectable()
|
||||
export class PipeResolver {
|
||||
/**
|
||||
* Return {@link Pipe} for a given `Type`.
|
||||
* Return {@link PipeMetadata} for a given `Type`.
|
||||
*/
|
||||
resolve(type: Type): Pipe {
|
||||
resolve(type: Type): PipeMetadata {
|
||||
var metas = reflector.annotations(resolveForwardRef(type));
|
||||
if (isPresent(metas)) {
|
||||
for (var i = 0; i < metas.length; i++) {
|
||||
var annotation = metas[i];
|
||||
if (annotation instanceof Pipe) {
|
||||
if (annotation instanceof PipeMetadata) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,14 @@ import {
|
||||
import {PipeBinding} from 'angular2/src/core/pipes/pipe_binding';
|
||||
import {ProtoPipes} from 'angular2/src/core/pipes/pipes';
|
||||
|
||||
import * as renderApi from 'angular2/src/render/api';
|
||||
import {
|
||||
RenderDirectiveMetadata,
|
||||
RenderElementBinder,
|
||||
PropertyBindingType,
|
||||
DirectiveBinder,
|
||||
ProtoViewDto,
|
||||
ViewType
|
||||
} from 'angular2/src/render/api';
|
||||
import {AppProtoView} from './view';
|
||||
import {ElementBinder} from './element_binder';
|
||||
import {ProtoElementInjector, DirectiveBinding} from './element_injector';
|
||||
@ -26,8 +33,8 @@ import {ProtoElementInjector, DirectiveBinding} from './element_injector';
|
||||
export class BindingRecordsCreator {
|
||||
_directiveRecordsMap: Map<number, DirectiveRecord> = new Map();
|
||||
|
||||
getEventBindingRecords(elementBinders: List<renderApi.ElementBinder>,
|
||||
allDirectiveMetadatas: renderApi.DirectiveMetadata[]): BindingRecord[] {
|
||||
getEventBindingRecords(elementBinders: List<RenderElementBinder>,
|
||||
allDirectiveMetadatas: RenderDirectiveMetadata[]): BindingRecord[] {
|
||||
var res = [];
|
||||
for (var boundElementIndex = 0; boundElementIndex < elementBinders.length;
|
||||
boundElementIndex++) {
|
||||
@ -41,16 +48,15 @@ export class BindingRecordsCreator {
|
||||
}
|
||||
|
||||
private _createTemplateEventRecords(res: BindingRecord[],
|
||||
renderElementBinder: renderApi.ElementBinder,
|
||||
renderElementBinder: RenderElementBinder,
|
||||
boundElementIndex: number): void {
|
||||
renderElementBinder.eventBindings.forEach(eb => {
|
||||
res.push(BindingRecord.createForEvent(eb.source, eb.fullName, boundElementIndex));
|
||||
});
|
||||
}
|
||||
|
||||
private _createHostEventRecords(res: BindingRecord[],
|
||||
renderElementBinder: renderApi.ElementBinder,
|
||||
allDirectiveMetadatas: renderApi.DirectiveMetadata[],
|
||||
private _createHostEventRecords(res: BindingRecord[], renderElementBinder: RenderElementBinder,
|
||||
allDirectiveMetadatas: RenderDirectiveMetadata[],
|
||||
boundElementIndex: number): void {
|
||||
for (var i = 0; i < renderElementBinder.directives.length; ++i) {
|
||||
var dir = renderElementBinder.directives[i];
|
||||
@ -63,9 +69,9 @@ export class BindingRecordsCreator {
|
||||
}
|
||||
|
||||
getPropertyBindingRecords(textBindings: List<ASTWithSource>,
|
||||
elementBinders: List<renderApi.ElementBinder>,
|
||||
elementBinders: List<RenderElementBinder>,
|
||||
allDirectiveMetadatas:
|
||||
List<renderApi.DirectiveMetadata>): List<BindingRecord> {
|
||||
List<RenderDirectiveMetadata>): List<BindingRecord> {
|
||||
var bindings = [];
|
||||
|
||||
this._createTextNodeRecords(bindings, textBindings);
|
||||
@ -80,9 +86,8 @@ export class BindingRecordsCreator {
|
||||
return bindings;
|
||||
}
|
||||
|
||||
getDirectiveRecords(elementBinders: List<renderApi.ElementBinder>,
|
||||
allDirectiveMetadatas:
|
||||
List<renderApi.DirectiveMetadata>): List<DirectiveRecord> {
|
||||
getDirectiveRecords(elementBinders: List<RenderElementBinder>,
|
||||
allDirectiveMetadatas: List<RenderDirectiveMetadata>): List<DirectiveRecord> {
|
||||
var directiveRecords = [];
|
||||
|
||||
for (var elementIndex = 0; elementIndex < elementBinders.length; ++elementIndex) {
|
||||
@ -103,18 +108,18 @@ export class BindingRecordsCreator {
|
||||
}
|
||||
|
||||
_createElementPropertyRecords(bindings: List<BindingRecord>, boundElementIndex: number,
|
||||
renderElementBinder: renderApi.ElementBinder) {
|
||||
renderElementBinder: RenderElementBinder) {
|
||||
ListWrapper.forEach(renderElementBinder.propertyBindings, (binding) => {
|
||||
if (binding.type === renderApi.PropertyBindingType.PROPERTY) {
|
||||
if (binding.type === PropertyBindingType.PROPERTY) {
|
||||
bindings.push(BindingRecord.createForElementProperty(binding.astWithSource,
|
||||
boundElementIndex, binding.property));
|
||||
} else if (binding.type === renderApi.PropertyBindingType.ATTRIBUTE) {
|
||||
} else if (binding.type === PropertyBindingType.ATTRIBUTE) {
|
||||
bindings.push(BindingRecord.createForElementAttribute(binding.astWithSource,
|
||||
boundElementIndex, binding.property));
|
||||
} else if (binding.type === renderApi.PropertyBindingType.CLASS) {
|
||||
} else if (binding.type === PropertyBindingType.CLASS) {
|
||||
bindings.push(BindingRecord.createForElementClass(binding.astWithSource, boundElementIndex,
|
||||
binding.property));
|
||||
} else if (binding.type === renderApi.PropertyBindingType.STYLE) {
|
||||
} else if (binding.type === PropertyBindingType.STYLE) {
|
||||
bindings.push(BindingRecord.createForElementStyle(binding.astWithSource, boundElementIndex,
|
||||
binding.property, binding.unit));
|
||||
}
|
||||
@ -122,8 +127,8 @@ export class BindingRecordsCreator {
|
||||
}
|
||||
|
||||
_createDirectiveRecords(bindings: List<BindingRecord>, boundElementIndex: number,
|
||||
directiveBinders: List<renderApi.DirectiveBinder>,
|
||||
allDirectiveMetadatas: List<renderApi.DirectiveMetadata>) {
|
||||
directiveBinders: List<DirectiveBinder>,
|
||||
allDirectiveMetadatas: List<RenderDirectiveMetadata>) {
|
||||
for (var i = 0; i < directiveBinders.length; i++) {
|
||||
var directiveBinder = directiveBinders[i];
|
||||
var directiveMetadata = allDirectiveMetadatas[directiveBinder.directiveIndex];
|
||||
@ -154,16 +159,16 @@ export class BindingRecordsCreator {
|
||||
// host properties
|
||||
ListWrapper.forEach(directiveBinder.hostPropertyBindings, (binding) => {
|
||||
var dirIndex = new DirectiveIndex(boundElementIndex, i);
|
||||
if (binding.type === renderApi.PropertyBindingType.PROPERTY) {
|
||||
if (binding.type === PropertyBindingType.PROPERTY) {
|
||||
bindings.push(BindingRecord.createForHostProperty(dirIndex, binding.astWithSource,
|
||||
binding.property));
|
||||
} else if (binding.type === renderApi.PropertyBindingType.ATTRIBUTE) {
|
||||
} else if (binding.type === PropertyBindingType.ATTRIBUTE) {
|
||||
bindings.push(BindingRecord.createForHostAttribute(dirIndex, binding.astWithSource,
|
||||
binding.property));
|
||||
} else if (binding.type === renderApi.PropertyBindingType.CLASS) {
|
||||
} else if (binding.type === PropertyBindingType.CLASS) {
|
||||
bindings.push(
|
||||
BindingRecord.createForHostClass(dirIndex, binding.astWithSource, binding.property));
|
||||
} else if (binding.type === renderApi.PropertyBindingType.STYLE) {
|
||||
} else if (binding.type === PropertyBindingType.STYLE) {
|
||||
bindings.push(BindingRecord.createForHostStyle(dirIndex, binding.astWithSource,
|
||||
binding.property, binding.unit));
|
||||
}
|
||||
@ -172,7 +177,7 @@ export class BindingRecordsCreator {
|
||||
}
|
||||
|
||||
_getDirectiveRecord(boundElementIndex: number, directiveIndex: number,
|
||||
directiveMetadata: renderApi.DirectiveMetadata): DirectiveRecord {
|
||||
directiveMetadata: RenderDirectiveMetadata): DirectiveRecord {
|
||||
var id = boundElementIndex * 100 + directiveIndex;
|
||||
|
||||
if (!this._directiveRecordsMap.has(id)) {
|
||||
@ -198,8 +203,7 @@ export class ProtoViewFactory {
|
||||
*/
|
||||
constructor(public _changeDetection: ChangeDetection) {}
|
||||
|
||||
createAppProtoViews(hostComponentBinding: DirectiveBinding,
|
||||
rootRenderProtoView: renderApi.ProtoViewDto,
|
||||
createAppProtoViews(hostComponentBinding: DirectiveBinding, rootRenderProtoView: ProtoViewDto,
|
||||
allDirectives: List<DirectiveBinding>, pipes: PipeBinding[]): AppProtoView[] {
|
||||
var allRenderDirectiveMetadata =
|
||||
ListWrapper.map(allDirectives, directiveBinding => directiveBinding.metadata);
|
||||
@ -233,8 +237,8 @@ export class ProtoViewFactory {
|
||||
* for the given ProtoView and all nested ProtoViews.
|
||||
*/
|
||||
export function getChangeDetectorDefinitions(
|
||||
hostComponentMetadata: renderApi.DirectiveMetadata, rootRenderProtoView: renderApi.ProtoViewDto,
|
||||
allRenderDirectiveMetadata: List<renderApi.DirectiveMetadata>): List<ChangeDetectorDefinition> {
|
||||
hostComponentMetadata: RenderDirectiveMetadata, rootRenderProtoView: ProtoViewDto,
|
||||
allRenderDirectiveMetadata: List<RenderDirectiveMetadata>): List<ChangeDetectorDefinition> {
|
||||
var nestedPvsWithIndex = _collectNestedProtoViews(rootRenderProtoView);
|
||||
var nestedPvVariableNames = _collectNestedProtoViewsVariableNames(nestedPvsWithIndex);
|
||||
return _getChangeDetectorDefinitions(hostComponentMetadata, nestedPvsWithIndex,
|
||||
@ -242,7 +246,7 @@ export function getChangeDetectorDefinitions(
|
||||
}
|
||||
|
||||
function _collectNestedProtoViews(
|
||||
renderProtoView: renderApi.ProtoViewDto, parentIndex: number = null, boundElementIndex = null,
|
||||
renderProtoView: ProtoViewDto, parentIndex: number = null, boundElementIndex = null,
|
||||
result: List<RenderProtoViewWithIndex> = null): List<RenderProtoViewWithIndex> {
|
||||
if (isBlank(result)) {
|
||||
result = [];
|
||||
@ -263,9 +267,9 @@ function _collectNestedProtoViews(
|
||||
}
|
||||
|
||||
function _getChangeDetectorDefinitions(
|
||||
hostComponentMetadata: renderApi.DirectiveMetadata,
|
||||
hostComponentMetadata: RenderDirectiveMetadata,
|
||||
nestedPvsWithIndex: List<RenderProtoViewWithIndex>, nestedPvVariableNames: List<List<string>>,
|
||||
allRenderDirectiveMetadata: List<renderApi.DirectiveMetadata>): List<ChangeDetectorDefinition> {
|
||||
allRenderDirectiveMetadata: List<RenderDirectiveMetadata>): List<ChangeDetectorDefinition> {
|
||||
return ListWrapper.map(nestedPvsWithIndex, (pvWithIndex) => {
|
||||
var elementBinders = pvWithIndex.renderProtoView.elementBinders;
|
||||
var bindingRecordsCreator = new BindingRecordsCreator();
|
||||
@ -277,10 +281,10 @@ function _getChangeDetectorDefinitions(
|
||||
bindingRecordsCreator.getDirectiveRecords(elementBinders, allRenderDirectiveMetadata);
|
||||
var strategyName = DEFAULT;
|
||||
var typeString;
|
||||
if (pvWithIndex.renderProtoView.type === renderApi.ViewType.COMPONENT) {
|
||||
if (pvWithIndex.renderProtoView.type === ViewType.COMPONENT) {
|
||||
strategyName = hostComponentMetadata.changeDetection;
|
||||
typeString = 'comp';
|
||||
} else if (pvWithIndex.renderProtoView.type === renderApi.ViewType.HOST) {
|
||||
} else if (pvWithIndex.renderProtoView.type === ViewType.HOST) {
|
||||
typeString = 'host';
|
||||
} else {
|
||||
typeString = 'embedded';
|
||||
@ -293,7 +297,7 @@ function _getChangeDetectorDefinitions(
|
||||
}
|
||||
|
||||
function _createAppProtoView(
|
||||
renderProtoView: renderApi.ProtoViewDto, protoChangeDetector: ProtoChangeDetector,
|
||||
renderProtoView: ProtoViewDto, protoChangeDetector: ProtoChangeDetector,
|
||||
variableBindings: Map<string, string>, allDirectives: List<DirectiveBinding>,
|
||||
pipes: PipeBinding[]): AppProtoView {
|
||||
var elementBinders = renderProtoView.elementBinders;
|
||||
@ -346,7 +350,7 @@ function _createVariableNames(parentVariableNames: List<string>, renderProtoView
|
||||
return res;
|
||||
}
|
||||
|
||||
export function createVariableLocations(elementBinders: List<renderApi.ElementBinder>):
|
||||
export function createVariableLocations(elementBinders: List<RenderElementBinder>):
|
||||
Map<string, number> {
|
||||
var variableLocations = new Map();
|
||||
for (var i = 0; i < elementBinders.length; i++) {
|
||||
@ -368,7 +372,7 @@ function _createElementBinders(protoView, elementBinders, allDirectiveBindings)
|
||||
ListWrapper.map(dirs, (dir) => allDirectiveBindings[dir.directiveIndex]);
|
||||
var componentDirectiveBinding = null;
|
||||
if (directiveBindings.length > 0) {
|
||||
if (directiveBindings[0].metadata.type === renderApi.DirectiveMetadata.COMPONENT_TYPE) {
|
||||
if (directiveBindings[0].metadata.type === RenderDirectiveMetadata.COMPONENT_TYPE) {
|
||||
componentDirectiveBinding = directiveBindings[0];
|
||||
}
|
||||
}
|
||||
@ -439,7 +443,7 @@ function _createElementBinder(protoView: AppProtoView, boundElementIndex, render
|
||||
return elBinder;
|
||||
}
|
||||
|
||||
export function createDirectiveVariableBindings(renderElementBinder: renderApi.ElementBinder,
|
||||
export function createDirectiveVariableBindings(renderElementBinder: RenderElementBinder,
|
||||
directiveBindings: List<DirectiveBinding>):
|
||||
Map<string, number> {
|
||||
var directiveVariableBindings = new Map();
|
||||
@ -478,7 +482,7 @@ function _findDirectiveIndexByExportAs(renderElementBinder, directiveBindings, e
|
||||
function _directiveExportAs(directive): string {
|
||||
var directiveExportAs = directive.metadata.exportAs;
|
||||
if (isBlank(directiveExportAs) &&
|
||||
directive.metadata.type === renderApi.DirectiveMetadata.COMPONENT_TYPE) {
|
||||
directive.metadata.type === RenderDirectiveMetadata.COMPONENT_TYPE) {
|
||||
return "$implicit";
|
||||
} else {
|
||||
return directiveExportAs;
|
||||
@ -486,7 +490,7 @@ function _directiveExportAs(directive): string {
|
||||
}
|
||||
|
||||
class RenderProtoViewWithIndex {
|
||||
constructor(public renderProtoView: renderApi.ProtoViewDto, public index: number,
|
||||
constructor(public renderProtoView: ProtoViewDto, public index: number,
|
||||
public parentIndex: number, public boundElementIndex: number) {}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {View} from 'angular2/src/core/annotations_impl/view';
|
||||
import {ViewMetadata} from '../metadata/view';
|
||||
|
||||
import {Type, stringify, isBlank, BaseException} from 'angular2/src/facade/lang';
|
||||
import {Map, MapWrapper, List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
@ -11,7 +11,7 @@ import {reflector} from 'angular2/src/reflection/reflection';
|
||||
export class ViewResolver {
|
||||
_cache: Map<Type, /*node*/ any> = new Map();
|
||||
|
||||
resolve(component: Type): View {
|
||||
resolve(component: Type): ViewMetadata {
|
||||
var view = this._cache.get(component);
|
||||
|
||||
if (isBlank(view)) {
|
||||
@ -22,11 +22,11 @@ export class ViewResolver {
|
||||
return view;
|
||||
}
|
||||
|
||||
_resolve(component: Type): View {
|
||||
_resolve(component: Type): ViewMetadata {
|
||||
var annotations = reflector.annotations(component);
|
||||
for (var i = 0; i < annotations.length; i++) {
|
||||
var annotation = annotations[i];
|
||||
if (annotation instanceof View) {
|
||||
if (annotation instanceof ViewMetadata) {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user