chore: removed angular2.api.ts
BREACKING CHANGE: We export InjectMetadata instead of InjectAnnotation
This commit is contained in:
@ -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.
|
||||
*
|
||||
|
@ -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} = {}) {
|
||||
|
@ -26,8 +26,7 @@ import {
|
||||
CyclicDependencyError,
|
||||
resolveForwardRef,
|
||||
resolveBindings,
|
||||
Visibility,
|
||||
VisibilityAnnotation,
|
||||
VisibilityMetadata,
|
||||
DependencyProvider,
|
||||
self
|
||||
} from 'angular2/di';
|
||||
|
@ -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}.
|
||||
|
@ -1,3 +0,0 @@
|
||||
library angular2.di.annotations;
|
||||
|
||||
export './annotations_impl.dart';
|
@ -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';
|
@ -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<any>) {}
|
||||
|
||||
static fromKey(key: Key): Dependency {
|
||||
@ -421,16 +421,16 @@ function _extractToken(typeOrFunc, annotations /*List<any> | 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> | 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;
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
/**
|
||||
* 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 = <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);
|
@ -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;
|
||||
|
@ -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}));
|
||||
export const unbounded = CONST_EXPR(new UnboundedMetadata({self: true}));
|
@ -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),
|
||||
|
Reference in New Issue
Block a user