feat(decorators): adds decorators to be used by TS and Babel transpiled apps.
This commit is contained in:
8
modules/angular2/src/core/annotations/annotations.dart
Normal file
8
modules/angular2/src/core/annotations/annotations.dart
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* This indirection is needed for TS compilation path.
|
||||
* See comment in annotations.es6.
|
||||
*/
|
||||
|
||||
library angular2.core.annotations.annotations;
|
||||
|
||||
export "../annotations_impl/annotations.dart";
|
13
modules/angular2/src/core/annotations/annotations.es6
Normal file
13
modules/angular2/src/core/annotations/annotations.es6
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* This indirection is needed to free up Component, etc symbols in the public API
|
||||
* to be used by the decorator versions of these annotations.
|
||||
*/
|
||||
|
||||
export {
|
||||
Component as ComponentAnnotation,
|
||||
Decorator as DecoratorAnnotation,
|
||||
Directive as DirectiveAnnotation,
|
||||
DynamicComponent as DynamicComponentAnnotation,
|
||||
Viewport as ViewportAnnotation,
|
||||
onDestroy, onChange, onAllChangesDone
|
||||
} from '../annotations_impl/annotations';
|
1028
modules/angular2/src/core/annotations/annotations.js
vendored
1028
modules/angular2/src/core/annotations/annotations.js
vendored
File diff suppressed because it is too large
Load Diff
3
modules/angular2/src/core/annotations/di.dart
Normal file
3
modules/angular2/src/core/annotations/di.dart
Normal file
@ -0,0 +1,3 @@
|
||||
library angular2.core.annotations.di;
|
||||
|
||||
export "../annotations_impl/di.dart";
|
4
modules/angular2/src/core/annotations/di.es6
Normal file
4
modules/angular2/src/core/annotations/di.es6
Normal file
@ -0,0 +1,4 @@
|
||||
export {
|
||||
Query as QueryAnnotation,
|
||||
Attribute as AttributeAnnotation,
|
||||
} from '../annotations_impl/di';
|
63
modules/angular2/src/core/annotations/di.js
vendored
63
modules/angular2/src/core/annotations/di.js
vendored
@ -1,63 +0,0 @@
|
||||
import {CONST} from 'angular2/src/facade/lang';
|
||||
import {DependencyAnnotation} 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
|
||||
* @Decorator({
|
||||
* selector: `input'
|
||||
* })
|
||||
* class InputDecorator {
|
||||
* constructor(@Attribute('type') type) {
|
||||
* // type would be `text` in this example
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @exportedAs angular2/annotations
|
||||
*/
|
||||
export class Attribute extends DependencyAnnotation {
|
||||
attributeName: string;
|
||||
@CONST()
|
||||
constructor(attributeName) {
|
||||
super();
|
||||
this.attributeName = attributeName;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that a {@link QueryList} should be injected.
|
||||
*
|
||||
* See {@link QueryList} for usage and example.
|
||||
*
|
||||
* @exportedAs angular2/annotations
|
||||
*/
|
||||
export class Query extends DependencyAnnotation {
|
||||
directive;
|
||||
@CONST()
|
||||
constructor(directive) {
|
||||
super();
|
||||
this.directive = directive;
|
||||
}
|
||||
}
|
3
modules/angular2/src/core/annotations/view.dart
Normal file
3
modules/angular2/src/core/annotations/view.dart
Normal file
@ -0,0 +1,3 @@
|
||||
library angular2.core.annotations.view;
|
||||
|
||||
export "../annotations_impl/view.dart";
|
3
modules/angular2/src/core/annotations/view.es6
Normal file
3
modules/angular2/src/core/annotations/view.es6
Normal file
@ -0,0 +1,3 @@
|
||||
export {
|
||||
View as ViewAnnotation,
|
||||
} from '../annotations_impl/view';
|
98
modules/angular2/src/core/annotations/view.js
vendored
98
modules/angular2/src/core/annotations/view.js
vendored
@ -1,98 +0,0 @@
|
||||
import {ABSTRACT, CONST, Type} from 'angular2/src/facade/lang';
|
||||
|
||||
/**
|
||||
* 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 Component}.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* ```
|
||||
* @Component({
|
||||
* selector: 'greet'
|
||||
* })
|
||||
* @View({
|
||||
* template: 'Hello {{name}}!',
|
||||
* directives: [GreetUser, Bold]
|
||||
* })
|
||||
* class Greet {
|
||||
* name: string;
|
||||
*
|
||||
* constructor() {
|
||||
* this.name = 'World';
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @exportedAs angular2/annotations
|
||||
*/
|
||||
export class View {
|
||||
/**
|
||||
* 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 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 *for="item in items">{{item}}</li>
|
||||
* </ul>'
|
||||
* })
|
||||
* class MyComponent {
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
directives:List<Type>;
|
||||
|
||||
/**
|
||||
* Specify a custom renderer for this View.
|
||||
* If this is set, neither `template`, `templateURL` nor `directives` are used.
|
||||
*/
|
||||
renderer:any; // string;
|
||||
|
||||
@CONST()
|
||||
constructor({
|
||||
templateUrl,
|
||||
template,
|
||||
directives,
|
||||
renderer
|
||||
}: {
|
||||
templateUrl: string,
|
||||
template: string,
|
||||
directives: List<Type>,
|
||||
renderer: string
|
||||
})
|
||||
{
|
||||
this.templateUrl = templateUrl;
|
||||
this.template = template;
|
||||
this.directives = directives;
|
||||
this.renderer = renderer;
|
||||
}
|
||||
}
|
3
modules/angular2/src/core/annotations/visibility.dart
Normal file
3
modules/angular2/src/core/annotations/visibility.dart
Normal file
@ -0,0 +1,3 @@
|
||||
library angular2.core.annotations.visibility;
|
||||
|
||||
export "../annotations_impl/visibility.dart";
|
4
modules/angular2/src/core/annotations/visibility.es6
Normal file
4
modules/angular2/src/core/annotations/visibility.es6
Normal file
@ -0,0 +1,4 @@
|
||||
export {
|
||||
Ancestor as AncestorAnnotation,
|
||||
Parent as ParentAnnotation,
|
||||
} from '../annotations_impl/visibility';
|
111
modules/angular2/src/core/annotations/visibility.js
vendored
111
modules/angular2/src/core/annotations/visibility.js
vendored
@ -1,111 +0,0 @@
|
||||
import {CONST} from 'angular2/src/facade/lang';
|
||||
import {DependencyAnnotation} from 'angular2/di';
|
||||
|
||||
/**
|
||||
* Specifies that an injector should retrieve a dependency from the direct parent.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* Here is a simple directive that retrieves a dependency from its parent element.
|
||||
*
|
||||
* ```
|
||||
* @Decorator({
|
||||
* selector: '[dependency]',
|
||||
* properties: {
|
||||
* 'id':'dependency'
|
||||
* }
|
||||
* })
|
||||
* class Dependency {
|
||||
* id:string;
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @Decorator({
|
||||
* selector: '[my-directive]'
|
||||
* })
|
||||
* class Dependency {
|
||||
* constructor(@Parent() dependency:Dependency) {
|
||||
* expect(dependency.id).toEqual(1);
|
||||
* };
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* We use this with the following HTML template:
|
||||
*
|
||||
* ```
|
||||
* <div dependency="1">
|
||||
* <div dependency="2" my-directive></div>
|
||||
* </div>
|
||||
* ```
|
||||
* The `@Parent()` annotation in our constructor forces the injector to retrieve the dependency from the
|
||||
* parent element (even thought the current element could resolve it): Angular injects `dependency=1`.
|
||||
*
|
||||
* @exportedAs angular2/annotations
|
||||
*/
|
||||
export class Parent extends DependencyAnnotation {
|
||||
@CONST()
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that an injector should retrieve a dependency from any ancestor element.
|
||||
*
|
||||
* An ancestor is any element between the parent element and shadow root.
|
||||
*
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* Here is a simple directive that retrieves a dependency from an ancestor element.
|
||||
*
|
||||
* ```
|
||||
* @Decorator({
|
||||
* selector: '[dependency]',
|
||||
* properties: {
|
||||
* 'id':'dependency'
|
||||
* }
|
||||
* })
|
||||
* class Dependency {
|
||||
* id:string;
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @Decorator({
|
||||
* selector: '[my-directive]'
|
||||
* })
|
||||
* class Dependency {
|
||||
* constructor(@Ancestor() dependency:Dependency) {
|
||||
* expect(dependency.id).toEqual(2);
|
||||
* };
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* We use this with the following HTML template:
|
||||
*
|
||||
* ```
|
||||
* <div dependency="1">
|
||||
* <div dependency="2">
|
||||
* <div>
|
||||
* <div dependency="3" my-directive></div>
|
||||
* </div>
|
||||
* </div>
|
||||
* </div>
|
||||
* ```
|
||||
*
|
||||
* The `@Ancestor()` annotation in our constructor forces the injector to retrieve the dependency from the
|
||||
* nearest ancestor element:
|
||||
* - The current element `dependency="3"` is skipped because it is not an ancestor.
|
||||
* - Next parent has no directives `<div>`
|
||||
* - Next parent has the `Dependency` directive and so the dependency is satisfied.
|
||||
*
|
||||
* Angular injects `dependency=2`.
|
||||
*
|
||||
* @exportedAs angular2/annotations
|
||||
*/
|
||||
export class Ancestor extends DependencyAnnotation {
|
||||
@CONST()
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user