From b54e7214f02beee25d7c7fbfda5ce599d19f7b94 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 8 Jul 2015 12:04:24 -0700 Subject: [PATCH] chore: removed angular2.api.ts BREACKING CHANGE: We export InjectMetadata instead of InjectAnnotation --- .../processors/createTypeDefinitionFile.js | 4 +- modules/angular2/angular2.api.dart | 3 - modules/angular2/angular2.api.ts | 24 ---- modules/angular2/angular2.ts | 59 +++------ modules/angular2/core.ts | 1 + modules/angular2/di.ts | 37 +++--- modules/angular2/di_annotations.ts | 6 - modules/angular2/di_metadata.ts | 6 + modules/angular2/forms.ts | 2 + .../src/core/annotations_impl/annotations.ts | 4 +- .../angular2/src/core/annotations_impl/di.ts | 6 +- .../src/core/compiler/element_injector.ts | 3 +- .../src/core/compiler/view_manager.ts | 4 +- modules/angular2/src/di/annotations.dart | 3 - modules/angular2/src/di/annotations.ts | 16 --- modules/angular2/src/di/binding.ts | 25 ++-- modules/angular2/src/di/decorators.dart | 52 +++++++- modules/angular2/src/di/decorators.ts | 118 +++++++++++++++--- modules/angular2/src/di/injector.ts | 4 +- .../di/{annotations_impl.ts => metadata.ts} | 46 +++---- .../transform/common/annotation_matcher.dart | 4 - .../core/compiler/element_injector_spec.ts | 5 +- .../test/core/compiler/integration_spec.ts | 6 +- modules/angular2/test/di/injector_spec.ts | 20 +-- .../test/transform/integration/all_tests.dart | 4 +- 25 files changed, 254 insertions(+), 208 deletions(-) delete mode 100644 modules/angular2/angular2.api.dart delete mode 100644 modules/angular2/angular2.api.ts delete mode 100644 modules/angular2/di_annotations.ts create mode 100644 modules/angular2/di_metadata.ts delete mode 100644 modules/angular2/src/di/annotations.dart delete mode 100644 modules/angular2/src/di/annotations.ts rename modules/angular2/src/di/{annotations_impl.ts => metadata.ts} (81%) diff --git a/docs/dgeni-package/processors/createTypeDefinitionFile.js b/docs/dgeni-package/processors/createTypeDefinitionFile.js index c3566a6433..d07bbef69d 100644 --- a/docs/dgeni-package/processors/createTypeDefinitionFile.js +++ b/docs/dgeni-package/processors/createTypeDefinitionFile.js @@ -17,9 +17,7 @@ module.exports = function createTypeDefinitionFile(log) { { id: 'angular2/angular2', modules: { - // The shape of the public API is determined by what is reexported into - // angular2/angular2, with hacks layered into angular2.api.ts - 'angular2/angular2': 'angular2/angular2.api', + 'angular2/angular2': 'angular2/angular2', } }, { diff --git a/modules/angular2/angular2.api.dart b/modules/angular2/angular2.api.dart deleted file mode 100644 index e7d1496a13..0000000000 --- a/modules/angular2/angular2.api.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.angular2.api; -// Ignore this file for dart emit. -// It is used only for generating the TypeScript .d.ts file. \ No newline at end of file diff --git a/modules/angular2/angular2.api.ts b/modules/angular2/angular2.api.ts deleted file mode 100644 index e8ea2f6835..0000000000 --- a/modules/angular2/angular2.api.ts +++ /dev/null @@ -1,24 +0,0 @@ -// This module is used by dgeni to produce the angular2.d.ts file. - -// Re-export everything we export to the application runtime -export * from './angular2'; - -// Horrible hack. See -// https://docs.google.com/document/d/1nNebWTiLzz5ePcit_bjZPtaiSIFU4EsQKUlX7LX0c0A/edit -// Exports needed to make angular2.d.ts work, -// because these symbols are dependencies of other exports but are not otherwise exported. -// This should be cleaned up in one of two ways: -// 1) if the symbol is intended to be part of the public API, then re-export somewhere else -// 2) if the symbol should be omitted from the public API, then the class exposing it should -// not be exported, or should avoid exposing the symbol. -export * from './src/core/compiler/element_injector'; -export {DependencyAnnotation} from './src/di/annotations_impl'; -export {LifecycleEvent} from './src/core/annotations_impl/annotations'; -export {Form} from './src/forms/directives/form_interface'; -export {TypeDecorator, ClassDefinition} from './src/util/decorators'; -export {Query} from './src/core/annotations_impl/di'; -export {ControlContainer} from './src/forms/directives/control_container'; -export {Injectable, Visibility} from './src/di/annotations_impl'; -export {BaseQueryList} from './src/core/compiler/base_query_list'; -export {AppProtoView, AppView, AppViewContainer} from './src/core/compiler/view'; -export * from './src/change_detection/parser/ast'; diff --git a/modules/angular2/angular2.ts b/modules/angular2/angular2.ts index 49a9e6136f..8b09bd3ec2 100644 --- a/modules/angular2/angular2.ts +++ b/modules/angular2/angular2.ts @@ -4,15 +4,16 @@ export * from 'angular2/annotations'; export * from 'angular2/core'; -// TO BE CLEANED UP. export { DehydratedException, ExpressionChangedAfterItHasBeenChecked, ChangeDetectionError, - ChangeDetection, + ON_PUSH, DEFAULT, + ChangeDetectorRef, + PipeRegistry, WrappedValue, Pipe, @@ -20,52 +21,14 @@ export { NullPipe, NullPipeFactory, defaultPipes, - DynamicChangeDetection, - JitChangeDetection, - PreGeneratedChangeDetection, - preGeneratedProtoDetectors, defaultPipeRegistry, - DirectiveIndex, - BindingRecord, - ProtoChangeDetector, - ChangeDispatcher, - ChangeDetector, - Locals, - ChangeDetectorDefinition, BasePipe, - DirectiveRecord + + Locals } from './change_detection'; -export { - Inject, - Optional, - Injectable, - forwardRef, - resolveForwardRef, - ForwardRefFn, - Injector, - ProtoInjector, - Binding, - bind, - Key, - NoBindingError, - AbstractBindingError, - AsyncBindingError, - CyclicDependencyError, - InstantiationError, - InvalidBindingError, - NoAnnotationError, - OpaqueToken, - ResolvedBinding, - BindingBuilder, - Dependency, - Visibility, - Self, - Parent, - Ancestor, - Unbounded, - DependencyProvider -} from './di'; +export * from './di'; +export * from './forms'; export * from './directives'; @@ -95,5 +58,11 @@ export { } from './forms'; export * from './http'; -export * from 'angular2/src/render/api'; +export { + EventDispatcher, + Renderer, + RenderElementRef, + RenderViewRef, + RenderProtoViewRef +} from 'angular2/src/render/api'; export {DomRenderer, DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer'; diff --git a/modules/angular2/core.ts b/modules/angular2/core.ts index 0bb885345c..17a65dc3b8 100644 --- a/modules/angular2/core.ts +++ b/modules/angular2/core.ts @@ -17,6 +17,7 @@ export {Compiler} from 'angular2/src/core/compiler/compiler'; export {AppViewManager} from 'angular2/src/core/compiler/view_manager'; export {QueryList} from 'angular2/src/core/compiler/query_list'; +export {BaseQueryList} from 'angular2/src/core/compiler/base_query_list'; export {ElementRef} from 'angular2/src/core/compiler/element_ref'; export {RenderElementRef} from 'angular2/src/render/api'; export {ViewRef, ProtoViewRef} from 'angular2/src/core/compiler/view_ref'; diff --git a/modules/angular2/di.ts b/modules/angular2/di.ts index 5f51b4546f..1c338220cf 100644 --- a/modules/angular2/di.ts +++ b/modules/angular2/di.ts @@ -6,28 +6,22 @@ */ export { - InjectAnnotation, - OptionalAnnotation, - InjectableAnnotation, - DependencyAnnotation, - VisibilityAnnotation, - SelfAnnotation, - ParentAnnotation, - AncestorAnnotation, - UnboundedAnnotation -} from './src/di/annotations'; + InjectMetadata, + OptionalMetadata, + InjectableMetadata, + VisibilityMetadata, + SelfMetadata, + ParentMetadata, + AncestorMetadata, + UnboundedMetadata, + DependencyMetadata, + self, + unbounded +} from './src/di/metadata'; + +// we have to reexport * because Dart and TS export two different sets of types +export * from './src/di/decorators'; -export { - Inject, - Optional, - Injectable, - Visibility, - Self, - Parent, - Ancestor, - Unbounded -} from './src/di/decorators'; -export {self} from './src/di/annotations_impl'; export {forwardRef, resolveForwardRef, ForwardRefFn} from './src/di/forward_ref'; export { resolveBindings, @@ -38,6 +32,7 @@ export { PUBLIC, PRIVATE, undefinedValue + } from './src/di/injector'; export {Binding, BindingBuilder, ResolvedBinding, Dependency, bind} from './src/di/binding'; export {Key, KeyRegistry, TypeLiteral} from './src/di/key'; diff --git a/modules/angular2/di_annotations.ts b/modules/angular2/di_annotations.ts deleted file mode 100644 index 186676b48b..0000000000 --- a/modules/angular2/di_annotations.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * @module - * @public - * @description - * Annotations which control how the dependencies are resolved by the {@link Injector}. - */ diff --git a/modules/angular2/di_metadata.ts b/modules/angular2/di_metadata.ts new file mode 100644 index 0000000000..5669307be5 --- /dev/null +++ b/modules/angular2/di_metadata.ts @@ -0,0 +1,6 @@ +/** + * @module + * @public + * @description + * Metadata which control how the dependencies are resolved by the {@link Injector}. + */ diff --git a/modules/angular2/forms.ts b/modules/angular2/forms.ts index 01d7186f8d..0371fb73cc 100644 --- a/modules/angular2/forms.ts +++ b/modules/angular2/forms.ts @@ -16,6 +16,8 @@ export {AbstractControl, Control, ControlGroup, ControlArray} from './src/forms/model'; export {AbstractControlDirective} from './src/forms/directives/abstract_control_directive'; +export {Form} from './src/forms/directives/form_interface'; +export {ControlContainer} from './src/forms/directives/control_container'; export {NgControlName} from './src/forms/directives/ng_control_name'; export {NgFormControl} from './src/forms/directives/ng_form_control'; export {NgModel} from './src/forms/directives/ng_model'; diff --git a/modules/angular2/src/core/annotations_impl/annotations.ts b/modules/angular2/src/core/annotations_impl/annotations.ts index b67a5ef020..80489447f6 100644 --- a/modules/angular2/src/core/annotations_impl/annotations.ts +++ b/modules/angular2/src/core/annotations_impl/annotations.ts @@ -1,6 +1,6 @@ import {CONST, CONST_EXPR} from 'angular2/src/facade/lang'; import {List} from 'angular2/src/facade/collection'; -import {Injectable, self} from 'angular2/src/di/annotations_impl'; +import {InjectableMetadata, self} from 'angular2/src/di/metadata'; import {DEFAULT} from 'angular2/change_detection'; /** @@ -407,7 +407,7 @@ import {DEFAULT} from 'angular2/change_detection'; * @exportedAs angular2/annotations */ @CONST() -export class Directive extends Injectable { +export class Directive extends InjectableMetadata { /** * The CSS selector that triggers the instantiation of a directive. * diff --git a/modules/angular2/src/core/annotations_impl/di.ts b/modules/angular2/src/core/annotations_impl/di.ts index 78ed67384a..ae2ea39113 100644 --- a/modules/angular2/src/core/annotations_impl/di.ts +++ b/modules/angular2/src/core/annotations_impl/di.ts @@ -1,5 +1,5 @@ import {CONST, Type, stringify, isPresent, StringWrapper, isString} from 'angular2/src/facade/lang'; -import {DependencyAnnotation} from 'angular2/src/di/annotations_impl'; +import {DependencyMetadata} from 'angular2/src/di/metadata'; import {resolveForwardRef} from 'angular2/di'; /** @@ -31,7 +31,7 @@ import {resolveForwardRef} from 'angular2/di'; * @exportedAs angular2/annotations */ @CONST() -export class Attribute extends DependencyAnnotation { +export class Attribute extends DependencyMetadata { constructor(public attributeName: string) { super(); } get token() { @@ -53,7 +53,7 @@ export class Attribute extends DependencyAnnotation { * @exportedAs angular2/annotations */ @CONST() -export class Query extends DependencyAnnotation { +export class Query extends DependencyMetadata { descendants: boolean; constructor(private _selector: Type | string, {descendants = false}: {descendants?: boolean} = {}) { diff --git a/modules/angular2/src/core/compiler/element_injector.ts b/modules/angular2/src/core/compiler/element_injector.ts index 618de50ada..b8a3375aa8 100644 --- a/modules/angular2/src/core/compiler/element_injector.ts +++ b/modules/angular2/src/core/compiler/element_injector.ts @@ -26,8 +26,7 @@ import { CyclicDependencyError, resolveForwardRef, resolveBindings, - Visibility, - VisibilityAnnotation, + VisibilityMetadata, DependencyProvider, self } from 'angular2/di'; diff --git a/modules/angular2/src/core/compiler/view_manager.ts b/modules/angular2/src/core/compiler/view_manager.ts index ada0fc1ab0..0f412aa2e8 100644 --- a/modules/angular2/src/core/compiler/view_manager.ts +++ b/modules/angular2/src/core/compiler/view_manager.ts @@ -19,8 +19,8 @@ export class AppViewManager { /** * @private */ - constructor(public _viewPool: AppViewPool, public _viewListener: AppViewListener, - public _utils: AppViewManagerUtils, public _renderer: Renderer) {} + constructor(private _viewPool: AppViewPool, private _viewListener: AppViewListener, + private _utils: AppViewManagerUtils, private _renderer: Renderer) {} /** * Returns associated Component {@link ViewRef} from {@link ElementRef}. diff --git a/modules/angular2/src/di/annotations.dart b/modules/angular2/src/di/annotations.dart deleted file mode 100644 index b019ea5ff3..0000000000 --- a/modules/angular2/src/di/annotations.dart +++ /dev/null @@ -1,3 +0,0 @@ -library angular2.di.annotations; - -export './annotations_impl.dart'; diff --git a/modules/angular2/src/di/annotations.ts b/modules/angular2/src/di/annotations.ts deleted file mode 100644 index 599122edb8..0000000000 --- a/modules/angular2/src/di/annotations.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * 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, - Optional as OptionalAnnotation, - Injectable as InjectableAnnotation, - Visibility as VisibilityAnnotation, - Self as SelfAnnotation, - Parent as ParentAnnotation, - Ancestor as AncestorAnnotation, - Unbounded as UnboundedAnnotation, - DependencyAnnotation, // abstract base class, does not need a decorator -} from './annotations_impl'; diff --git a/modules/angular2/src/di/binding.ts b/modules/angular2/src/di/binding.ts index dee1a9ca28..beb4411fe2 100644 --- a/modules/angular2/src/di/binding.ts +++ b/modules/angular2/src/di/binding.ts @@ -12,13 +12,13 @@ import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {reflector} from 'angular2/src/reflection/reflection'; import {Key} from './key'; import { - Inject, - Injectable, - Visibility, - Optional, + InjectMetadata, + InjectableMetadata, + VisibilityMetadata, + OptionalMetadata, unbounded, - DependencyAnnotation -} from './annotations_impl'; + DependencyMetadata +} from './metadata'; import {NoAnnotationError} from './exceptions'; import {resolveForwardRef} from './forward_ref'; @@ -26,7 +26,7 @@ import {resolveForwardRef} from './forward_ref'; * @private */ export class Dependency { - constructor(public key: Key, public optional: boolean, public visibility: Visibility, + constructor(public key: Key, public optional: boolean, public visibility: VisibilityMetadata, public properties: List) {} static fromKey(key: Key): Dependency { @@ -421,16 +421,16 @@ function _extractToken(typeOrFunc, annotations /*List | any*/, token = paramAnnotation; defaultVisibility = _defaulVisiblity(token); - } else if (paramAnnotation instanceof Inject) { + } else if (paramAnnotation instanceof InjectMetadata) { token = paramAnnotation.token; - } else if (paramAnnotation instanceof Optional) { + } else if (paramAnnotation instanceof OptionalMetadata) { optional = true; - } else if (paramAnnotation instanceof Visibility) { + } else if (paramAnnotation instanceof VisibilityMetadata) { visibility = paramAnnotation; - } else if (paramAnnotation instanceof DependencyAnnotation) { + } else if (paramAnnotation instanceof DependencyMetadata) { if (isPresent(paramAnnotation.token)) { token = paramAnnotation.token; } @@ -454,7 +454,8 @@ function _extractToken(typeOrFunc, annotations /*List | any*/, function _defaulVisiblity(typeOrFunc) { try { if (!(typeOrFunc instanceof Type)) return unbounded; - var f = ListWrapper.filter(reflector.annotations(typeOrFunc), s => s instanceof Injectable); + var f = + ListWrapper.filter(reflector.annotations(typeOrFunc), s => s instanceof InjectableMetadata); return f.length === 0 ? unbounded : f[0].visibility; } catch (e) { return unbounded; diff --git a/modules/angular2/src/di/decorators.dart b/modules/angular2/src/di/decorators.dart index ef271560c2..96efaab45a 100644 --- a/modules/angular2/src/di/decorators.dart +++ b/modules/angular2/src/di/decorators.dart @@ -1,5 +1,53 @@ library angular2.di.decorators; -/* This file is empty because, Dart does not have decorators. */ +import 'metadata.dart'; +export 'metadata.dart'; -export 'annotations.dart'; +/** + * {@link InjectMetadata}. + */ +class Inject extends InjectMetadata { + const Inject(dynamic token): super(token); +} + +/** + * {@link OptionalMetadata}. + */ +class Optional extends OptionalMetadata { + const Optional(): super(); +} + +/** + * {@link InjectableMetadata}. + */ +class Injectable extends InjectableMetadata { + const Injectable([VisibilityMetadata visibility = unbounded]): super(visibility); +} + +/** + * {@link SelfMetadata}. + */ +class Self extends SelfMetadata { + const Self(): super(); +} + +/** + * {@link ParentMetadata}. + */ +class Parent extends ParentMetadata { + const Parent({bool self}): super(self:self); +} + +/** + * {@link AncestorMetadata}. + */ +class Ancestor extends AncestorMetadata { + const Ancestor({bool self}): super(self:self); +} + +/** + * {@link UnboundedMetadata}. + */ +class Unbounded extends UnboundedMetadata { + const Unbounded({bool self}): super(self:self); +} \ No newline at end of file diff --git a/modules/angular2/src/di/decorators.ts b/modules/angular2/src/di/decorators.ts index a15b5029d2..016e301526 100644 --- a/modules/angular2/src/di/decorators.ts +++ b/modules/angular2/src/di/decorators.ts @@ -1,20 +1,102 @@ import { - InjectAnnotation, - OptionalAnnotation, - InjectableAnnotation, - VisibilityAnnotation, - SelfAnnotation, - ParentAnnotation, - AncestorAnnotation, - UnboundedAnnotation -} from './annotations'; -import {makeDecorator, makeParamDecorator} from '../util/decorators'; + InjectMetadata, + OptionalMetadata, + InjectableMetadata, + SelfMetadata, + VisibilityMetadata, + ParentMetadata, + AncestorMetadata, + UnboundedMetadata +} from './metadata'; +import {makeDecorator, makeParamDecorator, TypeDecorator} from '../util/decorators'; -export var Inject = makeParamDecorator(InjectAnnotation); -export var Optional = makeParamDecorator(OptionalAnnotation); -export var Injectable = makeDecorator(InjectableAnnotation); -export var Visibility = makeParamDecorator(VisibilityAnnotation); -export var Self = makeParamDecorator(SelfAnnotation); -export var Parent = makeParamDecorator(ParentAnnotation); -export var Ancestor = makeParamDecorator(AncestorAnnotation); -export var Unbounded = makeParamDecorator(UnboundedAnnotation); \ No newline at end of file +/** + * Factory for creating {@link InjectMetadata}. + */ +export interface InjectFactory { + (token: any): any; + new (token: any): InjectMetadata; +} + +/** + * Factory for creating {@link OptionalMetadata}. + */ +export interface OptionalFactory { + (): any; + new (): OptionalMetadata; +} + +/** + * Factory for creating {@link InjectableMetadata}. + */ +export interface InjectableFactory { + (visibility?: VisibilityMetadata): any; + new (visibility?: VisibilityMetadata): InjectableMetadata; +} + +/** + * Factory for creating {@link SelfMetadata}. + */ +export interface SelfFactory { + (): any; + new (): SelfMetadata; +} + +/** + * Factory for creating {@link ParentMetadata}. + */ +export interface ParentFactory { + ({self: boolean}?): any; + new ({self: boolean}?): ParentMetadata; +} + +/** + * Factory for creating {@link AncestorMetadata}. + */ +export interface AncestorFactory { + ({self: boolean}?): any; + new ({self: boolean}?): AncestorMetadata; +} + +/** + * Factory for creating {@link UnboundedMetadata}. + */ +export interface UnboundedFactory { + ({self: boolean}?): any; + new ({self: boolean}?): UnboundedMetadata; +} + +/** + * Factory for creating {@link InjectMetadata}. + */ +export var Inject: InjectFactory = makeParamDecorator(InjectMetadata); + +/** + * Factory for creating {@link OptionalMetadata}. + */ +export var Optional: OptionalFactory = makeParamDecorator(OptionalMetadata); + +/** + * Factory for creating {@link InjectableMetadata}. + */ +export var Injectable: InjectableFactory = makeDecorator(InjectableMetadata); + +/** + * Factory for creating {@link SelfMetadata}. + */ +export var Self: SelfFactory = makeParamDecorator(SelfMetadata); + +/** + * Factory for creating {@link ParentMetadata}. + */ +export var Parent: ParentFactory = makeParamDecorator(ParentMetadata); + +/** + * Factory for creating {@link AncestorMetadata}. + */ +export var Ancestor: AncestorFactory = makeParamDecorator(AncestorMetadata); + +/** + * Factory for creating {@link UnboundedMetadata}. + */ +export var Unbounded: UnboundedFactory = makeParamDecorator(UnboundedMetadata); \ No newline at end of file diff --git a/modules/angular2/src/di/injector.ts b/modules/angular2/src/di/injector.ts index 4e77aae30f..2c534b027e 100644 --- a/modules/angular2/src/di/injector.ts +++ b/modules/angular2/src/di/injector.ts @@ -14,7 +14,7 @@ import { import {FunctionWrapper, Type, isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang'; import {Key} from './key'; import {resolveForwardRef} from './forward_ref'; -import {Visibility, unbounded} from './annotations_impl'; +import {VisibilityMetadata, unbounded} from './metadata'; const _constructing = CONST_EXPR(new Object()); const _notFound = CONST_EXPR(new Object()); @@ -713,7 +713,7 @@ export class Injector { } } - private _getByKey(key: Key, depVisibility: Visibility, optional: boolean, + private _getByKey(key: Key, depVisibility: VisibilityMetadata, optional: boolean, bindingVisibility: number): any { if (key.token === Injector) { return this; diff --git a/modules/angular2/src/di/annotations_impl.ts b/modules/angular2/src/di/metadata.ts similarity index 81% rename from modules/angular2/src/di/annotations_impl.ts rename to modules/angular2/src/di/metadata.ts index 71392168fd..20ca7f33c6 100644 --- a/modules/angular2/src/di/annotations_impl.ts +++ b/modules/angular2/src/di/metadata.ts @@ -1,7 +1,7 @@ import {CONST, CONST_EXPR, stringify, isBlank, isPresent} from "angular2/src/facade/lang"; /** - * A parameter annotation that specifies a dependency. + * A parameter metadata that specifies a dependency. * * ``` * class AComponent { @@ -9,17 +9,17 @@ import {CONST, CONST_EXPR, stringify, isBlank, isPresent} from "angular2/src/fac * } * ``` * - * @exportedAs angular2/di_annotations + * @exportedAs angular2/di_metadata */ @CONST() -export class Inject { +export class InjectMetadata { constructor(public token) {} toString(): string { return `@Inject(${stringify(this.token)})`; } } /** - * A parameter annotation that marks a dependency as optional. {@link Injector} provides `null` if + * A parameter metadata that marks a dependency as optional. {@link Injector} provides `null` if * the dependency is not found. * * ``` @@ -30,23 +30,23 @@ export class Inject { * } * ``` * - * @exportedAs angular2/di_annotations + * @exportedAs angular2/di_metadata */ @CONST() -export class Optional { +export class OptionalMetadata { toString(): string { return `@Optional()`; } } /** - * `DependencyAnnotation` is used by the framework to extend DI. + * `DependencyMetadata is used by the framework to extend DI. * - * Only annotations implementing `DependencyAnnotation` are added to the list of dependency + * Only metadata implementing `DependencyMetadata` are added to the list of dependency * properties. * * For example: * * ``` - * class Parent extends DependencyAnnotation {} + * class Parent extends DependencyMetadata {} * class NotDependencyProperty {} * * class AComponent { @@ -63,15 +63,15 @@ export class Optional { * The framework can use `new Parent()` to handle the `aService` dependency * in a specific way. * - * @exportedAs angular2/di_annotations + * @exportedAs angular2/di_metadata */ @CONST() -export class DependencyAnnotation { +export class DependencyMetadata { get token() { return null; } } /** - * A marker annotation that marks a class as available to `Injector` for creation. Used by tooling + * A marker metadata that marks a class as available to `Injector` for creation. Used by tooling * for generating constructor stubs. * * ``` @@ -82,11 +82,11 @@ export class DependencyAnnotation { * @Injectable * class UsefulService {} * ``` - * @exportedAs angular2/di_annotations + * @exportedAs angular2/di_metadata */ @CONST() -export class Injectable { - constructor(public visibility: Visibility = unbounded) {} +export class InjectableMetadata { + constructor(public visibility: VisibilityMetadata = unbounded) {} } /** @@ -94,10 +94,10 @@ export class Injectable { * * See {@link Self}, {@link Parent}, {@link Ancestor}, {@link Unbounded}. * - * @exportedAs angular2/di_annotations + * @exportedAs angular2/di_metadata */ @CONST() -export class Visibility { +export class VisibilityMetadata { constructor(public depth: number, public crossBoundaries: boolean, public _includeSelf: boolean) { } @@ -129,12 +129,12 @@ export class Visibility { * @exportedAs angular2/di */ @CONST() -export class Self extends Visibility { +export class SelfMetadata extends VisibilityMetadata { constructor() { super(0, false, true); } toString(): string { return `@Self()`; } } -export const self = CONST_EXPR(new Self()); +export const self = CONST_EXPR(new SelfMetadata()); /** * Specifies that an injector should retrieve a dependency from the direct parent. @@ -169,7 +169,7 @@ export const self = CONST_EXPR(new Self()); * @exportedAs angular2/di */ @CONST() -export class Parent extends Visibility { +export class ParentMetadata extends VisibilityMetadata { constructor({self}: {self?: boolean} = {}) { super(1, false, self); } toString(): string { return `@Parent(self: ${this.includeSelf}})`; } } @@ -208,7 +208,7 @@ export class Parent extends Visibility { * @exportedAs angular2/di */ @CONST() -export class Ancestor extends Visibility { +export class AncestorMetadata extends VisibilityMetadata { constructor({self}: {self?: boolean} = {}) { super(999999, false, self); } toString(): string { return `@Ancestor(self: ${this.includeSelf}})`; } } @@ -247,9 +247,9 @@ export class Ancestor extends Visibility { * @exportedAs angular2/di */ @CONST() -export class Unbounded extends Visibility { +export class UnboundedMetadata extends VisibilityMetadata { constructor({self}: {self?: boolean} = {}) { super(999999, true, self); } toString(): string { return `@Unbounded(self: ${this.includeSelf}})`; } } -export const unbounded = CONST_EXPR(new Unbounded({self: true})); \ No newline at end of file +export const unbounded = CONST_EXPR(new UnboundedMetadata({self: true})); \ No newline at end of file diff --git a/modules/angular2/src/transform/common/annotation_matcher.dart b/modules/angular2/src/transform/common/annotation_matcher.dart index 115beb2db2..fff919506c 100644 --- a/modules/angular2/src/transform/common/annotation_matcher.dart +++ b/modules/angular2/src/transform/common/annotation_matcher.dart @@ -10,10 +10,6 @@ import 'logging.dart' show logger; /// on a class. These classes are re-exported in many places so this covers all /// the possible libraries which could provide them. const INJECTABLES = const [ - const AnnotationDescriptor( - 'Injectable', 'package:angular2/src/di/annotations.dart', null), - const AnnotationDescriptor( - 'Injectable', 'package:angular2/src/di/annotations_impl.dart', null), const AnnotationDescriptor( 'Injectable', 'package:angular2/src/di/decorators.dart', null), const AnnotationDescriptor('Injectable', 'package:angular2/di.dart', null), diff --git a/modules/angular2/test/core/compiler/element_injector_spec.ts b/modules/angular2/test/core/compiler/element_injector_spec.ts index 566ff892ae..e5cc39b96c 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.ts +++ b/modules/angular2/test/core/compiler/element_injector_spec.ts @@ -40,8 +40,7 @@ import { Directive, onDestroy } from 'angular2/annotations'; -import {bind, Injector, Binding, resolveBindings, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self} from 'angular2/di'; -import * as diAnn from 'angular2/src/di/annotations_impl'; +import {bind, Injector, Binding, resolveBindings, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self, InjectMetadata, ParentMetadata} from 'angular2/di'; import {AppProtoView, AppView} from 'angular2/src/core/compiler/view'; import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref'; import {ProtoViewRef} from 'angular2/src/core/compiler/view_ref'; @@ -595,7 +594,7 @@ export function main() { bind('injectable2') .toFactory( (val) => `${val}-injectable2`, - [[new diAnn.Inject('injectable1'), new diAnn.Parent()]]) + [[new InjectMetadata('injectable1'), new ParentMetadata()]]) ] }))]); expect(childInj.get('injectable2')).toEqual('injectable1-injectable2'); diff --git a/modules/angular2/test/core/compiler/integration_spec.ts b/modules/angular2/test/core/compiler/integration_spec.ts index 76e68de5f4..40e187187c 100644 --- a/modules/angular2/test/core/compiler/integration_spec.ts +++ b/modules/angular2/test/core/compiler/integration_spec.ts @@ -43,7 +43,8 @@ import { Inject, Parent, Ancestor, - Unbounded + Unbounded, + UnboundedMetadata } from 'angular2/di'; import { PipeFactory, @@ -58,7 +59,6 @@ import { import {Directive, Component, View, Attribute, Query} from 'angular2/annotations'; import * as viewAnn from 'angular2/src/core/annotations_impl/view'; -import * as visAnn from 'angular2/src/di/annotations_impl'; import {QueryList} from 'angular2/src/core/compiler/query_list'; @@ -1779,7 +1779,7 @@ function createParentBus(peb) { selector: 'parent-providing-event-bus', hostInjector: [ new Binding(EventBus, - {toFactory: createParentBus, deps: [[EventBus, new visAnn.Unbounded()]]}) + {toFactory: createParentBus, deps: [[EventBus, new UnboundedMetadata()]]}) ] }) @View({ diff --git a/modules/angular2/test/di/injector_spec.ts b/modules/angular2/test/di/injector_spec.ts index dd5d80a4c9..c1c4269605 100644 --- a/modules/angular2/test/di/injector_spec.ts +++ b/modules/angular2/test/di/injector_spec.ts @@ -14,20 +14,22 @@ import { ResolvedBinding, Key, forwardRef, - DependencyAnnotation, - Injectable + DependencyMetadata, + Injectable, + InjectMetadata, + self, + unbounded } from 'angular2/di'; import {InjectorInlineStrategy, InjectorDynamicStrategy} from 'angular2/src/di/injector'; import {Optional, Inject} from 'angular2/src/di/decorators'; -import * as ann from 'angular2/src/di/annotations_impl'; -class CustomDependencyAnnotation extends DependencyAnnotation {} +class CustomDependencyMetadata extends DependencyMetadata {} class Engine {} -@Injectable(ann.self) +@Injectable(self) class EngineWithSetVisibility { } @@ -407,12 +409,12 @@ export function main() { var bindings = Injector.resolve([ bind("token") .toFactory((e) => "result", - [[new ann.Inject("dep"), new CustomDependencyAnnotation()]]) + [[new InjectMetadata("dep"), new CustomDependencyMetadata()]]) ]); var binding = bindings[0]; expect(binding.dependencies[0].key.token).toEqual("dep"); - expect(binding.dependencies[0].properties).toEqual([new CustomDependencyAnnotation()]); + expect(binding.dependencies[0].properties).toEqual([new CustomDependencyMetadata()]); }); }); @@ -420,13 +422,13 @@ export function main() { it("should use the provided visibility", () => { var bindings = Injector.resolve([CarNeedsEngineWithSetVisibility, EngineWithSetVisibility]); var carBinding = bindings[0]; - expect(carBinding.dependencies[0].visibility).toEqual(ann.self); + expect(carBinding.dependencies[0].visibility).toEqual(self); }); it("should set the default visibility to unbounded", () => { var bindings = Injector.resolve([Car, Engine]); var carBinding = bindings[0]; - expect(carBinding.dependencies[0].visibility).toEqual(ann.unbounded); + expect(carBinding.dependencies[0].visibility).toEqual(unbounded); }); }); }); diff --git a/modules/angular2/test/transform/integration/all_tests.dart b/modules/angular2/test/transform/integration/all_tests.dart index f32aa8c939..9c251d260f 100644 --- a/modules/angular2/test/transform/integration/all_tests.dart +++ b/modules/angular2/test/transform/integration/all_tests.dart @@ -43,8 +43,8 @@ void allTests() { 'angular2|lib/src/reflection/reflection_capabilities.dart': '../common/reflection_capabilities.dart', 'angular2|lib/di.dart': '../../../lib/di.dart', - 'angular2|lib/src/di/annotations_impl.dart': - '../../../lib/src/di/annotations_impl.dart', + 'angular2|lib/src/di/decorators.dart': + '../../../lib/src/di/decorators.dart', }; var tests = [