chore: removed angular2.api.ts
BREACKING CHANGE: We export InjectMetadata instead of InjectAnnotation
This commit is contained in:
parent
d6dadc6efc
commit
b54e7214f0
|
@ -17,9 +17,7 @@ module.exports = function createTypeDefinitionFile(log) {
|
||||||
{
|
{
|
||||||
id: 'angular2/angular2',
|
id: 'angular2/angular2',
|
||||||
modules: {
|
modules: {
|
||||||
// The shape of the public API is determined by what is reexported into
|
'angular2/angular2': 'angular2/angular2',
|
||||||
// angular2/angular2, with hacks layered into angular2.api.ts
|
|
||||||
'angular2/angular2': 'angular2/angular2.api',
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -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.
|
|
|
@ -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';
|
|
|
@ -4,15 +4,16 @@
|
||||||
export * from 'angular2/annotations';
|
export * from 'angular2/annotations';
|
||||||
export * from 'angular2/core';
|
export * from 'angular2/core';
|
||||||
|
|
||||||
// TO BE CLEANED UP.
|
|
||||||
export {
|
export {
|
||||||
DehydratedException,
|
DehydratedException,
|
||||||
ExpressionChangedAfterItHasBeenChecked,
|
ExpressionChangedAfterItHasBeenChecked,
|
||||||
ChangeDetectionError,
|
ChangeDetectionError,
|
||||||
ChangeDetection,
|
|
||||||
ON_PUSH,
|
ON_PUSH,
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
|
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
|
|
||||||
PipeRegistry,
|
PipeRegistry,
|
||||||
WrappedValue,
|
WrappedValue,
|
||||||
Pipe,
|
Pipe,
|
||||||
|
@ -20,52 +21,14 @@ export {
|
||||||
NullPipe,
|
NullPipe,
|
||||||
NullPipeFactory,
|
NullPipeFactory,
|
||||||
defaultPipes,
|
defaultPipes,
|
||||||
DynamicChangeDetection,
|
|
||||||
JitChangeDetection,
|
|
||||||
PreGeneratedChangeDetection,
|
|
||||||
preGeneratedProtoDetectors,
|
|
||||||
defaultPipeRegistry,
|
defaultPipeRegistry,
|
||||||
DirectiveIndex,
|
|
||||||
BindingRecord,
|
|
||||||
ProtoChangeDetector,
|
|
||||||
ChangeDispatcher,
|
|
||||||
ChangeDetector,
|
|
||||||
Locals,
|
|
||||||
ChangeDetectorDefinition,
|
|
||||||
BasePipe,
|
BasePipe,
|
||||||
DirectiveRecord
|
|
||||||
|
Locals
|
||||||
} from './change_detection';
|
} from './change_detection';
|
||||||
|
|
||||||
export {
|
export * from './di';
|
||||||
Inject,
|
export * from './forms';
|
||||||
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 './directives';
|
export * from './directives';
|
||||||
|
|
||||||
|
@ -95,5 +58,11 @@ export {
|
||||||
} from './forms';
|
} from './forms';
|
||||||
|
|
||||||
export * from './http';
|
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';
|
export {DomRenderer, DOCUMENT_TOKEN} from 'angular2/src/render/dom/dom_renderer';
|
||||||
|
|
|
@ -17,6 +17,7 @@ export {Compiler} from 'angular2/src/core/compiler/compiler';
|
||||||
|
|
||||||
export {AppViewManager} from 'angular2/src/core/compiler/view_manager';
|
export {AppViewManager} from 'angular2/src/core/compiler/view_manager';
|
||||||
export {QueryList} from 'angular2/src/core/compiler/query_list';
|
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 {ElementRef} from 'angular2/src/core/compiler/element_ref';
|
||||||
export {RenderElementRef} from 'angular2/src/render/api';
|
export {RenderElementRef} from 'angular2/src/render/api';
|
||||||
export {ViewRef, ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
|
export {ViewRef, ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
|
||||||
|
|
|
@ -6,28 +6,22 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export {
|
export {
|
||||||
InjectAnnotation,
|
InjectMetadata,
|
||||||
OptionalAnnotation,
|
OptionalMetadata,
|
||||||
InjectableAnnotation,
|
InjectableMetadata,
|
||||||
DependencyAnnotation,
|
VisibilityMetadata,
|
||||||
VisibilityAnnotation,
|
SelfMetadata,
|
||||||
SelfAnnotation,
|
ParentMetadata,
|
||||||
ParentAnnotation,
|
AncestorMetadata,
|
||||||
AncestorAnnotation,
|
UnboundedMetadata,
|
||||||
UnboundedAnnotation
|
DependencyMetadata,
|
||||||
} from './src/di/annotations';
|
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 {forwardRef, resolveForwardRef, ForwardRefFn} from './src/di/forward_ref';
|
||||||
export {
|
export {
|
||||||
resolveBindings,
|
resolveBindings,
|
||||||
|
@ -38,6 +32,7 @@ export {
|
||||||
PUBLIC,
|
PUBLIC,
|
||||||
PRIVATE,
|
PRIVATE,
|
||||||
undefinedValue
|
undefinedValue
|
||||||
|
|
||||||
} from './src/di/injector';
|
} from './src/di/injector';
|
||||||
export {Binding, BindingBuilder, ResolvedBinding, Dependency, bind} from './src/di/binding';
|
export {Binding, BindingBuilder, ResolvedBinding, Dependency, bind} from './src/di/binding';
|
||||||
export {Key, KeyRegistry, TypeLiteral} from './src/di/key';
|
export {Key, KeyRegistry, TypeLiteral} from './src/di/key';
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
/**
|
|
||||||
* @module
|
|
||||||
* @public
|
|
||||||
* @description
|
|
||||||
* Annotations which control how the dependencies are resolved by the {@link Injector}.
|
|
||||||
*/
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
/**
|
||||||
|
* @module
|
||||||
|
* @public
|
||||||
|
* @description
|
||||||
|
* Metadata which control how the dependencies are resolved by the {@link Injector}.
|
||||||
|
*/
|
|
@ -16,6 +16,8 @@
|
||||||
export {AbstractControl, Control, ControlGroup, ControlArray} from './src/forms/model';
|
export {AbstractControl, Control, ControlGroup, ControlArray} from './src/forms/model';
|
||||||
|
|
||||||
export {AbstractControlDirective} from './src/forms/directives/abstract_control_directive';
|
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 {NgControlName} from './src/forms/directives/ng_control_name';
|
||||||
export {NgFormControl} from './src/forms/directives/ng_form_control';
|
export {NgFormControl} from './src/forms/directives/ng_form_control';
|
||||||
export {NgModel} from './src/forms/directives/ng_model';
|
export {NgModel} from './src/forms/directives/ng_model';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {CONST, CONST_EXPR} from 'angular2/src/facade/lang';
|
import {CONST, CONST_EXPR} from 'angular2/src/facade/lang';
|
||||||
import {List} from 'angular2/src/facade/collection';
|
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';
|
import {DEFAULT} from 'angular2/change_detection';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -407,7 +407,7 @@ import {DEFAULT} from 'angular2/change_detection';
|
||||||
* @exportedAs angular2/annotations
|
* @exportedAs angular2/annotations
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Directive extends Injectable {
|
export class Directive extends InjectableMetadata {
|
||||||
/**
|
/**
|
||||||
* The CSS selector that triggers the instantiation of a directive.
|
* 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 {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';
|
import {resolveForwardRef} from 'angular2/di';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +31,7 @@ import {resolveForwardRef} from 'angular2/di';
|
||||||
* @exportedAs angular2/annotations
|
* @exportedAs angular2/annotations
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Attribute extends DependencyAnnotation {
|
export class Attribute extends DependencyMetadata {
|
||||||
constructor(public attributeName: string) { super(); }
|
constructor(public attributeName: string) { super(); }
|
||||||
|
|
||||||
get token() {
|
get token() {
|
||||||
|
@ -53,7 +53,7 @@ export class Attribute extends DependencyAnnotation {
|
||||||
* @exportedAs angular2/annotations
|
* @exportedAs angular2/annotations
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Query extends DependencyAnnotation {
|
export class Query extends DependencyMetadata {
|
||||||
descendants: boolean;
|
descendants: boolean;
|
||||||
constructor(private _selector: Type | string,
|
constructor(private _selector: Type | string,
|
||||||
{descendants = false}: {descendants?: boolean} = {}) {
|
{descendants = false}: {descendants?: boolean} = {}) {
|
||||||
|
|
|
@ -26,8 +26,7 @@ import {
|
||||||
CyclicDependencyError,
|
CyclicDependencyError,
|
||||||
resolveForwardRef,
|
resolveForwardRef,
|
||||||
resolveBindings,
|
resolveBindings,
|
||||||
Visibility,
|
VisibilityMetadata,
|
||||||
VisibilityAnnotation,
|
|
||||||
DependencyProvider,
|
DependencyProvider,
|
||||||
self
|
self
|
||||||
} from 'angular2/di';
|
} from 'angular2/di';
|
||||||
|
|
|
@ -19,8 +19,8 @@ export class AppViewManager {
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
constructor(public _viewPool: AppViewPool, public _viewListener: AppViewListener,
|
constructor(private _viewPool: AppViewPool, private _viewListener: AppViewListener,
|
||||||
public _utils: AppViewManagerUtils, public _renderer: Renderer) {}
|
private _utils: AppViewManagerUtils, private _renderer: Renderer) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns associated Component {@link ViewRef} from {@link ElementRef}.
|
* 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 {reflector} from 'angular2/src/reflection/reflection';
|
||||||
import {Key} from './key';
|
import {Key} from './key';
|
||||||
import {
|
import {
|
||||||
Inject,
|
InjectMetadata,
|
||||||
Injectable,
|
InjectableMetadata,
|
||||||
Visibility,
|
VisibilityMetadata,
|
||||||
Optional,
|
OptionalMetadata,
|
||||||
unbounded,
|
unbounded,
|
||||||
DependencyAnnotation
|
DependencyMetadata
|
||||||
} from './annotations_impl';
|
} from './metadata';
|
||||||
import {NoAnnotationError} from './exceptions';
|
import {NoAnnotationError} from './exceptions';
|
||||||
import {resolveForwardRef} from './forward_ref';
|
import {resolveForwardRef} from './forward_ref';
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import {resolveForwardRef} from './forward_ref';
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export class Dependency {
|
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>) {}
|
public properties: List<any>) {}
|
||||||
|
|
||||||
static fromKey(key: Key): Dependency {
|
static fromKey(key: Key): Dependency {
|
||||||
|
@ -421,16 +421,16 @@ function _extractToken(typeOrFunc, annotations /*List<any> | any*/,
|
||||||
token = paramAnnotation;
|
token = paramAnnotation;
|
||||||
defaultVisibility = _defaulVisiblity(token);
|
defaultVisibility = _defaulVisiblity(token);
|
||||||
|
|
||||||
} else if (paramAnnotation instanceof Inject) {
|
} else if (paramAnnotation instanceof InjectMetadata) {
|
||||||
token = paramAnnotation.token;
|
token = paramAnnotation.token;
|
||||||
|
|
||||||
} else if (paramAnnotation instanceof Optional) {
|
} else if (paramAnnotation instanceof OptionalMetadata) {
|
||||||
optional = true;
|
optional = true;
|
||||||
|
|
||||||
} else if (paramAnnotation instanceof Visibility) {
|
} else if (paramAnnotation instanceof VisibilityMetadata) {
|
||||||
visibility = paramAnnotation;
|
visibility = paramAnnotation;
|
||||||
|
|
||||||
} else if (paramAnnotation instanceof DependencyAnnotation) {
|
} else if (paramAnnotation instanceof DependencyMetadata) {
|
||||||
if (isPresent(paramAnnotation.token)) {
|
if (isPresent(paramAnnotation.token)) {
|
||||||
token = paramAnnotation.token;
|
token = paramAnnotation.token;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,8 @@ function _extractToken(typeOrFunc, annotations /*List<any> | any*/,
|
||||||
function _defaulVisiblity(typeOrFunc) {
|
function _defaulVisiblity(typeOrFunc) {
|
||||||
try {
|
try {
|
||||||
if (!(typeOrFunc instanceof Type)) return unbounded;
|
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;
|
return f.length === 0 ? unbounded : f[0].visibility;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return unbounded;
|
return unbounded;
|
||||||
|
|
|
@ -1,5 +1,53 @@
|
||||||
library angular2.di.decorators;
|
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 {
|
import {
|
||||||
InjectAnnotation,
|
InjectMetadata,
|
||||||
OptionalAnnotation,
|
OptionalMetadata,
|
||||||
InjectableAnnotation,
|
InjectableMetadata,
|
||||||
VisibilityAnnotation,
|
SelfMetadata,
|
||||||
SelfAnnotation,
|
VisibilityMetadata,
|
||||||
ParentAnnotation,
|
ParentMetadata,
|
||||||
AncestorAnnotation,
|
AncestorMetadata,
|
||||||
UnboundedAnnotation
|
UnboundedMetadata
|
||||||
} from './annotations';
|
} from './metadata';
|
||||||
import {makeDecorator, makeParamDecorator} from '../util/decorators';
|
import {makeDecorator, makeParamDecorator, TypeDecorator} from '../util/decorators';
|
||||||
|
|
||||||
export var Inject = makeParamDecorator(InjectAnnotation);
|
/**
|
||||||
export var Optional = makeParamDecorator(OptionalAnnotation);
|
* Factory for creating {@link InjectMetadata}.
|
||||||
export var Injectable = makeDecorator(InjectableAnnotation);
|
*/
|
||||||
export var Visibility = makeParamDecorator(VisibilityAnnotation);
|
export interface InjectFactory {
|
||||||
export var Self = makeParamDecorator(SelfAnnotation);
|
(token: any): any;
|
||||||
export var Parent = makeParamDecorator(ParentAnnotation);
|
new (token: any): InjectMetadata;
|
||||||
export var Ancestor = makeParamDecorator(AncestorAnnotation);
|
}
|
||||||
export var Unbounded = makeParamDecorator(UnboundedAnnotation);
|
|
||||||
|
/**
|
||||||
|
* 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 {FunctionWrapper, Type, isPresent, isBlank, CONST_EXPR} from 'angular2/src/facade/lang';
|
||||||
import {Key} from './key';
|
import {Key} from './key';
|
||||||
import {resolveForwardRef} from './forward_ref';
|
import {resolveForwardRef} from './forward_ref';
|
||||||
import {Visibility, unbounded} from './annotations_impl';
|
import {VisibilityMetadata, unbounded} from './metadata';
|
||||||
|
|
||||||
const _constructing = CONST_EXPR(new Object());
|
const _constructing = CONST_EXPR(new Object());
|
||||||
const _notFound = 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 {
|
bindingVisibility: number): any {
|
||||||
if (key.token === Injector) {
|
if (key.token === Injector) {
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {CONST, CONST_EXPR, stringify, isBlank, isPresent} from "angular2/src/facade/lang";
|
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 {
|
* 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()
|
@CONST()
|
||||||
export class Inject {
|
export class InjectMetadata {
|
||||||
constructor(public token) {}
|
constructor(public token) {}
|
||||||
toString(): string { return `@Inject(${stringify(this.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.
|
* the dependency is not found.
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
|
@ -30,23 +30,23 @@ export class Inject {
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @exportedAs angular2/di_annotations
|
* @exportedAs angular2/di_metadata
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Optional {
|
export class OptionalMetadata {
|
||||||
toString(): string { return `@Optional()`; }
|
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.
|
* properties.
|
||||||
*
|
*
|
||||||
* For example:
|
* For example:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* class Parent extends DependencyAnnotation {}
|
* class Parent extends DependencyMetadata {}
|
||||||
* class NotDependencyProperty {}
|
* class NotDependencyProperty {}
|
||||||
*
|
*
|
||||||
* class AComponent {
|
* class AComponent {
|
||||||
|
@ -63,15 +63,15 @@ export class Optional {
|
||||||
* The framework can use `new Parent()` to handle the `aService` dependency
|
* The framework can use `new Parent()` to handle the `aService` dependency
|
||||||
* in a specific way.
|
* in a specific way.
|
||||||
*
|
*
|
||||||
* @exportedAs angular2/di_annotations
|
* @exportedAs angular2/di_metadata
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class DependencyAnnotation {
|
export class DependencyMetadata {
|
||||||
get token() { return null; }
|
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.
|
* for generating constructor stubs.
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
|
@ -82,11 +82,11 @@ export class DependencyAnnotation {
|
||||||
* @Injectable
|
* @Injectable
|
||||||
* class UsefulService {}
|
* class UsefulService {}
|
||||||
* ```
|
* ```
|
||||||
* @exportedAs angular2/di_annotations
|
* @exportedAs angular2/di_metadata
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Injectable {
|
export class InjectableMetadata {
|
||||||
constructor(public visibility: Visibility = unbounded) {}
|
constructor(public visibility: VisibilityMetadata = unbounded) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,10 +94,10 @@ export class Injectable {
|
||||||
*
|
*
|
||||||
* See {@link Self}, {@link Parent}, {@link Ancestor}, {@link Unbounded}.
|
* See {@link Self}, {@link Parent}, {@link Ancestor}, {@link Unbounded}.
|
||||||
*
|
*
|
||||||
* @exportedAs angular2/di_annotations
|
* @exportedAs angular2/di_metadata
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Visibility {
|
export class VisibilityMetadata {
|
||||||
constructor(public depth: number, public crossBoundaries: boolean, public _includeSelf: boolean) {
|
constructor(public depth: number, public crossBoundaries: boolean, public _includeSelf: boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +129,12 @@ export class Visibility {
|
||||||
* @exportedAs angular2/di
|
* @exportedAs angular2/di
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Self extends Visibility {
|
export class SelfMetadata extends VisibilityMetadata {
|
||||||
constructor() { super(0, false, true); }
|
constructor() { super(0, false, true); }
|
||||||
toString(): string { return `@Self()`; }
|
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.
|
* 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
|
* @exportedAs angular2/di
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Parent extends Visibility {
|
export class ParentMetadata extends VisibilityMetadata {
|
||||||
constructor({self}: {self?: boolean} = {}) { super(1, false, self); }
|
constructor({self}: {self?: boolean} = {}) { super(1, false, self); }
|
||||||
toString(): string { return `@Parent(self: ${this.includeSelf}})`; }
|
toString(): string { return `@Parent(self: ${this.includeSelf}})`; }
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ export class Parent extends Visibility {
|
||||||
* @exportedAs angular2/di
|
* @exportedAs angular2/di
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Ancestor extends Visibility {
|
export class AncestorMetadata extends VisibilityMetadata {
|
||||||
constructor({self}: {self?: boolean} = {}) { super(999999, false, self); }
|
constructor({self}: {self?: boolean} = {}) { super(999999, false, self); }
|
||||||
toString(): string { return `@Ancestor(self: ${this.includeSelf}})`; }
|
toString(): string { return `@Ancestor(self: ${this.includeSelf}})`; }
|
||||||
}
|
}
|
||||||
|
@ -247,9 +247,9 @@ export class Ancestor extends Visibility {
|
||||||
* @exportedAs angular2/di
|
* @exportedAs angular2/di
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class Unbounded extends Visibility {
|
export class UnboundedMetadata extends VisibilityMetadata {
|
||||||
constructor({self}: {self?: boolean} = {}) { super(999999, true, self); }
|
constructor({self}: {self?: boolean} = {}) { super(999999, true, self); }
|
||||||
toString(): string { return `@Unbounded(self: ${this.includeSelf}})`; }
|
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
|
/// on a class. These classes are re-exported in many places so this covers all
|
||||||
/// the possible libraries which could provide them.
|
/// the possible libraries which could provide them.
|
||||||
const INJECTABLES = const [
|
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(
|
const AnnotationDescriptor(
|
||||||
'Injectable', 'package:angular2/src/di/decorators.dart', null),
|
'Injectable', 'package:angular2/src/di/decorators.dart', null),
|
||||||
const AnnotationDescriptor('Injectable', 'package:angular2/di.dart', null),
|
const AnnotationDescriptor('Injectable', 'package:angular2/di.dart', null),
|
||||||
|
|
|
@ -40,8 +40,7 @@ import {
|
||||||
Directive,
|
Directive,
|
||||||
onDestroy
|
onDestroy
|
||||||
} from 'angular2/annotations';
|
} from 'angular2/annotations';
|
||||||
import {bind, Injector, Binding, resolveBindings, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self} from 'angular2/di';
|
import {bind, Injector, Binding, resolveBindings, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, self, InjectMetadata, ParentMetadata} from 'angular2/di';
|
||||||
import * as diAnn from 'angular2/src/di/annotations_impl';
|
|
||||||
import {AppProtoView, AppView} from 'angular2/src/core/compiler/view';
|
import {AppProtoView, AppView} from 'angular2/src/core/compiler/view';
|
||||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||||
import {ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
|
import {ProtoViewRef} from 'angular2/src/core/compiler/view_ref';
|
||||||
|
@ -595,7 +594,7 @@ export function main() {
|
||||||
bind('injectable2')
|
bind('injectable2')
|
||||||
.toFactory(
|
.toFactory(
|
||||||
(val) => `${val}-injectable2`,
|
(val) => `${val}-injectable2`,
|
||||||
[[new diAnn.Inject('injectable1'), new diAnn.Parent()]])
|
[[new InjectMetadata('injectable1'), new ParentMetadata()]])
|
||||||
]
|
]
|
||||||
}))]);
|
}))]);
|
||||||
expect(childInj.get('injectable2')).toEqual('injectable1-injectable2');
|
expect(childInj.get('injectable2')).toEqual('injectable1-injectable2');
|
||||||
|
|
|
@ -43,7 +43,8 @@ import {
|
||||||
Inject,
|
Inject,
|
||||||
Parent,
|
Parent,
|
||||||
Ancestor,
|
Ancestor,
|
||||||
Unbounded
|
Unbounded,
|
||||||
|
UnboundedMetadata
|
||||||
} from 'angular2/di';
|
} from 'angular2/di';
|
||||||
import {
|
import {
|
||||||
PipeFactory,
|
PipeFactory,
|
||||||
|
@ -58,7 +59,6 @@ import {
|
||||||
|
|
||||||
import {Directive, Component, View, Attribute, Query} from 'angular2/annotations';
|
import {Directive, Component, View, Attribute, Query} from 'angular2/annotations';
|
||||||
import * as viewAnn from 'angular2/src/core/annotations_impl/view';
|
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';
|
import {QueryList} from 'angular2/src/core/compiler/query_list';
|
||||||
|
|
||||||
|
@ -1779,7 +1779,7 @@ function createParentBus(peb) {
|
||||||
selector: 'parent-providing-event-bus',
|
selector: 'parent-providing-event-bus',
|
||||||
hostInjector: [
|
hostInjector: [
|
||||||
new Binding(EventBus,
|
new Binding(EventBus,
|
||||||
{toFactory: createParentBus, deps: [[EventBus, new visAnn.Unbounded()]]})
|
{toFactory: createParentBus, deps: [[EventBus, new UnboundedMetadata()]]})
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
@View({
|
@View({
|
||||||
|
|
|
@ -14,20 +14,22 @@ import {
|
||||||
ResolvedBinding,
|
ResolvedBinding,
|
||||||
Key,
|
Key,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
DependencyAnnotation,
|
DependencyMetadata,
|
||||||
Injectable
|
Injectable,
|
||||||
|
InjectMetadata,
|
||||||
|
self,
|
||||||
|
unbounded
|
||||||
} from 'angular2/di';
|
} from 'angular2/di';
|
||||||
|
|
||||||
import {InjectorInlineStrategy, InjectorDynamicStrategy} from 'angular2/src/di/injector';
|
import {InjectorInlineStrategy, InjectorDynamicStrategy} from 'angular2/src/di/injector';
|
||||||
|
|
||||||
import {Optional, Inject} from 'angular2/src/di/decorators';
|
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 {}
|
class Engine {}
|
||||||
|
|
||||||
@Injectable(ann.self)
|
@Injectable(self)
|
||||||
class EngineWithSetVisibility {
|
class EngineWithSetVisibility {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,12 +409,12 @@ export function main() {
|
||||||
var bindings = Injector.resolve([
|
var bindings = Injector.resolve([
|
||||||
bind("token")
|
bind("token")
|
||||||
.toFactory((e) => "result",
|
.toFactory((e) => "result",
|
||||||
[[new ann.Inject("dep"), new CustomDependencyAnnotation()]])
|
[[new InjectMetadata("dep"), new CustomDependencyMetadata()]])
|
||||||
]);
|
]);
|
||||||
var binding = bindings[0];
|
var binding = bindings[0];
|
||||||
|
|
||||||
expect(binding.dependencies[0].key.token).toEqual("dep");
|
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", () => {
|
it("should use the provided visibility", () => {
|
||||||
var bindings = Injector.resolve([CarNeedsEngineWithSetVisibility, EngineWithSetVisibility]);
|
var bindings = Injector.resolve([CarNeedsEngineWithSetVisibility, EngineWithSetVisibility]);
|
||||||
var carBinding = bindings[0];
|
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", () => {
|
it("should set the default visibility to unbounded", () => {
|
||||||
var bindings = Injector.resolve([Car, Engine]);
|
var bindings = Injector.resolve([Car, Engine]);
|
||||||
var carBinding = bindings[0];
|
var carBinding = bindings[0];
|
||||||
expect(carBinding.dependencies[0].visibility).toEqual(ann.unbounded);
|
expect(carBinding.dependencies[0].visibility).toEqual(unbounded);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,8 +43,8 @@ void allTests() {
|
||||||
'angular2|lib/src/reflection/reflection_capabilities.dart':
|
'angular2|lib/src/reflection/reflection_capabilities.dart':
|
||||||
'../common/reflection_capabilities.dart',
|
'../common/reflection_capabilities.dart',
|
||||||
'angular2|lib/di.dart': '../../../lib/di.dart',
|
'angular2|lib/di.dart': '../../../lib/di.dart',
|
||||||
'angular2|lib/src/di/annotations_impl.dart':
|
'angular2|lib/src/di/decorators.dart':
|
||||||
'../../../lib/src/di/annotations_impl.dart',
|
'../../../lib/src/di/decorators.dart',
|
||||||
};
|
};
|
||||||
|
|
||||||
var tests = [
|
var tests = [
|
||||||
|
|
Loading…
Reference in New Issue