feat(decorators): adds decorator versions of DI annotations.

In 'angular2/di' the symbol:
- Inject is a decorator
- InjectAnnotation is an annotation

Internally one an get a hold of annotations without *Annotations appened
(to make ts2dart work without workarounds) by importing from
'angular2/src/di/annotations_impl' instead of 'angular2/di'. This is
needed only for users that transpile through TS and through ts2dart.
This commit is contained in:
Rado Kirov
2015-05-04 11:11:22 -07:00
parent 28feac9411
commit 457c15cd6c
52 changed files with 121 additions and 74 deletions
+1 -2
View File
@@ -8,10 +8,9 @@ import {BindingRecord} from './binding_record';
import {DirectiveRecord} from './directive_record';
import {DEFAULT} from './constants';
import {ChangeDetection, ProtoChangeDetector} from './interfaces';
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {List} from 'angular2/src/facade/collection';
/**
* Structural diffing for `Object`s and `Map`s.
*
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {List, ListWrapper, SetWrapper} from "angular2/src/facade/collection";
import {int, NumberWrapper, StringJoiner, StringWrapper} from "angular2/src/facade/lang";
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {int, isBlank, isPresent, BaseException, StringWrapper, RegExpWrapper} from 'angular2/src/facade/lang';
import {ListWrapper, List} from 'angular2/src/facade/collection';
import {Lexer, EOF, Token, $PERIOD, $COLON, $SEMICOLON, $LBRACKET, $RBRACKET,
@@ -1,7 +1,7 @@
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {isBlank, isPresent, BaseException, CONST} from 'angular2/src/facade/lang';
import {Pipe} from './pipe';
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {ChangeDetectorRef} from '../change_detector_ref';
@Injectable()
@@ -0,0 +1,23 @@
import {
ComponentAnnotation,
DirectiveAnnotation
} from './annotations';
import {ViewAnnotation} from './view';
import {AncestorAnnotation, ParentAnnotation} from './visibility';
import {AttributeAnnotation, QueryAnnotation} from './di';
import {makeDecorator, makeParamDecorator} from '../../util/decorators';
/* from annotations */
export var Component = makeDecorator(ComponentAnnotation);
export var Decorator = makeDecorator(DirectiveAnnotation);
/* from view */
export var View = makeDecorator(ViewAnnotation);
/* from visibility */
export var Ancestor = makeParamDecorator(AncestorAnnotation);
export var Parent = makeParamDecorator(ParentAnnotation);
/* from di */
export var Attribute = makeParamDecorator(AttributeAnnotation);
export var Query = makeParamDecorator(QueryAnnotation);
+1 -1
View File
@@ -1,6 +1,6 @@
import {CONST, normalizeBlank, isPresent} from 'angular2/src/facade/lang';
import {ListWrapper, List} from 'angular2/src/facade/collection';
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {DEFAULT} from 'angular2/change_detection';
// type StringMap = {[idx: string]: string};
+1 -1
View File
@@ -1,5 +1,5 @@
import {CONST} from 'angular2/src/facade/lang';
import {DependencyAnnotation} from 'angular2/di';
import {DependencyAnnotation} from 'angular2/src/di/annotations_impl';
/**
* Specifies that a constant attribute value should be injected.
+1 -1
View File
@@ -1,5 +1,5 @@
import {CONST} from 'angular2/src/facade/lang';
import {DependencyAnnotation} from 'angular2/di';
import {DependencyAnnotation} from 'angular2/src/di/annotations_impl';
/**
* Specifies that an injector should retrieve a dependency from the direct parent.
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injector, bind, OpaqueToken, Optional} from 'angular2/di';
import {Injector, bind, OpaqueToken} from 'angular2/di';
import {NumberWrapper, Type, isBlank, isPresent, BaseException,
assertionsEnabled, print, stringify} from 'angular2/src/facade/lang';
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
+2 -1
View File
@@ -1,4 +1,5 @@
import {Injectable, Binding} from 'angular2/di';
import {Binding} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {Type, isBlank, isPresent, BaseException, normalizeBlank, stringify} from 'angular2/src/facade/lang';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {Type, isPresent} from 'angular2/src/facade/lang';
import {Map, MapWrapper} from 'angular2/src/facade/collection';
@@ -1,4 +1,5 @@
import {Injectable, Injector} from 'angular2/di';
import {Injector} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {Type, isPresent, BaseException, stringify} from 'angular2/src/facade/lang';
import {Directive, Component} from '../annotations_impl/annotations';
import {DirectiveMetadata} from './directive_metadata';
@@ -1,4 +1,5 @@
import {Key, Injector, Injectable, ResolvedBinding, Binding, bind} from 'angular2/di'
import {Key, Injector, ResolvedBinding, Binding, bind} from 'angular2/di'
import {Injectable} from 'angular2/src/di/annotations_impl';
import {Compiler} from './compiler';
import {Type, BaseException, stringify, isPresent} from 'angular2/src/facade/lang';
import {Promise} from 'angular2/src/facade/async';
+3 -2
View File
@@ -1,4 +1,5 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
import {isPresent, isBlank} from 'angular2/src/facade/lang';
import {reflector} from 'angular2/src/reflection/reflection';
@@ -29,7 +30,7 @@ class BindingRecordsCreator {
bindings = ListWrapper.concat(bindings, this._createElementPropertyRecords(boundElementIndex, renderElementBinder));
bindings = ListWrapper.concat(bindings, this._createDirectiveRecords(boundElementIndex, sortedDirectives[boundElementIndex]));
}
return bindings;
}
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {View} from 'angular2/src/core/annotations_impl/view';
import {Type, stringify, isBlank, BaseException} from 'angular2/src/facade/lang';
+3 -2
View File
@@ -1,4 +1,5 @@
import {Injector, Injectable, Binding} from 'angular2/di';
import {Injector, Binding} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
import {isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
import * as viewModule from './view';
@@ -216,4 +217,4 @@ export class AppViewManager {
}
view.render = null;
}
}
}
+3 -2
View File
@@ -1,4 +1,5 @@
import {Injectable, Injector, Binding} from 'angular2/di';
import {Injector, Binding} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
import * as eli from './element_injector';
import {isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
@@ -241,4 +242,4 @@ export class AppViewManagerUtils {
view.changeDetector.dehydrate();
}
}
}
+3 -2
View File
@@ -1,4 +1,5 @@
import {Inject, OpaqueToken} from 'angular2/di';
import {Inject} from 'angular2/src/di/annotations_impl';
import {ListWrapper, MapWrapper, Map, List} from 'angular2/src/facade/collection';
import {isPresent, isBlank} from 'angular2/src/facade/lang';
@@ -37,4 +38,4 @@ export class AppViewPool {
}
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {isPresent, print} from 'angular2/src/facade/lang';
import {ListWrapper, isListLikeIterable} from 'angular2/src/facade/collection';
import {DOM} from 'angular2/src/dom/dom_adapter';
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {ChangeDetector} from 'angular2/change_detection';
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {DOM} from 'angular2/src/dom/dom_adapter';
import {Map, MapWrapper, List, ListWrapper} from 'angular2/src/facade/collection';
import {StringWrapper, isBlank, BaseException} from 'angular2/src/facade/lang';
+3
View File
@@ -0,0 +1,3 @@
library angular2.di.annotations;
export './annotations_impl.dart';
+13
View 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 {
Inject as InjectAnnotation,
InjectPromise as InjectPromiseAnnotation,
InjectLazy as InjectLazyAnnotation,
Optional as OptionalAnnotation,
Injectable as InjectableAnnotation,
DependencyAnnotation, // abstract base class, does not need a decorator
} from './annotations_impl';
+1 -1
View File
@@ -2,7 +2,7 @@ import {Type, isBlank, isPresent, CONST} from 'angular2/src/facade/lang';
import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {reflector} from 'angular2/src/reflection/reflection';
import {Key} from './key';
import {Inject, InjectLazy, InjectPromise, Optional, DependencyAnnotation} from './annotations';
import {Inject, InjectLazy, InjectPromise, Optional, DependencyAnnotation} from './annotations_impl';
import {NoAnnotationError} from './exceptions';
/**
+3
View File
@@ -0,0 +1,3 @@
library angular2.di.decorators;
/* This file is empty because, Dart does not have decorators. */
+13
View File
@@ -0,0 +1,13 @@
import {
InjectAnnotation,
InjectPromiseAnnotation,
InjectLazyAnnotation,
OptionalAnnotation,
InjectableAnnotation} from './annotations';
import {makeDecorator, makeParamDecorator} from '../util/decorators';
export var Inject = makeParamDecorator(InjectAnnotation);
export var InjectPromise = makeParamDecorator(InjectPromiseAnnotation);
export var InjectLazy = makeParamDecorator(InjectLazyAnnotation);
export var Optional = makeParamDecorator(OptionalAnnotation);
export var Injectable = makeDecorator(InjectableAnnotation);
+1 -1
View File
@@ -1,7 +1,7 @@
import {Directive, onChange} from 'angular2/src/core/annotations_impl/annotations';
import {Ancestor} from 'angular2/src/core/annotations_impl/visibility';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {Optional} from 'angular2/di';
import {Optional} from 'angular2/src/di/annotations_impl';
import {Renderer} from 'angular2/src/render/api';
import {isPresent, isString} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection';
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
import {BaseException} from 'angular2/src/facade/lang';
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {isBlank, isPresent, BaseException, stringify} from 'angular2/src/facade/lang';
import {Map, MapWrapper, StringMapWrapper, StringMap} from 'angular2/src/facade/collection';
import {PromiseWrapper, Promise} from 'angular2/src/facade/async';
+2 -1
View File
@@ -1,4 +1,5 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {List, ListWrapper} from 'angular2/src/facade/collection';
import {isBlank, isPresent, BaseException} from 'angular2/src/facade/lang';
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {XHR} from 'angular2/src/services/xhr';
import {ListWrapper} from 'angular2/src/facade/collection';
@@ -1,7 +1,7 @@
// Some of the code comes from WebComponents.JS
// https://github.com/webcomponents/webcomponentsjs/blob/master/src/HTMLImports/path.js
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {RegExp, RegExpWrapper, StringWrapper} from 'angular2/src/facade/lang';
import {UrlResolver} from 'angular2/src/services/url_resolver';
+1 -1
View File
@@ -1,4 +1,4 @@
import {OpaqueToken, Inject, Injectable} from 'angular2/di';
import {Inject, Injectable} from 'angular2/src/di/annotations_impl';
import {int, isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {int, isPresent, isBlank, BaseException} from 'angular2/src/facade/lang';
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {isPresent, isBlank, RegExpWrapper, BaseException} from 'angular2/src/facade/lang';
import {DOM} from 'angular2/src/dom/dom_adapter';
+1 -1
View File
@@ -1,4 +1,4 @@
import {Injectable} from 'angular2/di';
import {Injectable} from 'angular2/src/di/annotations_impl';
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
import {XHR} from './xhr';
@@ -1,13 +1,6 @@
import {
ComponentAnnotation,
DirectiveAnnotation
} from '../annotations/annotations';
import {ViewAnnotation} from '../annotations/view';
import {AncestorAnnotation, ParentAnnotation} from '../annotations/visibility';
import {AttributeAnnotation, QueryAnnotation} from '../annotations/di';
import {global} from 'angular2/src/facade/lang';
function makeDecorator(annotationCls) {
export function makeDecorator(annotationCls) {
return function(...args) {
var Reflect = global.Reflect;
if (!(Reflect && Reflect.getMetadata)) {
@@ -24,7 +17,7 @@ function makeDecorator(annotationCls) {
}
}
function makeParamDecorator(annotationCls) {
export function makeParamDecorator(annotationCls) {
return function(...args) {
var Reflect = global.Reflect;
if (!(Reflect && Reflect.getMetadata)) {
@@ -45,18 +38,3 @@ function makeParamDecorator(annotationCls) {
}
}
}
/* from annotations */
export var Component = makeDecorator(ComponentAnnotation);
export var Decorator = makeDecorator(DirectiveAnnotation);
/* from view */
export var View = makeDecorator(ViewAnnotation);
/* from visibility */
export var Ancestor = makeParamDecorator(AncestorAnnotation);
export var Parent = makeParamDecorator(ParentAnnotation);
/* from di */
export var Attribute = makeParamDecorator(AttributeAnnotation);
export var Query = makeParamDecorator(QueryAnnotation);