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
84
modules/angular2/src/core/metadata/di.ts
Normal file
84
modules/angular2/src/core/metadata/di.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import {CONST, Type, stringify, isPresent, StringWrapper, isString} from 'angular2/src/facade/lang';
|
||||
import {DependencyMetadata} from 'angular2/src/di/metadata';
|
||||
import {resolveForwardRef} from 'angular2/di';
|
||||
|
||||
/**
|
||||
* Specifies that a constant attribute value should be injected.
|
||||
*
|
||||
* The directive can inject constant string literals of host element attributes.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* Suppose we have an `<input>` element and want to know its `type`.
|
||||
*
|
||||
* ```html
|
||||
* <input type="text">
|
||||
* ```
|
||||
*
|
||||
* A decorator can inject string literal `text` like so:
|
||||
*
|
||||
* ```javascript
|
||||
* @Directive({
|
||||
* selector: `input'
|
||||
* })
|
||||
* class InputDirective {
|
||||
* constructor(@Attribute('type') type) {
|
||||
* // type would be `text` in this example
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
@CONST()
|
||||
export class AttributeMetadata extends DependencyMetadata {
|
||||
constructor(public attributeName: string) { super(); }
|
||||
|
||||
get token() {
|
||||
// Normally one would default a token to a type of an injected value but here
|
||||
// the type of a variable is "string" and we can't use primitive type as a return value
|
||||
// so we use instance of Attribute instead. This doesn't matter much in practice as arguments
|
||||
// with @Attribute annotation are injected by ElementInjector that doesn't take tokens into
|
||||
// account.
|
||||
return this;
|
||||
}
|
||||
toString(): string { return `@Attribute(${stringify(this.attributeName)})`; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that a {@link QueryList} should be injected.
|
||||
*
|
||||
* See {@link QueryList} for usage and example.
|
||||
*/
|
||||
@CONST()
|
||||
export class QueryMetadata extends DependencyMetadata {
|
||||
descendants: boolean;
|
||||
constructor(private _selector: Type | string,
|
||||
{descendants = false}: {descendants?: boolean} = {}) {
|
||||
super();
|
||||
this.descendants = descendants;
|
||||
}
|
||||
|
||||
get isViewQuery() { return false; }
|
||||
|
||||
get selector() { return resolveForwardRef(this._selector); }
|
||||
|
||||
get isVarBindingQuery(): boolean { return isString(this.selector); }
|
||||
|
||||
get varBindings(): List<string> { return StringWrapper.split(this.selector, new RegExp(",")); }
|
||||
|
||||
toString(): string { return `@Query(${stringify(this.selector)})`; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that a {@link QueryList} should be injected.
|
||||
*
|
||||
* See {@link QueryList} for usage and example.
|
||||
*/
|
||||
@CONST()
|
||||
export class ViewQueryMetadata extends QueryMetadata {
|
||||
constructor(_selector: Type | string, {descendants = false}: {descendants?: boolean} = {}) {
|
||||
super(_selector, {descendants: descendants});
|
||||
}
|
||||
|
||||
get isViewQuery() { return true; }
|
||||
toString(): string { return `@ViewQuery(${stringify(this.selector)})`; }
|
||||
}
|
1032
modules/angular2/src/core/metadata/directives.ts
Normal file
1032
modules/angular2/src/core/metadata/directives.ts
Normal file
File diff suppressed because it is too large
Load Diff
117
modules/angular2/src/core/metadata/view.ts
Normal file
117
modules/angular2/src/core/metadata/view.ts
Normal file
@ -0,0 +1,117 @@
|
||||
import {ABSTRACT, CONST, Type} from 'angular2/src/facade/lang';
|
||||
import {ViewEncapsulation} from 'angular2/src/render/api';
|
||||
|
||||
export {ViewEncapsulation} from 'angular2/src/render/api';
|
||||
|
||||
/**
|
||||
* Declares the available HTML templates for an application.
|
||||
*
|
||||
* Each angular component requires a single `@Component` and at least one `@View` annotation. The
|
||||
* `@View` annotation specifies the HTML template to use, and lists the directives that are active
|
||||
* within the template.
|
||||
*
|
||||
* When a component is instantiated, the template is loaded into the component's shadow root, and
|
||||
* the expressions and statements in the template are evaluated against the component.
|
||||
*
|
||||
* For details on the `@Component` annotation, see {@link ComponentMetadata}.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* ```
|
||||
* @Component({
|
||||
* selector: 'greet'
|
||||
* })
|
||||
* @View({
|
||||
* template: 'Hello {{name}}!',
|
||||
* directives: [GreetUser, Bold]
|
||||
* })
|
||||
* class Greet {
|
||||
* name: string;
|
||||
*
|
||||
* constructor() {
|
||||
* this.name = 'World';
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
@CONST()
|
||||
export class ViewMetadata {
|
||||
/**
|
||||
* Specifies a template URL for an angular component.
|
||||
*
|
||||
* NOTE: either `templateUrl` or `template` should be used, but not both.
|
||||
*/
|
||||
templateUrl: string;
|
||||
|
||||
/**
|
||||
* Specifies an inline template for an angular component.
|
||||
*
|
||||
* NOTE: either `templateUrl` or `template` should be used, but not both.
|
||||
*/
|
||||
template: string;
|
||||
|
||||
/**
|
||||
* Specifies stylesheet URLs for an angular component.
|
||||
*/
|
||||
styleUrls: List<string>;
|
||||
|
||||
/**
|
||||
* Specifies an inline stylesheet for an angular component.
|
||||
*/
|
||||
styles: List<string>;
|
||||
|
||||
/**
|
||||
* Specifies a list of directives that can be used within a template.
|
||||
*
|
||||
* Directives must be listed explicitly to provide proper component encapsulation.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* ```javascript
|
||||
* @Component({
|
||||
* selector: 'my-component'
|
||||
* })
|
||||
* @View({
|
||||
* directives: [For]
|
||||
* template: '
|
||||
* <ul>
|
||||
* <li *ng-for="#item of items">{{item}}</li>
|
||||
* </ul>'
|
||||
* })
|
||||
* class MyComponent {
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
// TODO(tbosch): use Type | Binding | List<any> when Dart supports union types,
|
||||
// as otherwise we would need to import Binding type and Dart would warn
|
||||
// for an unused import.
|
||||
directives: List<Type | any | List<any>>;
|
||||
|
||||
pipes: List<Type | any | List<any>>;
|
||||
|
||||
/**
|
||||
* Specify how the template and the styles should be encapsulated.
|
||||
* The default is {@link ViewEncapsulation#EMULATED `ViewEncapsulation.EMULATED`} if the view
|
||||
* has styles,
|
||||
* otherwise {@link ViewEncapsulation#NONE `ViewEncapsulation.NONE`}.
|
||||
*/
|
||||
encapsulation: ViewEncapsulation;
|
||||
|
||||
constructor({templateUrl, template, directives, pipes, encapsulation, styles, styleUrls}: {
|
||||
templateUrl?: string,
|
||||
template?: string,
|
||||
directives?: List<Type | any | List<any>>,
|
||||
pipes?: List<Type | any | List<any>>,
|
||||
encapsulation?: ViewEncapsulation,
|
||||
styles?: List<string>,
|
||||
styleUrls?: List<string>,
|
||||
} = {}) {
|
||||
this.templateUrl = templateUrl;
|
||||
this.template = template;
|
||||
this.styleUrls = styleUrls;
|
||||
this.styles = styles;
|
||||
this.directives = directives;
|
||||
this.pipes = pipes;
|
||||
this.encapsulation = encapsulation;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user