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:
Misko Hevery
2015-08-17 21:23:25 +00:00
committed by Miško Hevery
parent 5e6317fecc
commit ea6673947c
172 changed files with 1287 additions and 1173 deletions
+10 -10
View File
@@ -36,7 +36,7 @@ export class ElementPropertyBinding {
public property: string, public unit: string = null) {}
}
export class ElementBinder {
export class RenderElementBinder {
index: number;
parentIndex: number;
distanceToParent: number;
@@ -110,7 +110,7 @@ export enum ViewType {
export class ProtoViewDto {
render: RenderProtoViewRef;
elementBinders: List<ElementBinder>;
elementBinders: List<RenderElementBinder>;
variableBindings: Map<string, string>;
type: ViewType;
textBindings: List<ASTWithSource>;
@@ -119,7 +119,7 @@ export class ProtoViewDto {
constructor({render, elementBinders, variableBindings, type, textBindings,
transitiveNgContentCount}: {
render?: RenderProtoViewRef,
elementBinders?: List<ElementBinder>,
elementBinders?: List<RenderElementBinder>,
variableBindings?: Map<string, string>,
type?: ViewType,
textBindings?: List<ASTWithSource>,
@@ -134,7 +134,7 @@ export class ProtoViewDto {
}
}
export class DirectiveMetadata {
export class RenderDirectiveMetadata {
static get DIRECTIVE_TYPE() { return 0; }
static get COMPONENT_TYPE() { return 1; }
id: any;
@@ -220,7 +220,7 @@ export class DirectiveMetadata {
callOnAllChangesDone?: boolean,
changeDetection?: string,
exportAs?: string
}): DirectiveMetadata {
}): RenderDirectiveMetadata {
let hostListeners = new Map();
let hostProperties = new Map();
let hostAttributes = new Map();
@@ -228,7 +228,7 @@ export class DirectiveMetadata {
if (isPresent(host)) {
MapWrapper.forEach(host, (value: string, key: string) => {
var matches = RegExpWrapper.firstMatch(DirectiveMetadata._hostRegExp, key);
var matches = RegExpWrapper.firstMatch(RenderDirectiveMetadata._hostRegExp, key);
if (isBlank(matches)) {
hostAttributes.set(key, value);
} else if (isPresent(matches[1])) {
@@ -241,7 +241,7 @@ export class DirectiveMetadata {
});
}
return new DirectiveMetadata({
return new RenderDirectiveMetadata({
id: id,
selector: selector,
compileChildren: compileChildren,
@@ -296,7 +296,7 @@ export class ViewDefinition {
componentId: string;
templateAbsUrl: string;
template: string;
directives: List<DirectiveMetadata>;
directives: List<RenderDirectiveMetadata>;
styleAbsUrls: List<string>;
styles: List<string>;
encapsulation: ViewEncapsulation;
@@ -308,7 +308,7 @@ export class ViewDefinition {
template?: string,
styleAbsUrls?: List<string>,
styles?: List<string>,
directives?: List<DirectiveMetadata>,
directives?: List<RenderDirectiveMetadata>,
encapsulation?: ViewEncapsulation
} = {}) {
this.componentId = componentId;
@@ -348,7 +348,7 @@ export class RenderCompiler {
/**
* Creats a ProtoViewDto that contains a single nested component with the given componentId.
*/
compileHost(directiveMetadata: DirectiveMetadata): Promise<ProtoViewDto> { return null; }
compileHost(directiveMetadata: RenderDirectiveMetadata): Promise<ProtoViewDto> { return null; }
/**
* Compiles a single DomProtoView. Non recursive so that
@@ -8,7 +8,7 @@ import {
ViewDefinition,
ProtoViewDto,
ViewType,
DirectiveMetadata,
RenderDirectiveMetadata,
RenderCompiler,
RenderProtoViewRef,
RenderProtoViewMergeMapping,
@@ -50,7 +50,7 @@ export class DomCompiler extends RenderCompiler {
});
}
compileHost(directiveMetadata: DirectiveMetadata): Promise<ProtoViewDto> {
compileHost(directiveMetadata: RenderDirectiveMetadata): Promise<ProtoViewDto> {
let hostViewDef = new ViewDefinition({
componentId: directiveMetadata.id,
templateAbsUrl: null, template: null,
@@ -9,7 +9,7 @@ import {CompileStep} from './compile_step';
import {CompileElement} from './compile_element';
import {CompileControl} from './compile_control';
import {DirectiveMetadata} from '../../api';
import {RenderDirectiveMetadata} from '../../api';
import {dashCaseToCamelCase, camelCaseToDashCase, EVENT_TARGET_SEPARATOR} from '../util';
import {DirectiveBuilder, ElementBinderBuilder} from '../view/proto_view_builder';
@@ -20,7 +20,7 @@ import {DirectiveBuilder, ElementBinderBuilder} from '../view/proto_view_builder
export class DirectiveParser implements CompileStep {
_selectorMatcher: SelectorMatcher = new SelectorMatcher();
constructor(public _parser: Parser, public _directives: List<DirectiveMetadata>) {
constructor(public _parser: Parser, public _directives: List<RenderDirectiveMetadata>) {
for (var i = 0; i < _directives.length; i++) {
var directive = _directives[i];
var selector = CssSelector.parse(directive.selector);
@@ -48,7 +48,7 @@ export class DirectiveParser implements CompileStep {
var directive = this._directives[directiveIndex];
elementBinder = current.bindElement();
if (directive.type === DirectiveMetadata.COMPONENT_TYPE) {
if (directive.type === RenderDirectiveMetadata.COMPONENT_TYPE) {
this._ensureHasOnlyOneComponent(elementBinder, current.elementDescription);
// components need to go first, so it is easier to locate them in the result.
+4 -4
View File
@@ -1,12 +1,12 @@
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
import {isPresent, isArray} from 'angular2/src/facade/lang';
import {DirectiveMetadata} from 'angular2/src/render/api';
import {RenderDirectiveMetadata} from 'angular2/src/render/api';
/**
* Converts a [DirectiveMetadata] to a map representation. This creates a copy,
* that is, subsequent changes to `meta` will not be mirrored in the map.
*/
export function directiveMetadataToMap(meta: DirectiveMetadata): Map<string, any> {
export function directiveMetadataToMap(meta: RenderDirectiveMetadata): Map<string, any> {
return MapWrapper.createFromPairs([
['id', meta.id],
['selector', meta.selector],
@@ -35,8 +35,8 @@ export function directiveMetadataToMap(meta: DirectiveMetadata): Map<string, any
* [DirectiveMetadata] object. This creates a copy, that is, subsequent changes
* to `map` will not be mirrored in the [DirectiveMetadata] object.
*/
export function directiveMetadataFromMap(map: Map<string, any>): DirectiveMetadata {
return new DirectiveMetadata({
export function directiveMetadataFromMap(map: Map<string, any>): RenderDirectiveMetadata {
return new RenderDirectiveMetadata({
id:<string>map.get('id'),
selector:<string>map.get('selector'),
compileChildren:<boolean>map.get('compileChildren'),
@@ -23,7 +23,16 @@ import {DomElementBinder, Event, HostAction} from './element_binder';
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
import {TemplateCloner} from '../template_cloner';
import * as api from '../../api';
import {
ViewType,
ViewEncapsulation,
ProtoViewDto,
DirectiveBinder,
RenderElementBinder,
EventBinding,
ElementPropertyBinding,
PropertyBindingType
} from '../../api';
import {
NG_BINDING_CLASS,
@@ -39,8 +48,8 @@ export class ProtoViewBuilder {
ngContentCount: number = 0;
hostAttributes: Map<string, string> = new Map();
constructor(public rootElement, public type: api.ViewType,
public viewEncapsulation: api.ViewEncapsulation) {}
constructor(public rootElement, public type: ViewType,
public viewEncapsulation: ViewEncapsulation) {}
bindElement(element: HTMLElement, description: string = null): ElementBinderBuilder {
var builder = new ElementBinderBuilder(this.elements.length, element, description);
@@ -70,7 +79,7 @@ export class ProtoViewBuilder {
setHostAttribute(name: string, value: string) { this.hostAttributes.set(name, value); }
build(schemaRegistry: ElementSchemaRegistry, templateCloner: TemplateCloner): api.ProtoViewDto {
build(schemaRegistry: ElementSchemaRegistry, templateCloner: TemplateCloner): ProtoViewDto {
var domElementBinders = [];
var apiElementBinders = [];
@@ -89,7 +98,7 @@ export class ProtoViewBuilder {
ebb.eventBuilder.merge(dbb.eventBuilder);
ListWrapper.forEach(dbb.templatePropertyNames,
(name) => directiveTemplatePropertyNames.add(name));
return new api.DirectiveBinder({
return new DirectiveBinder({
directiveIndex: dbb.directiveIndex,
propertyBindings: dbb.propertyBindings,
eventBindings: dbb.eventBindings,
@@ -109,7 +118,7 @@ export class ProtoViewBuilder {
textNodeExpressions.push(expression);
textNodeIndices.push(nodeIndex);
});
apiElementBinders.push(new api.ElementBinder({
apiElementBinders.push(new RenderElementBinder({
index: ebb.index,
parentIndex: parentIndex,
distanceToParent: ebb.distanceToParent,
@@ -132,7 +141,7 @@ export class ProtoViewBuilder {
}));
});
var rootNodeCount = DOM.childNodes(DOM.content(this.rootElement)).length;
return new api.ProtoViewDto({
return new ProtoViewDto({
render: new DomProtoViewRef(DomProtoView.create(
templateCloner, this.type, this.rootElement, this.viewEncapsulation, [rootNodeCount],
rootTextNodeIndices, domElementBinders, this.hostAttributes)),
@@ -152,7 +161,7 @@ export class ElementBinderBuilder {
nestedProtoView: ProtoViewBuilder = null;
propertyBindings: Map<string, ASTWithSource> = new Map();
variableBindings: Map<string, string> = new Map();
eventBindings: List<api.EventBinding> = [];
eventBindings: List<EventBinding> = [];
eventBuilder: EventBuilder = new EventBuilder();
textBindings: Map<Node, ASTWithSource> = new Map();
readAttributes: Map<string, string> = new Map();
@@ -185,7 +194,7 @@ export class ElementBinderBuilder {
throw new BaseException('Only one nested view per element is allowed');
}
this.nestedProtoView =
new ProtoViewBuilder(rootElement, api.ViewType.EMBEDDED, api.ViewEncapsulation.NONE);
new ProtoViewBuilder(rootElement, ViewType.EMBEDDED, ViewEncapsulation.NONE);
return this.nestedProtoView;
}
@@ -230,7 +239,7 @@ export class DirectiveBuilder {
// property names used in the template
templatePropertyNames: List<string> = [];
hostPropertyBindings: Map<string, ASTWithSource> = new Map();
eventBindings: List<api.EventBinding> = [];
eventBindings: List<EventBinding> = [];
eventBuilder: EventBuilder = new EventBuilder();
constructor(public directiveIndex: number) {}
@@ -261,14 +270,14 @@ export class EventBuilder extends AstTransformer {
constructor() { super(); }
add(name: string, source: ASTWithSource, target: string): api.EventBinding {
add(name: string, source: ASTWithSource, target: string): EventBinding {
// TODO(tbosch): reenable this when we are parsing element properties
// out of action expressions
// var adjustedAst = astWithSource.ast.visit(this);
var adjustedAst = source.ast;
var fullName = isPresent(target) ? target + EVENT_TARGET_SEPARATOR + name : name;
var result = new api.EventBinding(
fullName, new ASTWithSource(adjustedAst, source.source, source.location));
var result =
new EventBinding(fullName, new ASTWithSource(adjustedAst, source.source, source.location));
var event = new Event(name, target, fullName);
if (isBlank(target)) {
this.localEvents.push(event);
@@ -331,7 +340,7 @@ const STYLE_PREFIX = 'style';
function buildElementPropertyBindings(
schemaRegistry: ElementSchemaRegistry, protoElement: /*element*/ any, isNgComponent: boolean,
bindingsInTemplate: Map<string, ASTWithSource>, directiveTemplatePropertyNames: Set<string>):
List<api.ElementPropertyBinding> {
List<ElementPropertyBinding> {
var propertyBindings = [];
MapWrapper.forEach(bindingsInTemplate, (ast, propertyNameInTemplate) => {
@@ -361,8 +370,8 @@ function buildElementPropertyBindings(
function isValidElementPropertyBinding(schemaRegistry: ElementSchemaRegistry,
protoElement: /*element*/ any, isNgComponent: boolean,
binding: api.ElementPropertyBinding): boolean {
if (binding.type === api.PropertyBindingType.PROPERTY) {
binding: ElementPropertyBinding): boolean {
if (binding.type === PropertyBindingType.PROPERTY) {
if (!isNgComponent) {
return schemaRegistry.hasProperty(protoElement, binding.property);
} else {
@@ -374,19 +383,19 @@ function isValidElementPropertyBinding(schemaRegistry: ElementSchemaRegistry,
}
function createElementPropertyBinding(schemaRegistry: ElementSchemaRegistry, ast: ASTWithSource,
propertyNameInTemplate: string): api.ElementPropertyBinding {
propertyNameInTemplate: string): ElementPropertyBinding {
var parts = StringWrapper.split(propertyNameInTemplate, PROPERTY_PARTS_SEPARATOR);
if (parts.length === 1) {
var propName = schemaRegistry.getMappedPropName(parts[0]);
return new api.ElementPropertyBinding(api.PropertyBindingType.PROPERTY, ast, propName);
return new ElementPropertyBinding(PropertyBindingType.PROPERTY, ast, propName);
} else if (parts[0] == ATTRIBUTE_PREFIX) {
return new api.ElementPropertyBinding(api.PropertyBindingType.ATTRIBUTE, ast, parts[1]);
return new ElementPropertyBinding(PropertyBindingType.ATTRIBUTE, ast, parts[1]);
} else if (parts[0] == CLASS_PREFIX) {
return new api.ElementPropertyBinding(api.PropertyBindingType.CLASS, ast,
camelCaseToDashCase(parts[1]));
return new ElementPropertyBinding(PropertyBindingType.CLASS, ast,
camelCaseToDashCase(parts[1]));
} else if (parts[0] == STYLE_PREFIX) {
var unit = parts.length > 2 ? parts[2] : null;
return new api.ElementPropertyBinding(api.PropertyBindingType.STYLE, ast, parts[1], unit);
return new ElementPropertyBinding(PropertyBindingType.STYLE, ast, parts[1], unit);
} else {
throw new BaseException(`Invalid property name ${propertyNameInTemplate}`);
}