refactor(Provider): remove deprecated provider/bind API (#10652)
Closes #9751 BREAKING CHANGE: These forms of providers are no longer accepted: bind(MyClass).toFactory(...) new Provider(MyClass, toFactory: ...) We now only accept: {provider: MyClass, toFactory: ...}
This commit is contained in:
parent
04c11bb749
commit
bec5c5fdad
|
@ -6,8 +6,11 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {Provider} from '@angular/core';
|
||||||
|
|
||||||
import {CORE_DIRECTIVES} from './directives';
|
import {CORE_DIRECTIVES} from './directives';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of Angular core directives that are likely to be used in each and every Angular
|
* A collection of Angular core directives that are likely to be used in each and every Angular
|
||||||
* application. This includes core directives (e.g., NgIf and NgFor), and forms directives (e.g.,
|
* application. This includes core directives (e.g., NgIf and NgFor), and forms directives (e.g.,
|
||||||
|
@ -53,4 +56,4 @@ import {CORE_DIRECTIVES} from './directives';
|
||||||
*
|
*
|
||||||
* @experimental Contains forms which are experimental.
|
* @experimental Contains forms which are experimental.
|
||||||
*/
|
*/
|
||||||
export const COMMON_DIRECTIVES: any[] = CORE_DIRECTIVES;
|
export const COMMON_DIRECTIVES: Provider[] = CORE_DIRECTIVES;
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {AttributeMetadata, ComponentMetadata, ContentChildMetadata, ContentChildrenMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, HostMetadata, InjectMetadata, InjectableMetadata, InputMetadata, NgModuleMetadata, OptionalMetadata, OutputMetadata, PipeMetadata, Provider, QueryMetadata, SelfMetadata, SkipSelfMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
import {AttributeMetadata, ComponentMetadata, ContentChildMetadata, ContentChildrenMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, HostMetadata, InjectMetadata, InjectableMetadata, InputMetadata, NgModuleMetadata, OptionalMetadata, OutputMetadata, PipeMetadata, QueryMetadata, SelfMetadata, SkipSelfMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
||||||
|
|
||||||
import {ReflectorReader} from './core_private';
|
import {ReflectorReader} from './core_private';
|
||||||
|
|
||||||
|
@ -175,7 +175,6 @@ export class StaticReflector implements ReflectorReader {
|
||||||
const {coreDecorators, diDecorators, diMetadata, diOpaqueToken, animationMetadata, provider} =
|
const {coreDecorators, diDecorators, diMetadata, diOpaqueToken, animationMetadata, provider} =
|
||||||
this.host.angularImportLocations();
|
this.host.angularImportLocations();
|
||||||
this.opaqueToken = this.host.findDeclaration(diOpaqueToken, 'OpaqueToken');
|
this.opaqueToken = this.host.findDeclaration(diOpaqueToken, 'OpaqueToken');
|
||||||
this.registerDecoratorOrConstructor(this.host.findDeclaration(provider, 'Provider'), Provider);
|
|
||||||
|
|
||||||
this.registerDecoratorOrConstructor(
|
this.registerDecoratorOrConstructor(
|
||||||
this.host.findDeclaration(diDecorators, 'Host'), HostMetadata);
|
this.host.findDeclaration(diDecorators, 'Host'), HostMetadata);
|
||||||
|
|
|
@ -46,8 +46,6 @@ export var ValueUnwrapper: typeof t.ValueUnwrapper = r.ValueUnwrapper;
|
||||||
export var TemplateRef_: typeof t.TemplateRef_ = r.TemplateRef_;
|
export var TemplateRef_: typeof t.TemplateRef_ = r.TemplateRef_;
|
||||||
export type RenderDebugInfo = t.RenderDebugInfo;
|
export type RenderDebugInfo = t.RenderDebugInfo;
|
||||||
export var RenderDebugInfo: typeof t.RenderDebugInfo = r.RenderDebugInfo;
|
export var RenderDebugInfo: typeof t.RenderDebugInfo = r.RenderDebugInfo;
|
||||||
export var createProvider: typeof t.createProvider = r.createProvider;
|
|
||||||
export var isProviderLiteral: typeof t.isProviderLiteral = r.isProviderLiteral;
|
|
||||||
export var EMPTY_ARRAY: typeof t.EMPTY_ARRAY = r.EMPTY_ARRAY;
|
export var EMPTY_ARRAY: typeof t.EMPTY_ARRAY = r.EMPTY_ARRAY;
|
||||||
export var EMPTY_MAP: typeof t.EMPTY_MAP = r.EMPTY_MAP;
|
export var EMPTY_MAP: typeof t.EMPTY_MAP = r.EMPTY_MAP;
|
||||||
export var pureProxy1: typeof t.pureProxy1 = r.pureProxy1;
|
export var pureProxy1: typeof t.pureProxy1 = r.pureProxy1;
|
||||||
|
|
|
@ -720,3 +720,30 @@ export interface StaticSymbol {
|
||||||
name: string;
|
name: string;
|
||||||
filePath: string;
|
filePath: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ProviderMeta {
|
||||||
|
token: any;
|
||||||
|
useClass: Type<any>;
|
||||||
|
useValue: any;
|
||||||
|
useExisting: any;
|
||||||
|
useFactory: Function;
|
||||||
|
dependencies: Object[];
|
||||||
|
multi: boolean;
|
||||||
|
|
||||||
|
constructor(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
|
||||||
|
useClass?: Type<any>,
|
||||||
|
useValue?: any,
|
||||||
|
useExisting?: any,
|
||||||
|
useFactory?: Function,
|
||||||
|
deps?: Object[],
|
||||||
|
multi?: boolean
|
||||||
|
}) {
|
||||||
|
this.token = token;
|
||||||
|
this.useClass = useClass;
|
||||||
|
this.useValue = useValue;
|
||||||
|
this.useExisting = useExisting;
|
||||||
|
this.useFactory = useFactory;
|
||||||
|
this.dependencies = deps;
|
||||||
|
this.multi = !!multi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, AttributeMetadata, ChangeDetectionStrategy, ComponentMetadata, HostMetadata, InjectMetadata, Injectable, ModuleWithProviders, OptionalMetadata, Provider, QueryMetadata, SchemaMetadata, SelfMetadata, SkipSelfMetadata, Type, ViewQueryMetadata, resolveForwardRef} from '@angular/core';
|
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, AttributeMetadata, ChangeDetectionStrategy, ComponentMetadata, HostMetadata, InjectMetadata, Injectable, ModuleWithProviders, OptionalMetadata, Provider, QueryMetadata, SchemaMetadata, SelfMetadata, SkipSelfMetadata, Type, ViewQueryMetadata, resolveForwardRef} from '@angular/core';
|
||||||
|
|
||||||
import {Console, LIFECYCLE_HOOKS_VALUES, ReflectorReader, createProvider, isProviderLiteral, reflector} from '../core_private';
|
import {Console, LIFECYCLE_HOOKS_VALUES, ReflectorReader, reflector} from '../core_private';
|
||||||
import {StringMapWrapper} from '../src/facade/collection';
|
import {StringMapWrapper} from '../src/facade/collection';
|
||||||
|
|
||||||
import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
|
import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
|
||||||
|
@ -616,18 +616,18 @@ export class CompileMetadataResolver {
|
||||||
return compileToken;
|
return compileToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
getProvidersMetadata(providers: any[], targetEntryComponents: cpl.CompileTypeMetadata[]):
|
getProvidersMetadata(providers: Provider[], targetEntryComponents: cpl.CompileTypeMetadata[]):
|
||||||
Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> {
|
Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> {
|
||||||
const compileProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = [];
|
const compileProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = [];
|
||||||
providers.forEach((provider) => {
|
providers.forEach((provider: any) => {
|
||||||
provider = resolveForwardRef(provider);
|
provider = resolveForwardRef(provider);
|
||||||
if (isProviderLiteral(provider)) {
|
if (provider && typeof provider == 'object' && provider.hasOwnProperty('provide')) {
|
||||||
provider = createProvider(provider);
|
provider = new cpl.ProviderMeta(provider.provide, provider);
|
||||||
}
|
}
|
||||||
let compileProvider: cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[];
|
let compileProvider: cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[];
|
||||||
if (isArray(provider)) {
|
if (isArray(provider)) {
|
||||||
compileProvider = this.getProvidersMetadata(provider, targetEntryComponents);
|
compileProvider = this.getProvidersMetadata(provider, targetEntryComponents);
|
||||||
} else if (provider instanceof Provider) {
|
} else if (provider instanceof cpl.ProviderMeta) {
|
||||||
let tokenMeta = this.getTokenMetadata(provider.token);
|
let tokenMeta = this.getTokenMetadata(provider.token);
|
||||||
if (tokenMeta.equalsTo(identifierToken(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS))) {
|
if (tokenMeta.equalsTo(identifierToken(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS))) {
|
||||||
targetEntryComponents.push(...this._getEntryComponentsFromProvider(provider));
|
targetEntryComponents.push(...this._getEntryComponentsFromProvider(provider));
|
||||||
|
@ -647,7 +647,7 @@ export class CompileMetadataResolver {
|
||||||
return compileProviders;
|
return compileProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getEntryComponentsFromProvider(provider: Provider): cpl.CompileTypeMetadata[] {
|
private _getEntryComponentsFromProvider(provider: cpl.ProviderMeta): cpl.CompileTypeMetadata[] {
|
||||||
let components: cpl.CompileTypeMetadata[] = [];
|
let components: cpl.CompileTypeMetadata[] = [];
|
||||||
let collectedIdentifiers: cpl.CompileIdentifierMetadata[] = [];
|
let collectedIdentifiers: cpl.CompileIdentifierMetadata[] = [];
|
||||||
if (provider.useFactory || provider.useExisting || provider.useClass) {
|
if (provider.useFactory || provider.useExisting || provider.useClass) {
|
||||||
|
@ -667,7 +667,7 @@ export class CompileMetadataResolver {
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
getProviderMetadata(provider: Provider): cpl.CompileProviderMetadata {
|
getProviderMetadata(provider: cpl.ProviderMeta): cpl.CompileProviderMetadata {
|
||||||
var compileDeps: cpl.CompileDiDependencyMetadata[];
|
var compileDeps: cpl.CompileDiDependencyMetadata[];
|
||||||
var compileTypeMetadata: cpl.CompileTypeMetadata = null;
|
var compileTypeMetadata: cpl.CompileTypeMetadata = null;
|
||||||
var compileFactoryMetadata: cpl.CompileFactoryMetadata = null;
|
var compileFactoryMetadata: cpl.CompileFactoryMetadata = null;
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Compiler, ComponentFactory, ComponentResolver, ComponentStillLoadingError, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, OptionalMetadata, Provider, SchemaMetadata, SkipSelfMetadata, Type} from '@angular/core';
|
import {Compiler, ComponentFactory, ComponentResolver, ComponentStillLoadingError, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, OptionalMetadata, SchemaMetadata, SkipSelfMetadata, Type} from '@angular/core';
|
||||||
|
|
||||||
import {Console} from '../core_private';
|
import {Console} from '../core_private';
|
||||||
|
|
||||||
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, createHostComponentMeta} from './compile_metadata';
|
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, ProviderMeta, createHostComponentMeta} from './compile_metadata';
|
||||||
import {CompilerConfig} from './config';
|
import {CompilerConfig} from './config';
|
||||||
import {DirectiveNormalizer} from './directive_normalizer';
|
import {DirectiveNormalizer} from './directive_normalizer';
|
||||||
import {BaseException} from './facade/exceptions';
|
import {BaseException} from './facade/exceptions';
|
||||||
|
@ -129,12 +129,12 @@ export class RuntimeCompiler implements Compiler {
|
||||||
new ModuleBoundCompiler(this, moduleMeta.type.runtime, parentResolver, this._console);
|
new ModuleBoundCompiler(this, moduleMeta.type.runtime, parentResolver, this._console);
|
||||||
// Always provide a bound Compiler and ComponentResolver
|
// Always provide a bound Compiler and ComponentResolver
|
||||||
const extraProviders = [
|
const extraProviders = [
|
||||||
this._metadataResolver.getProviderMetadata(new Provider(Compiler, {
|
this._metadataResolver.getProviderMetadata(new ProviderMeta(Compiler, {
|
||||||
useFactory: boundCompilerFactory,
|
useFactory: boundCompilerFactory,
|
||||||
deps: [[new OptionalMetadata(), new SkipSelfMetadata(), ComponentResolver]]
|
deps: [[new OptionalMetadata(), new SkipSelfMetadata(), ComponentResolver]]
|
||||||
})),
|
})),
|
||||||
this._metadataResolver.getProviderMetadata(
|
this._metadataResolver.getProviderMetadata(
|
||||||
new Provider(ComponentResolver, {useExisting: Compiler}))
|
new ProviderMeta(ComponentResolver, {useExisting: Compiler}))
|
||||||
];
|
];
|
||||||
var compileResult = this._ngModuleCompiler.compile(moduleMeta, extraProviders);
|
var compileResult = this._ngModuleCompiler.compile(moduleMeta, extraProviders);
|
||||||
compileResult.dependencies.forEach((dep) => {
|
compileResult.dependencies.forEach((dep) => {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Provider} from './index';
|
|
||||||
import {ANY_STATE as ANY_STATE_, DEFAULT_STATE as DEFAULT_STATE_, EMPTY_STATE as EMPTY_STATE_, FILL_STYLE_FLAG as FILL_STYLE_FLAG_} from './src/animation/animation_constants';
|
import {ANY_STATE as ANY_STATE_, DEFAULT_STATE as DEFAULT_STATE_, EMPTY_STATE as EMPTY_STATE_, FILL_STYLE_FLAG as FILL_STYLE_FLAG_} from './src/animation/animation_constants';
|
||||||
import {AnimationGroupPlayer as AnimationGroupPlayer_} from './src/animation/animation_group_player';
|
import {AnimationGroupPlayer as AnimationGroupPlayer_} from './src/animation/animation_group_player';
|
||||||
import {AnimationKeyframe as AnimationKeyframe_} from './src/animation/animation_keyframe';
|
import {AnimationKeyframe as AnimationKeyframe_} from './src/animation/animation_keyframe';
|
||||||
|
@ -18,7 +17,7 @@ import * as change_detection_util from './src/change_detection/change_detection_
|
||||||
import * as constants from './src/change_detection/constants';
|
import * as constants from './src/change_detection/constants';
|
||||||
import * as console from './src/console';
|
import * as console from './src/console';
|
||||||
import * as debug from './src/debug/debug_renderer';
|
import * as debug from './src/debug/debug_renderer';
|
||||||
import * as provider_util from './src/di/provider_util';
|
import * as provider from './src/di/provider';
|
||||||
import * as reflective_provider from './src/di/reflective_provider';
|
import * as reflective_provider from './src/di/reflective_provider';
|
||||||
import * as component_factory_resolver from './src/linker/component_factory_resolver';
|
import * as component_factory_resolver from './src/linker/component_factory_resolver';
|
||||||
import * as component_resolver from './src/linker/component_resolver';
|
import * as component_resolver from './src/linker/component_resolver';
|
||||||
|
@ -83,8 +82,6 @@ export declare namespace __core_private_types__ {
|
||||||
export var makeDecorator: typeof decorators.makeDecorator;
|
export var makeDecorator: typeof decorators.makeDecorator;
|
||||||
export type DebugDomRootRenderer = debug.DebugDomRootRenderer;
|
export type DebugDomRootRenderer = debug.DebugDomRootRenderer;
|
||||||
export var DebugDomRootRenderer: typeof debug.DebugDomRootRenderer;
|
export var DebugDomRootRenderer: typeof debug.DebugDomRootRenderer;
|
||||||
export var createProvider: typeof provider_util.createProvider;
|
|
||||||
export var isProviderLiteral: typeof provider_util.isProviderLiteral;
|
|
||||||
export var EMPTY_ARRAY: typeof view_utils.EMPTY_ARRAY;
|
export var EMPTY_ARRAY: typeof view_utils.EMPTY_ARRAY;
|
||||||
export var EMPTY_MAP: typeof view_utils.EMPTY_MAP;
|
export var EMPTY_MAP: typeof view_utils.EMPTY_MAP;
|
||||||
export var pureProxy1: typeof view_utils.pureProxy1;
|
export var pureProxy1: typeof view_utils.pureProxy1;
|
||||||
|
@ -158,8 +155,6 @@ export var __core_private__ = {
|
||||||
ReflectionCapabilities: reflection_capabilities.ReflectionCapabilities,
|
ReflectionCapabilities: reflection_capabilities.ReflectionCapabilities,
|
||||||
makeDecorator: decorators.makeDecorator,
|
makeDecorator: decorators.makeDecorator,
|
||||||
DebugDomRootRenderer: debug.DebugDomRootRenderer,
|
DebugDomRootRenderer: debug.DebugDomRootRenderer,
|
||||||
createProvider: provider_util.createProvider,
|
|
||||||
isProviderLiteral: provider_util.isProviderLiteral,
|
|
||||||
EMPTY_ARRAY: view_utils.EMPTY_ARRAY,
|
EMPTY_ARRAY: view_utils.EMPTY_ARRAY,
|
||||||
EMPTY_MAP: view_utils.EMPTY_MAP,
|
EMPTY_MAP: view_utils.EMPTY_MAP,
|
||||||
pureProxy1: view_utils.pureProxy1,
|
pureProxy1: view_utils.pureProxy1,
|
||||||
|
|
|
@ -80,7 +80,8 @@ export class IterableDiffers {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
static extend(factories: IterableDifferFactory[]): Provider {
|
static extend(factories: IterableDifferFactory[]): Provider {
|
||||||
return new Provider(IterableDiffers, {
|
return {
|
||||||
|
provide: IterableDiffers,
|
||||||
useFactory: (parent: IterableDiffers) => {
|
useFactory: (parent: IterableDiffers) => {
|
||||||
if (isBlank(parent)) {
|
if (isBlank(parent)) {
|
||||||
// Typically would occur when calling IterableDiffers.extend inside of dependencies passed
|
// Typically would occur when calling IterableDiffers.extend inside of dependencies passed
|
||||||
|
@ -92,7 +93,7 @@ export class IterableDiffers {
|
||||||
},
|
},
|
||||||
// Dependency technically isn't optional, but we can provide a better error message this way.
|
// Dependency technically isn't optional, but we can provide a better error message this way.
|
||||||
deps: [[IterableDiffers, new SkipSelfMetadata(), new OptionalMetadata()]]
|
deps: [[IterableDiffers, new SkipSelfMetadata(), new OptionalMetadata()]]
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
find(iterable: any): IterableDifferFactory {
|
find(iterable: any): IterableDifferFactory {
|
||||||
|
|
|
@ -70,7 +70,8 @@ export class KeyValueDiffers {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
static extend(factories: KeyValueDifferFactory[]): Provider {
|
static extend(factories: KeyValueDifferFactory[]): Provider {
|
||||||
return new Provider(KeyValueDiffers, {
|
return {
|
||||||
|
provide: KeyValueDiffers,
|
||||||
useFactory: (parent: KeyValueDiffers) => {
|
useFactory: (parent: KeyValueDiffers) => {
|
||||||
if (isBlank(parent)) {
|
if (isBlank(parent)) {
|
||||||
// Typically would occur when calling KeyValueDiffers.extend inside of dependencies passed
|
// Typically would occur when calling KeyValueDiffers.extend inside of dependencies passed
|
||||||
|
@ -82,7 +83,7 @@ export class KeyValueDiffers {
|
||||||
},
|
},
|
||||||
// Dependency technically isn't optional, but we can provide a better error message this way.
|
// Dependency technically isn't optional, but we can provide a better error message this way.
|
||||||
deps: [[KeyValueDiffers, new SkipSelfMetadata(), new OptionalMetadata()]]
|
deps: [[KeyValueDiffers, new SkipSelfMetadata(), new OptionalMetadata()]]
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
find(kv: Object): KeyValueDifferFactory {
|
find(kv: Object): KeyValueDifferFactory {
|
||||||
|
|
|
@ -22,7 +22,7 @@ export {forwardRef, resolveForwardRef, ForwardRefFn} from './di/forward_ref';
|
||||||
|
|
||||||
export {Injector} from './di/injector';
|
export {Injector} from './di/injector';
|
||||||
export {ReflectiveInjector} from './di/reflective_injector';
|
export {ReflectiveInjector} from './di/reflective_injector';
|
||||||
export {Binding, ProviderBuilder, bind, Provider, provide} from './di/provider';
|
export {Provider, TypeProvider, ValueProvider, ClassProvider, ExistingProvider, FactoryProvider} from './di/provider';
|
||||||
export {ResolvedReflectiveBinding, ResolvedReflectiveFactory, ResolvedReflectiveProvider} from './di/reflective_provider';
|
export {ResolvedReflectiveBinding, ResolvedReflectiveFactory, ResolvedReflectiveProvider} from './di/reflective_provider';
|
||||||
export {ReflectiveKey} from './di/reflective_key';
|
export {ReflectiveKey} from './di/reflective_key';
|
||||||
export {NoProviderError, AbstractProviderError, CyclicDependencyError, InstantiationError, InvalidProviderError, NoAnnotationError, OutOfBoundsError} from './di/reflective_exceptions';
|
export {NoProviderError, AbstractProviderError, CyclicDependencyError, InstantiationError, InvalidProviderError, NoAnnotationError, OutOfBoundsError} from './di/reflective_exceptions';
|
||||||
|
|
|
@ -6,410 +6,344 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseException} from '../facade/exceptions';
|
|
||||||
import {isBlank, isFunction, isType, normalizeBool, stringify} from '../facade/lang';
|
|
||||||
import {Type} from '../type';
|
import {Type} from '../type';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes how the {@link Injector} should instantiate a given token.
|
* Configures the {@link Injector} to return an instance of `Type` when `Type' is used as token.
|
||||||
*
|
*
|
||||||
* See {@link provide}.
|
* Create an instance by invoking the `new` operator and supplying additional arguments.
|
||||||
*
|
* This form is a short form of `TypeProvider`;
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/GNAyj6K6PfYg2NBzgwZ5?p%3Dpreview&p=preview))
|
|
||||||
*
|
*
|
||||||
|
* ### Example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* var injector = Injector.resolveAndCreate([
|
* @Injectable()
|
||||||
* new Provider("message", { useValue: 'Hello' })
|
* class Greeting {
|
||||||
|
* text: 'Hello';
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @Injectable()
|
||||||
|
* class MyClass {
|
||||||
|
* greeting:string;
|
||||||
|
* constructor(greeting: Greeting) {
|
||||||
|
* this.greeting = greeting.text;
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* const injector = Injector.resolveAndCreate([
|
||||||
|
* Greeting, // Shorthand for { provide: Greeting, useClass: Greeting }
|
||||||
|
* MyClass // Shorthand for { provide: MyClass, useClass: MyClass }
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injector.get("message")).toEqual('Hello');
|
* const myClass: MyClass = injector.get(MyClass);
|
||||||
|
* expect(myClass.greeting).toEqual('Hello');
|
||||||
* ```
|
* ```
|
||||||
* @deprecated
|
*
|
||||||
|
* @stable
|
||||||
*/
|
*/
|
||||||
export class Provider {
|
export interface TypeProvider extends Type<any> {}
|
||||||
/**
|
|
||||||
* Token used when retrieving this provider. Usually, it is a type {@link Type}.
|
|
||||||
*/
|
|
||||||
token: any;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds a DI token to an implementation class.
|
* Configures the {@link Injector} to return a value for a token.
|
||||||
*
|
*
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/RSTG86qgmoxCyj9SWPwY?p=preview))
|
* ### Example
|
||||||
*
|
* const injector = Injector.resolveAndCreate([
|
||||||
* Because `useExisting` and `useClass` are often confused, the example contains
|
* {provide: String, useValue: 'Hello'}
|
||||||
* both use cases for easy comparison.
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* class Vehicle {}
|
|
||||||
*
|
|
||||||
* class Car extends Vehicle {}
|
|
||||||
*
|
|
||||||
* var injectorClass = Injector.resolveAndCreate([
|
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useClass: Car }
|
|
||||||
* ]);
|
|
||||||
* var injectorAlias = Injector.resolveAndCreate([
|
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useExisting: Car }
|
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
* expect(injector.get(String)).toEqual('Hello');
|
||||||
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
|
|
||||||
*
|
|
||||||
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
|
||||||
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
|
|
||||||
* ```
|
* ```
|
||||||
|
* @stable
|
||||||
*/
|
*/
|
||||||
useClass: Type<any>;
|
export interface ValueProvider {
|
||||||
|
/**
|
||||||
|
* An injection token. (Typically an instance of `Type` or `OpaqueToken`, but can be `any`).
|
||||||
|
*/
|
||||||
|
provide: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds a DI token to a value.
|
* The value to inject.
|
||||||
*
|
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/UFVsMVQIDe7l4waWziES?p=preview))
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* var injector = Injector.resolveAndCreate([
|
|
||||||
* new Provider("message", { useValue: 'Hello' })
|
|
||||||
* ]);
|
|
||||||
*
|
|
||||||
* expect(injector.get("message")).toEqual('Hello');
|
|
||||||
* ```
|
|
||||||
*/
|
*/
|
||||||
useValue: any;
|
useValue: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds a DI token to an existing token.
|
* If true, than injector returns an array of instances. This is useful to allow multiple
|
||||||
|
* providers spread across many files to provide configuration information to a common token.
|
||||||
*
|
*
|
||||||
* {@link Injector} returns the same instance as if the provided token was used.
|
* ### Example
|
||||||
* This is in contrast to `useClass` where a separate instance of `useClass` is returned.
|
* ```javascript
|
||||||
|
* var locale = new OpaqueToken('local');
|
||||||
*
|
*
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/QsatsOJJ6P8T2fMe9gr8?p=preview))
|
* const injector = Injector.resolveAndCreate([
|
||||||
*
|
* { provide: locale, useValue: 'en' },
|
||||||
* Because `useExisting` and `useClass` are often confused the example contains
|
* { provide: locale, useValue: 'sk' },
|
||||||
* both use cases for easy comparison.
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* class Vehicle {}
|
|
||||||
*
|
|
||||||
* class Car extends Vehicle {}
|
|
||||||
*
|
|
||||||
* var injectorAlias = Injector.resolveAndCreate([
|
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useExisting: Car }
|
|
||||||
* ]);
|
|
||||||
* var injectorClass = Injector.resolveAndCreate([
|
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useClass: Car }
|
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
* const locales: string[] = injector.get(locale);
|
||||||
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
|
* expect(locales).toEqual(['en', 'sk']);
|
||||||
*
|
|
||||||
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
|
||||||
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
|
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
multi?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the {@link Injector} to return an instance of `useClass` for a token.
|
||||||
|
*
|
||||||
|
* ### Example
|
||||||
|
* ```javascript
|
||||||
|
* abstract class Shape {
|
||||||
|
* name: string;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* class Square extends Shape {
|
||||||
|
* name = 'square';
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* const injector = Injector.resolveAndCreate([
|
||||||
|
* {provide: Shape, useClass: Square}
|
||||||
|
* ]);
|
||||||
|
*
|
||||||
|
* const shape: Shape = injector.get(Shape);
|
||||||
|
* expect(shape.name).toEqual('square');
|
||||||
|
* expect(shape instanceof Square).toBe(true);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* Note that following is not equal:
|
||||||
|
* ```javascript
|
||||||
|
* class Greeting {
|
||||||
|
* salutation = 'Hello';
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* class FormalGreeting extends Greeting {
|
||||||
|
* salutation = 'Greetings';
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* const injector = Injector.resolveAndCreate([
|
||||||
|
* FormalGreeting,
|
||||||
|
* {provide: Greeting, useClass: FormalGreeting}
|
||||||
|
* ]);
|
||||||
|
*
|
||||||
|
* // The injector returns different instances.
|
||||||
|
* // See: {provide: ?, useExisting: ?} if you want the same instance.
|
||||||
|
* expect(injector.get(FormalGreeting)).not.toBe(injector.get(Greeting));
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @stable
|
||||||
|
*/
|
||||||
|
export interface ClassProvider {
|
||||||
|
/**
|
||||||
|
* An injection token. (Typically an instance of `Type` or `OpaqueToken`, but can be `any`).
|
||||||
|
*/
|
||||||
|
provide: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to instantiate for the `token`.
|
||||||
|
*/
|
||||||
|
useClass: Type<any>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, than injector returns an array of instances. This is useful to allow multiple
|
||||||
|
* providers spread across many files to provide configuration information to a common token.
|
||||||
|
*
|
||||||
|
* ### Example
|
||||||
|
* ```javascript
|
||||||
|
* abstract class Locale {
|
||||||
|
* name: string;
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* @Injectable()
|
||||||
|
* class EnLocale extends Locale {
|
||||||
|
* name: 'en';
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* @Injectable()
|
||||||
|
* class SkLocale extends Locale {
|
||||||
|
* name: 'sk';
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* const injector = Injector.resolveAndCreate([
|
||||||
|
* { provide: Locale, useValue: EnLocale, multi: true },
|
||||||
|
* { provide: Locale, useValue: SkLocale, multi: true },
|
||||||
|
* ]);
|
||||||
|
*
|
||||||
|
* const locales: Locale[] = injector.get(Locale);
|
||||||
|
* const localeNames: string[] = locals.map((l) => l.name);
|
||||||
|
* expect(localeNames).toEqual(['en', 'sk']);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
multi?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the {@link Injector} to return a value of another `useExisting` token.
|
||||||
|
*
|
||||||
|
* ### Example
|
||||||
|
* ```javascript
|
||||||
|
* class Greeting {
|
||||||
|
* salutation = 'Hello';
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* class FormalGreeting extends Greeting {
|
||||||
|
* salutation = 'Greetings';
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* const injector = Injector.resolveAndCreate([
|
||||||
|
* FormalGreeting,
|
||||||
|
* {provide: Greeting, useExisting: FormalGreeting}
|
||||||
|
* ]);
|
||||||
|
*
|
||||||
|
* expect(injector.get(Greeting).name).toEqual('Hello');
|
||||||
|
* expect(injector.get(FormalGreeting).name).toEqual('Hello');
|
||||||
|
* expect(injector.get(Salutation).name).toBe(injector.get(Greeting));
|
||||||
|
* ```
|
||||||
|
* @stable
|
||||||
|
*/
|
||||||
|
export interface ExistingProvider {
|
||||||
|
/**
|
||||||
|
* An injection token. (Typically an instance of `Type` or `OpaqueToken`, but can be `any`).
|
||||||
|
*/
|
||||||
|
provide: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Existing `token` to return. (equivalent to `injector.get(useExisting)`)
|
||||||
|
*/
|
||||||
useExisting: any;
|
useExisting: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds a DI token to a function which computes the value.
|
* If true, than injector returns an array of instances. This is useful to allow multiple
|
||||||
|
* providers spread across many files to provide configuration information to a common token.
|
||||||
*
|
*
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/Scoxy0pJNqKGAPZY1VVC?p=preview))
|
* ### Example
|
||||||
|
* ```javascript
|
||||||
|
* abstract class Locale {
|
||||||
|
* name: string;
|
||||||
|
* };
|
||||||
*
|
*
|
||||||
* ```typescript
|
* @Injectable()
|
||||||
* var injector = Injector.resolveAndCreate([
|
* class EnLocale extends Locale {
|
||||||
* {provide: Number, useFactory: () => { return 1+2; }},
|
* name: 'en';
|
||||||
* new Provider(String, { useFactory: (value) => { return "Value: " + value; },
|
* };
|
||||||
* deps: [Number] })
|
*
|
||||||
|
* @Injectable()
|
||||||
|
* class SkLocale extends Locale {
|
||||||
|
* name: 'sk';
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* const injector = Injector.resolveAndCreate([
|
||||||
|
* EnLocale,
|
||||||
|
* SkLocale
|
||||||
|
* { provide: Locale, useExisting: EnLocale, multi: true },
|
||||||
|
* { provide: Locale, useExisting: SkLocale, multi: true },
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injector.get(Number)).toEqual(3);
|
* const locales: Locale[] = injector.get(Locale);
|
||||||
* expect(injector.get(String)).toEqual('Value: 3');
|
* const localeNames: string[] = locals.map((l) => l.name);
|
||||||
|
* expect(localeNames).toEqual(['en', 'sk']);
|
||||||
* ```
|
* ```
|
||||||
|
*/
|
||||||
|
multi?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the {@link Injector} to return a value by invoking a `useFactory` function.
|
||||||
*
|
*
|
||||||
* Used in conjunction with dependencies.
|
* ### Example
|
||||||
|
* ```javascript
|
||||||
|
* const HASH = new OpaqueToken('hash');
|
||||||
|
*
|
||||||
|
* const injector = Injector.resolveAndCreate([
|
||||||
|
* {provide: Location, useValue: window.location},
|
||||||
|
* {provide: HASH, useFactory: (location: Location) => location.hash, deps: [Location]}
|
||||||
|
* ]);
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* // Assume location is: http://angular.io/#someLocation
|
||||||
|
* expect(injector.get(HASH)).toEqual('someLocation');
|
||||||
|
* ``
|
||||||
|
* @stable
|
||||||
|
*/
|
||||||
|
export interface FactoryProvider {
|
||||||
|
/**
|
||||||
|
* An injection token. (Typically an instance of `Type` or `OpaqueToken`, but can be `any`).
|
||||||
|
*/
|
||||||
|
provide: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function to invoke to create a value for this `token`. The function is invoked with
|
||||||
|
* resolved values of `token`s in the `deps` field.
|
||||||
*/
|
*/
|
||||||
useFactory: Function;
|
useFactory: Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies a set of dependencies
|
* A list of `token`s which need to be resolved by the injector. The list of values is than
|
||||||
* (as `token`s) which should be injected into the factory function.
|
* used as arguments to the `useFactory` function.
|
||||||
*
|
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/Scoxy0pJNqKGAPZY1VVC?p=preview))
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* var injector = Injector.resolveAndCreate([
|
|
||||||
* {provide: Number, useFactory: () => { return 1+2; }},
|
|
||||||
* new Provider(String, { useFactory: (value) => { return "Value: " + value; },
|
|
||||||
* deps: [Number] })
|
|
||||||
* ]);
|
|
||||||
*
|
|
||||||
* expect(injector.get(Number)).toEqual(3);
|
|
||||||
* expect(injector.get(String)).toEqual('Value: 3');
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* Used in conjunction with `useFactory`.
|
|
||||||
*/
|
*/
|
||||||
dependencies: Object[];
|
deps: any[];
|
||||||
|
|
||||||
/** @internal */
|
|
||||||
_multi: boolean;
|
|
||||||
|
|
||||||
constructor(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
|
|
||||||
useClass?: Type<any>,
|
|
||||||
useValue?: any,
|
|
||||||
useExisting?: any,
|
|
||||||
useFactory?: Function,
|
|
||||||
deps?: Object[],
|
|
||||||
multi?: boolean
|
|
||||||
}) {
|
|
||||||
this.token = token;
|
|
||||||
this.useClass = useClass;
|
|
||||||
this.useValue = useValue;
|
|
||||||
this.useExisting = useExisting;
|
|
||||||
this.useFactory = useFactory;
|
|
||||||
this.dependencies = deps;
|
|
||||||
this._multi = multi;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Provide a full working example after alpha38 is released.
|
|
||||||
/**
|
/**
|
||||||
* Creates multiple providers matching the same token (a multi-provider).
|
* If true, than injector returns an array of instances. This is useful to allow multiple
|
||||||
*
|
* providers spread across many files to provide configuration information to a common token.
|
||||||
* Multi-providers are used for creating pluggable service, where the system comes
|
|
||||||
* with some default providers, and the user can register additional providers.
|
|
||||||
* The combination of the default providers and the additional providers will be
|
|
||||||
* used to drive the behavior of the system.
|
|
||||||
*
|
*
|
||||||
* ### Example
|
* ### Example
|
||||||
|
* ```javascript
|
||||||
|
* class Locale {
|
||||||
|
* constructor(public name: string) {}
|
||||||
|
* };
|
||||||
|
* const PRIMARY = new OpequeToken('primary');
|
||||||
|
* const SECONDARY = new OpequeToken('secondary');
|
||||||
*
|
*
|
||||||
* ```typescript
|
* const injector = Injector.resolveAndCreate([
|
||||||
* var injector = Injector.resolveAndCreate([
|
* { provide: PRIMARY: useValue: 'en'},
|
||||||
* new Provider("Strings", { useValue: "String1", multi: true}),
|
* { provide: SECONDARY: useValue: 'sk'},
|
||||||
* new Provider("Strings", { useValue: "String2", multi: true})
|
* { provide: Locale, useFactory: (n) => new Locale(n), deps: [PRIMARY], multi: true},
|
||||||
|
* { provide: Locale, useFactory: (n) => new Locale(n), deps: [SECONDARY], multi: true},
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injector.get("Strings")).toEqual(["String1", "String2"]);
|
* const locales: Locale[] = injector.get(Locale);
|
||||||
* ```
|
* const localeNames: string[] = locals.map((l) => l.name);
|
||||||
*
|
* expect(localeNames).toEqual(['en', 'sk']);
|
||||||
* Multi-providers and regular providers cannot be mixed. The following
|
|
||||||
* will throw an exception:
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* var injector = Injector.resolveAndCreate([
|
|
||||||
* new Provider("Strings", { useValue: "String1", multi: true }),
|
|
||||||
* new Provider("Strings", { useValue: "String2"})
|
|
||||||
* ]);
|
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
get multi(): boolean { return normalizeBool(this._multi); }
|
multi?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link Provider} instead.
|
* Describes how the {@link Injector} should be configured.
|
||||||
*
|
*
|
||||||
* @deprecated
|
* See {@link TypeProvider}, {@link ValueProvider}, {@link ClassProvider}, {@link ExistingProvider},
|
||||||
*/
|
* {@link FactoryProvider}.
|
||||||
export class Binding extends Provider {
|
|
||||||
constructor(token: any, {toClass, toValue, toAlias, toFactory, deps, multi}: {
|
|
||||||
toClass?: Type<any>,
|
|
||||||
toValue?: any,
|
|
||||||
toAlias?: any,
|
|
||||||
toFactory: Function, deps?: Object[], multi?: boolean
|
|
||||||
}) {
|
|
||||||
super(token, {
|
|
||||||
useClass: toClass,
|
|
||||||
useValue: toValue,
|
|
||||||
useExisting: toAlias,
|
|
||||||
useFactory: toFactory,
|
|
||||||
deps: deps,
|
|
||||||
multi: multi
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
get toClass() { return this.useClass; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
get toAlias() { return this.useExisting; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
get toFactory() { return this.useFactory; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
get toValue() { return this.useValue; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link Provider}.
|
|
||||||
*
|
*
|
||||||
* To construct a {@link Provider}, bind a `token` to either a class, a value, a factory function,
|
* ```javascript
|
||||||
* or
|
* class Greeting {
|
||||||
* to an existing `token`.
|
* salutation = 'Hello';
|
||||||
* See {@link ProviderBuilder} for more details.
|
* }
|
||||||
*
|
*
|
||||||
* The `token` is most commonly a class or {@link OpaqueToken}.
|
* class FormalGreeting extends Greeting {
|
||||||
|
* salutation = 'Greetings';
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
* @deprecated
|
* abstract class Operation {
|
||||||
*/
|
* apply(a,b): any;
|
||||||
export function bind(token: any): ProviderBuilder {
|
* }
|
||||||
return new ProviderBuilder(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class for the {@link bind} function.
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
export class ProviderBuilder {
|
|
||||||
constructor(public token: any) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds a DI token to a class.
|
|
||||||
*
|
*
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/ZpBCSYqv6e2ud5KXLdxQ?p=preview))
|
* class AddOperation extends Operation {
|
||||||
|
* apply(a,b) { return a+b; }
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
* Because `toAlias` and `toClass` are often confused, the example contains
|
|
||||||
* both use cases for easy comparison.
|
|
||||||
*
|
*
|
||||||
* ```typescript
|
* const injector = Injector.resolveAndCreate([
|
||||||
* class Vehicle {}
|
* FormalGreeting,
|
||||||
*
|
* {provide: String, useValue: 'Hello World!'},
|
||||||
* class Car extends Vehicle {}
|
* {provide: Greeting, useExisting: FormalGreeting},
|
||||||
*
|
* {provide: Operation, useClass: AddOperation},
|
||||||
* var injectorClass = Injector.resolveAndCreate([
|
* {provide: Number, useFactory: (op) =>op.apply(1,2), deps: [Operation] }
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useClass: Car}
|
|
||||||
* ]);
|
|
||||||
* var injectorAlias = Injector.resolveAndCreate([
|
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useExisting: Car}
|
|
||||||
* ]);
|
* ]);
|
||||||
*
|
*
|
||||||
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
* expect(injector.get(FormalGreeting).name).toEqual('Greetings');
|
||||||
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
|
* expect(injector.get(String).name).toEqual('Hello World!');
|
||||||
*
|
* expect(injector.get(Greeting).name).toBe(injector.get(FormalGreeting));
|
||||||
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
* expect(injector.get(Number).toEqual(3);
|
||||||
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
|
|
||||||
* ```
|
* ```
|
||||||
|
* @stable
|
||||||
*/
|
*/
|
||||||
toClass(type: Type<any>): Provider {
|
export type Provider =
|
||||||
if (!isType(type)) {
|
TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[];
|
||||||
throw new BaseException(
|
|
||||||
`Trying to create a class provider but "${stringify(type)}" is not a class!`);
|
|
||||||
}
|
|
||||||
return new Provider(this.token, {useClass: type});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds a DI token to a value.
|
|
||||||
*
|
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/G024PFHmDL0cJFgfZK8O?p=preview))
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* var injector = Injector.resolveAndCreate([
|
|
||||||
* {provide: 'message', useValue: 'Hello'}
|
|
||||||
* ]);
|
|
||||||
*
|
|
||||||
* expect(injector.get('message')).toEqual('Hello');
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
toValue(value: any): Provider { return new Provider(this.token, {useValue: value}); }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds a DI token to an existing token.
|
|
||||||
*
|
|
||||||
* Angular will return the same instance as if the provided token was used. (This is
|
|
||||||
* in contrast to `useClass` where a separate instance of `useClass` will be returned.)
|
|
||||||
*
|
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/uBaoF2pN5cfc5AfZapNw?p=preview))
|
|
||||||
*
|
|
||||||
* Because `toAlias` and `toClass` are often confused, the example contains
|
|
||||||
* both use cases for easy comparison.
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* class Vehicle {}
|
|
||||||
*
|
|
||||||
* class Car extends Vehicle {}
|
|
||||||
*
|
|
||||||
* var injectorAlias = Injector.resolveAndCreate([
|
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useExisting: Car}
|
|
||||||
* ]);
|
|
||||||
* var injectorClass = Injector.resolveAndCreate([
|
|
||||||
* Car,
|
|
||||||
* {provide: Vehicle, useClass: Car})
|
|
||||||
* ]);
|
|
||||||
*
|
|
||||||
* expect(injectorAlias.get(Vehicle)).toBe(injectorAlias.get(Car));
|
|
||||||
* expect(injectorAlias.get(Vehicle) instanceof Car).toBe(true);
|
|
||||||
*
|
|
||||||
* expect(injectorClass.get(Vehicle)).not.toBe(injectorClass.get(Car));
|
|
||||||
* expect(injectorClass.get(Vehicle) instanceof Car).toBe(true);
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
toAlias(aliasToken: /*Type*/ any): Provider {
|
|
||||||
if (isBlank(aliasToken)) {
|
|
||||||
throw new BaseException(`Can not alias ${stringify(this.token)} to a blank value!`);
|
|
||||||
}
|
|
||||||
return new Provider(this.token, {useExisting: aliasToken});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binds a DI token to a function which computes the value.
|
|
||||||
*
|
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/OejNIfTT3zb1iBxaIYOb?p=preview))
|
|
||||||
*
|
|
||||||
* ```typescript
|
|
||||||
* var injector = Injector.resolveAndCreate([
|
|
||||||
* {provide: Number, useFactory: () => { return 1+2; }},
|
|
||||||
* {provide: String, useFactory: (v) => { return "Value: " + v; }, deps: [Number]}
|
|
||||||
* ]);
|
|
||||||
*
|
|
||||||
* expect(injector.get(Number)).toEqual(3);
|
|
||||||
* expect(injector.get(String)).toEqual('Value: 3');
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
toFactory(factory: Function, dependencies?: any[]): Provider {
|
|
||||||
if (!isFunction(factory)) {
|
|
||||||
throw new BaseException(
|
|
||||||
`Trying to create a factory provider but "${stringify(factory)}" is not a function!`);
|
|
||||||
}
|
|
||||||
return new Provider(this.token, {useFactory: factory, deps: dependencies});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link Provider}.
|
|
||||||
*
|
|
||||||
* See {@link Provider} for more details.
|
|
||||||
*
|
|
||||||
* <!-- TODO: improve the docs -->
|
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
export function provide(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
|
|
||||||
useClass?: Type<any>,
|
|
||||||
useValue?: any,
|
|
||||||
useExisting?: any,
|
|
||||||
useFactory?: Function,
|
|
||||||
deps?: Object[],
|
|
||||||
multi?: boolean
|
|
||||||
}): Provider {
|
|
||||||
return new Provider(token, {
|
|
||||||
useClass: useClass,
|
|
||||||
useValue: useValue,
|
|
||||||
useExisting: useExisting,
|
|
||||||
useFactory: useFactory,
|
|
||||||
deps: deps,
|
|
||||||
multi: multi
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
|
||||||
* found in the LICENSE file at https://angular.io/license
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {Provider} from './provider';
|
|
||||||
|
|
||||||
export function isProviderLiteral(obj: any): boolean {
|
|
||||||
return obj && typeof obj == 'object' && obj.provide;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createProvider(obj: any): Provider {
|
|
||||||
return new Provider(obj.provide, obj);
|
|
||||||
}
|
|
|
@ -10,8 +10,6 @@ import {ListWrapper} from '../facade/collection';
|
||||||
import {BaseException, WrappedException} from '../facade/exceptions';
|
import {BaseException, WrappedException} from '../facade/exceptions';
|
||||||
import {isBlank, stringify} from '../facade/lang';
|
import {isBlank, stringify} from '../facade/lang';
|
||||||
import {Type} from '../type';
|
import {Type} from '../type';
|
||||||
|
|
||||||
import {Provider} from './provider';
|
|
||||||
import {ReflectiveInjector} from './reflective_injector';
|
import {ReflectiveInjector} from './reflective_injector';
|
||||||
import {ReflectiveKey} from './reflective_key';
|
import {ReflectiveKey} from './reflective_key';
|
||||||
|
|
||||||
|
@ -273,8 +271,8 @@ export class OutOfBoundsError extends BaseException {
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* expect(() => Injector.resolveAndCreate([
|
* expect(() => Injector.resolveAndCreate([
|
||||||
* new Provider("Strings", {useValue: "string1", multi: true}),
|
* { provide: "Strings", useValue: "string1", multi: true},
|
||||||
* new Provider("Strings", {useValue: "string2", multi: false})
|
* { provide: "Strings", useValue: "string2", multi: false}
|
||||||
* ])).toThrowError();
|
* ])).toThrowError();
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -392,8 +392,7 @@ export abstract class ReflectiveInjector implements Injector {
|
||||||
*
|
*
|
||||||
* See {@link ReflectiveInjector#fromResolvedProviders} for more info.
|
* See {@link ReflectiveInjector#fromResolvedProviders} for more info.
|
||||||
*/
|
*/
|
||||||
static resolve(providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>):
|
static resolve(providers: Provider[]): ResolvedReflectiveProvider[] {
|
||||||
ResolvedReflectiveProvider[] {
|
|
||||||
return resolveReflectiveProviders(providers);
|
return resolveReflectiveProviders(providers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,9 +422,7 @@ export abstract class ReflectiveInjector implements Injector {
|
||||||
* because it needs to resolve the passed-in providers first.
|
* because it needs to resolve the passed-in providers first.
|
||||||
* See {@link Injector#resolve} and {@link Injector#fromResolvedProviders}.
|
* See {@link Injector#resolve} and {@link Injector#fromResolvedProviders}.
|
||||||
*/
|
*/
|
||||||
static resolveAndCreate(
|
static resolveAndCreate(providers: Provider[], parent: Injector = null): ReflectiveInjector {
|
||||||
providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>,
|
|
||||||
parent: Injector = null): ReflectiveInjector {
|
|
||||||
var ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
|
var ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
|
||||||
return ReflectiveInjector.fromResolvedProviders(ResolvedReflectiveProviders, parent);
|
return ReflectiveInjector.fromResolvedProviders(ResolvedReflectiveProviders, parent);
|
||||||
}
|
}
|
||||||
|
@ -516,10 +513,7 @@ export abstract class ReflectiveInjector implements Injector {
|
||||||
* because it needs to resolve the passed-in providers first.
|
* because it needs to resolve the passed-in providers first.
|
||||||
* See {@link Injector#resolve} and {@link Injector#createChildFromResolved}.
|
* See {@link Injector#resolve} and {@link Injector#createChildFromResolved}.
|
||||||
*/
|
*/
|
||||||
resolveAndCreateChild(providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>):
|
resolveAndCreateChild(providers: Provider[]): ReflectiveInjector { return unimplemented(); }
|
||||||
ReflectiveInjector {
|
|
||||||
return unimplemented();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a child injector from previously resolved providers.
|
* Creates a child injector from previously resolved providers.
|
||||||
|
@ -574,7 +568,7 @@ export abstract class ReflectiveInjector implements Injector {
|
||||||
* expect(car).not.toBe(injector.resolveAndInstantiate(Car));
|
* expect(car).not.toBe(injector.resolveAndInstantiate(Car));
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
resolveAndInstantiate(provider: Type<any>|Provider): any { return unimplemented(); }
|
resolveAndInstantiate(provider: Provider): any { return unimplemented(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates an object using a resolved provider in the context of the injector.
|
* Instantiates an object using a resolved provider in the context of the injector.
|
||||||
|
@ -644,7 +638,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
|
||||||
*/
|
*/
|
||||||
get internalStrategy(): any { return this._strategy; }
|
get internalStrategy(): any { return this._strategy; }
|
||||||
|
|
||||||
resolveAndCreateChild(providers: Array<Type<any>|Provider|any[]>): ReflectiveInjector {
|
resolveAndCreateChild(providers: Provider[]): ReflectiveInjector {
|
||||||
var ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
|
var ResolvedReflectiveProviders = ReflectiveInjector.resolve(providers);
|
||||||
return this.createChildFromResolved(ResolvedReflectiveProviders);
|
return this.createChildFromResolved(ResolvedReflectiveProviders);
|
||||||
}
|
}
|
||||||
|
@ -656,7 +650,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
|
||||||
return inj;
|
return inj;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveAndInstantiate(provider: Type<any>|Provider): any {
|
resolveAndInstantiate(provider: Provider): any {
|
||||||
return this.instantiateResolved(ReflectiveInjector.resolve([provider])[0]);
|
return this.instantiateResolved(ReflectiveInjector.resolve([provider])[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,13 @@ import {Type} from '../type';
|
||||||
|
|
||||||
import {resolveForwardRef} from './forward_ref';
|
import {resolveForwardRef} from './forward_ref';
|
||||||
import {DependencyMetadata, HostMetadata, InjectMetadata, OptionalMetadata, SelfMetadata, SkipSelfMetadata} from './metadata';
|
import {DependencyMetadata, HostMetadata, InjectMetadata, OptionalMetadata, SelfMetadata, SkipSelfMetadata} from './metadata';
|
||||||
import {Provider, ProviderBuilder, provide} from './provider';
|
import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './provider';
|
||||||
import {createProvider, isProviderLiteral} from './provider_util';
|
|
||||||
import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_exceptions';
|
import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_exceptions';
|
||||||
import {ReflectiveKey} from './reflective_key';
|
import {ReflectiveKey} from './reflective_key';
|
||||||
|
|
||||||
|
|
||||||
|
interface NormalizedProvider extends TypeProvider, ValueProvider, ClassProvider, ExistingProvider,
|
||||||
|
FactoryProvider {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `Dependency` is used by the framework to extend DI.
|
* `Dependency` is used by the framework to extend DI.
|
||||||
|
@ -46,7 +47,7 @@ const _EMPTY_LIST: any[] = [];
|
||||||
* ### Example ([live demo](http://plnkr.co/edit/RfEnhh8kUEI0G3qsnIeT?p%3Dpreview&p=preview))
|
* ### Example ([live demo](http://plnkr.co/edit/RfEnhh8kUEI0G3qsnIeT?p%3Dpreview&p=preview))
|
||||||
*
|
*
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* var resolvedProviders = Injector.resolve([new Provider('message', {useValue: 'Hello'})]);
|
* var resolvedProviders = Injector.resolve([{ provide: 'message', useValue: 'Hello' }]);
|
||||||
* var injector = Injector.fromResolvedProviders(resolvedProviders);
|
* var injector = Injector.fromResolvedProviders(resolvedProviders);
|
||||||
*
|
*
|
||||||
* expect(injector.get('message')).toEqual('Hello');
|
* expect(injector.get('message')).toEqual('Hello');
|
||||||
|
@ -87,7 +88,8 @@ export class ResolvedReflectiveProvider_ implements ResolvedReflectiveBinding {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An internal resolved representation of a factory function created by resolving {@link Provider}.
|
* An internal resolved representation of a factory function created by resolving {@link
|
||||||
|
* Provider}.
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export class ResolvedReflectiveFactory {
|
export class ResolvedReflectiveFactory {
|
||||||
|
@ -107,7 +109,7 @@ export class ResolvedReflectiveFactory {
|
||||||
/**
|
/**
|
||||||
* Resolve a single provider.
|
* Resolve a single provider.
|
||||||
*/
|
*/
|
||||||
export function resolveReflectiveFactory(provider: Provider): ResolvedReflectiveFactory {
|
function resolveReflectiveFactory(provider: NormalizedProvider): ResolvedReflectiveFactory {
|
||||||
var factoryFn: Function;
|
var factoryFn: Function;
|
||||||
var resolvedDeps: ReflectiveDependency[];
|
var resolvedDeps: ReflectiveDependency[];
|
||||||
if (isPresent(provider.useClass)) {
|
if (isPresent(provider.useClass)) {
|
||||||
|
@ -119,7 +121,7 @@ export function resolveReflectiveFactory(provider: Provider): ResolvedReflective
|
||||||
resolvedDeps = [ReflectiveDependency.fromKey(ReflectiveKey.get(provider.useExisting))];
|
resolvedDeps = [ReflectiveDependency.fromKey(ReflectiveKey.get(provider.useExisting))];
|
||||||
} else if (isPresent(provider.useFactory)) {
|
} else if (isPresent(provider.useFactory)) {
|
||||||
factoryFn = provider.useFactory;
|
factoryFn = provider.useFactory;
|
||||||
resolvedDeps = constructDependencies(provider.useFactory, provider.dependencies);
|
resolvedDeps = constructDependencies(provider.useFactory, provider.deps);
|
||||||
} else {
|
} else {
|
||||||
factoryFn = () => provider.useValue;
|
factoryFn = () => provider.useValue;
|
||||||
resolvedDeps = _EMPTY_LIST;
|
resolvedDeps = _EMPTY_LIST;
|
||||||
|
@ -133,16 +135,15 @@ export function resolveReflectiveFactory(provider: Provider): ResolvedReflective
|
||||||
* {@link Injector} internally only uses {@link ResolvedProvider}, {@link Provider} contains
|
* {@link Injector} internally only uses {@link ResolvedProvider}, {@link Provider} contains
|
||||||
* convenience provider syntax.
|
* convenience provider syntax.
|
||||||
*/
|
*/
|
||||||
export function resolveReflectiveProvider(provider: Provider): ResolvedReflectiveProvider {
|
function resolveReflectiveProvider(provider: NormalizedProvider): ResolvedReflectiveProvider {
|
||||||
return new ResolvedReflectiveProvider_(
|
return new ResolvedReflectiveProvider_(
|
||||||
ReflectiveKey.get(provider.token), [resolveReflectiveFactory(provider)], provider.multi);
|
ReflectiveKey.get(provider.provide), [resolveReflectiveFactory(provider)], provider.multi);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve a list of Providers.
|
* Resolve a list of Providers.
|
||||||
*/
|
*/
|
||||||
export function resolveReflectiveProviders(
|
export function resolveReflectiveProviders(providers: Provider[]): ResolvedReflectiveProvider[] {
|
||||||
providers: Array<Type<any>|Provider|{[k: string]: any}|any[]>): ResolvedReflectiveProvider[] {
|
|
||||||
var normalized = _normalizeProviders(providers, []);
|
var normalized = _normalizeProviders(providers, []);
|
||||||
var resolved = normalized.map(resolveReflectiveProvider);
|
var resolved = normalized.map(resolveReflectiveProvider);
|
||||||
return MapWrapper.values(
|
return MapWrapper.values(
|
||||||
|
@ -186,25 +187,17 @@ export function mergeResolvedReflectiveProviders(
|
||||||
return normalizedProvidersMap;
|
return normalizedProvidersMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _normalizeProviders(
|
function _normalizeProviders(providers: Provider[], res: Provider[]): Provider[] {
|
||||||
providers: Array<Type<any>|Provider|{[k: string]: any}|ProviderBuilder|any[]>,
|
|
||||||
res: Provider[]): Provider[] {
|
|
||||||
providers.forEach(b => {
|
providers.forEach(b => {
|
||||||
if (b instanceof Type) {
|
if (b instanceof Type) {
|
||||||
res.push(provide(b, {useClass: b}));
|
res.push({provide: b, useClass: b});
|
||||||
|
|
||||||
} else if (b instanceof Provider) {
|
} else if (b && typeof b == 'object' && b.hasOwnProperty('provide')) {
|
||||||
res.push(b);
|
res.push(b as NormalizedProvider);
|
||||||
|
|
||||||
} else if (isProviderLiteral(b)) {
|
|
||||||
res.push(createProvider(b));
|
|
||||||
|
|
||||||
} else if (b instanceof Array) {
|
} else if (b instanceof Array) {
|
||||||
_normalizeProviders(b, res);
|
_normalizeProviders(b, res);
|
||||||
|
|
||||||
} else if (b instanceof ProviderBuilder) {
|
|
||||||
throw new InvalidProviderError(b.token);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidProviderError(b);
|
throw new InvalidProviderError(b);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import {NgModuleFactory} from './ng_module_factory';
|
import {NgModuleFactory} from './ng_module_factory';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to load ng moduled factories.
|
* Used to load ng module factories.
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export abstract class NgModuleFactoryLoader {
|
export abstract class NgModuleFactoryLoader {
|
||||||
|
|
|
@ -12,13 +12,12 @@ import {Provider} from './di';
|
||||||
import {Reflector, reflector} from './reflection/reflection';
|
import {Reflector, reflector} from './reflection/reflection';
|
||||||
import {ReflectorReader} from './reflection/reflector_reader';
|
import {ReflectorReader} from './reflection/reflector_reader';
|
||||||
import {TestabilityRegistry} from './testability/testability';
|
import {TestabilityRegistry} from './testability/testability';
|
||||||
import {Type} from './type';
|
|
||||||
|
|
||||||
function _reflector(): Reflector {
|
function _reflector(): Reflector {
|
||||||
return reflector;
|
return reflector;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _CORE_PLATFORM_PROVIDERS: Array<any|Type<any>|Provider|any[]> = [
|
const _CORE_PLATFORM_PROVIDERS: Provider[] = [
|
||||||
PlatformRef_, {provide: PlatformRef, useExisting: PlatformRef_},
|
PlatformRef_, {provide: PlatformRef, useExisting: PlatformRef_},
|
||||||
{provide: Reflector, useFactory: _reflector, deps: []},
|
{provide: Reflector, useFactory: _reflector, deps: []},
|
||||||
{provide: ReflectorReader, useExisting: Reflector}, TestabilityRegistry, Console
|
{provide: ReflectorReader, useExisting: Reflector}, TestabilityRegistry, Console
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injector, ReflectiveInjector, provide} from '@angular/core';
|
import {Injector, ReflectiveInjector} from '@angular/core';
|
||||||
import {IterableDiffers} from '@angular/core/src/change_detection/differs/iterable_differs';
|
import {IterableDiffers} from '@angular/core/src/change_detection/differs/iterable_differs';
|
||||||
import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal';
|
import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* Copyright Google Inc. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
|
||||||
* found in the LICENSE file at https://angular.io/license
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {bind, provide} from '@angular/core';
|
|
||||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
|
||||||
|
|
||||||
export function main() {
|
|
||||||
describe('provider', () => {
|
|
||||||
|
|
||||||
describe('type errors', () => {
|
|
||||||
|
|
||||||
it('should throw when trying to create a class provider and not passing a class', () => {
|
|
||||||
expect(() => {
|
|
||||||
bind('foo').toClass(<any>0);
|
|
||||||
}).toThrowError('Trying to create a class provider but "0" is not a class!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw when trying to create a factory provider and not passing a function', () => {
|
|
||||||
expect(() => {
|
|
||||||
bind('foo').toFactory(<any>0);
|
|
||||||
}).toThrowError('Trying to create a factory provider but "0" is not a function!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {NgFor} from '@angular/common';
|
import {NgFor} from '@angular/common';
|
||||||
import {Component, ContentChildren, Directive, Inject, QueryList, asNativeElements, bind, forwardRef, provide, resolveForwardRef} from '@angular/core';
|
import {Component, ContentChildren, Directive, Inject, QueryList, asNativeElements, forwardRef} from '@angular/core';
|
||||||
import {TestComponentBuilder} from '@angular/core/testing';
|
import {TestComponentBuilder} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||||
|
|
|
@ -6,10 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {LowerCasePipe, NgIf} from '@angular/common';
|
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, ComponentResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, ReflectiveInjector, SelfMetadata, Type, forwardRef} from '@angular/core';
|
||||||
import {CompilerConfig, NgModuleResolver} from '@angular/compiler';
|
|
||||||
import {MockNgModuleResolver} from '@angular/compiler/testing';
|
|
||||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, ComponentResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, ReflectiveInjector, SelfMetadata, Type, forwardRef, provide} from '@angular/core';
|
|
||||||
import {Console} from '@angular/core/src/console';
|
import {Console} from '@angular/core/src/console';
|
||||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||||
|
@ -720,7 +717,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when no type and not @Inject (factory case)', () => {
|
it('should throw when no type and not @Inject (factory case)', () => {
|
||||||
expect(() => createInjector([provide('someToken', {useFactory: factoryFn})]))
|
expect(() => createInjector([{provide: 'someToken', useFactory: factoryFn}]))
|
||||||
.toThrowError('Can\'t resolve all parameters for factoryFn: (?).');
|
.toThrowError('Can\'t resolve all parameters for factoryFn: (?).');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -734,7 +731,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide to a value', () => {
|
it('should provide to a value', () => {
|
||||||
var injector = createInjector([provide(Engine, {useValue: 'fake engine'})]);
|
var injector = createInjector([{provide: Engine, useValue: 'fake engine'}]);
|
||||||
|
|
||||||
var engine = injector.get(Engine);
|
var engine = injector.get(Engine);
|
||||||
expect(engine).toEqual('fake engine');
|
expect(engine).toEqual('fake engine');
|
||||||
|
@ -744,7 +741,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
function sportsCarFactory(e: Engine) { return new SportsCar(e); }
|
function sportsCarFactory(e: Engine) { return new SportsCar(e); }
|
||||||
|
|
||||||
var injector =
|
var injector =
|
||||||
createInjector([Engine, provide(Car, {useFactory: sportsCarFactory, deps: [Engine]})]);
|
createInjector([Engine, {provide: Car, useFactory: sportsCarFactory, deps: [Engine]}]);
|
||||||
|
|
||||||
var car = injector.get(Car);
|
var car = injector.get(Car);
|
||||||
expect(car).toBeAnInstanceOf(SportsCar);
|
expect(car).toBeAnInstanceOf(SportsCar);
|
||||||
|
@ -752,15 +749,15 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should supporting provider to null', () => {
|
it('should supporting provider to null', () => {
|
||||||
var injector = createInjector([provide(Engine, {useValue: null})]);
|
var injector = createInjector([{provide: Engine, useValue: null}]);
|
||||||
var engine = injector.get(Engine);
|
var engine = injector.get(Engine);
|
||||||
expect(engine).toBeNull();
|
expect(engine).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should provide to an alias', () => {
|
it('should provide to an alias', () => {
|
||||||
var injector = createInjector([
|
var injector = createInjector([
|
||||||
Engine, provide(SportsCar, {useClass: SportsCar}),
|
Engine, {provide: SportsCar, useClass: SportsCar},
|
||||||
provide(Car, {useExisting: SportsCar})
|
{provide: Car, useExisting: SportsCar}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var car = injector.get(Car);
|
var car = injector.get(Car);
|
||||||
|
@ -771,8 +768,8 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
|
|
||||||
it('should support multiProviders', () => {
|
it('should support multiProviders', () => {
|
||||||
var injector = createInjector([
|
var injector = createInjector([
|
||||||
Engine, provide(Car, {useClass: SportsCar, multi: true}),
|
Engine, {provide: Car, useClass: SportsCar, multi: true},
|
||||||
provide(Car, {useClass: CarWithOptionalEngine, multi: true})
|
{provide: Car, useClass: CarWithOptionalEngine, multi: true}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var cars = injector.get(Car);
|
var cars = injector.get(Car);
|
||||||
|
@ -783,7 +780,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
|
|
||||||
it('should support multiProviders that are created using useExisting', () => {
|
it('should support multiProviders that are created using useExisting', () => {
|
||||||
var injector = createInjector(
|
var injector = createInjector(
|
||||||
[Engine, SportsCar, provide(Car, {useExisting: SportsCar, multi: true})]);
|
[Engine, SportsCar, {provide: Car, useExisting: SportsCar, multi: true}]);
|
||||||
|
|
||||||
var cars = injector.get(Car);
|
var cars = injector.get(Car);
|
||||||
expect(cars.length).toEqual(1);
|
expect(cars.length).toEqual(1);
|
||||||
|
@ -791,22 +788,22 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when the aliased provider does not exist', () => {
|
it('should throw when the aliased provider does not exist', () => {
|
||||||
var injector = createInjector([provide('car', {useExisting: SportsCar})]);
|
var injector = createInjector([{provide: 'car', useExisting: SportsCar}]);
|
||||||
var e = `No provider for ${stringify(SportsCar)}!`;
|
var e = `No provider for ${stringify(SportsCar)}!`;
|
||||||
expect(() => injector.get('car')).toThrowError(e);
|
expect(() => injector.get('car')).toThrowError(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle forwardRef in useExisting', () => {
|
it('should handle forwardRef in useExisting', () => {
|
||||||
var injector = createInjector([
|
var injector = createInjector([
|
||||||
provide('originalEngine', {useClass: forwardRef(() => Engine)}),
|
{provide: 'originalEngine', useClass: forwardRef(() => Engine)},
|
||||||
provide('aliasedEngine', {useExisting: <any>forwardRef(() => 'originalEngine')})
|
{provide: 'aliasedEngine', useExisting: <any>forwardRef(() => 'originalEngine')}
|
||||||
]);
|
]);
|
||||||
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
|
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support overriding factory dependencies', () => {
|
it('should support overriding factory dependencies', () => {
|
||||||
var injector = createInjector(
|
var injector = createInjector(
|
||||||
[Engine, provide(Car, {useFactory: (e: Engine) => new SportsCar(e), deps: [Engine]})]);
|
[Engine, {provide: Car, useFactory: (e: Engine) => new SportsCar(e), deps: [Engine]}]);
|
||||||
|
|
||||||
var car = injector.get(Car);
|
var car = injector.get(Car);
|
||||||
expect(car).toBeAnInstanceOf(SportsCar);
|
expect(car).toBeAnInstanceOf(SportsCar);
|
||||||
|
@ -829,13 +826,13 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
|
|
||||||
it('should use the last provider when there are multiple providers for same token', () => {
|
it('should use the last provider when there are multiple providers for same token', () => {
|
||||||
var injector = createInjector(
|
var injector = createInjector(
|
||||||
[provide(Engine, {useClass: Engine}), provide(Engine, {useClass: TurboEngine})]);
|
[{provide: Engine, useClass: Engine}, {provide: Engine, useClass: TurboEngine}]);
|
||||||
|
|
||||||
expect(injector.get(Engine)).toBeAnInstanceOf(TurboEngine);
|
expect(injector.get(Engine)).toBeAnInstanceOf(TurboEngine);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use non-type tokens', () => {
|
it('should use non-type tokens', () => {
|
||||||
var injector = createInjector([provide('token', {useValue: 'value'})]);
|
var injector = createInjector([{provide: 'token', useValue: 'value'}]);
|
||||||
|
|
||||||
expect(injector.get('token')).toEqual('value');
|
expect(injector.get('token')).toEqual('value');
|
||||||
});
|
});
|
||||||
|
@ -859,12 +856,12 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when trying to instantiate a cyclic dependency', () => {
|
it('should throw when trying to instantiate a cyclic dependency', () => {
|
||||||
expect(() => createInjector([Car, provide(Engine, {useClass: CyclicEngine})]))
|
expect(() => createInjector([Car, {provide: Engine, useClass: CyclicEngine}]))
|
||||||
.toThrowError(/Cannot instantiate cyclic dependency! Car/g);
|
.toThrowError(/Cannot instantiate cyclic dependency! Car/g);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support null values', () => {
|
it('should support null values', () => {
|
||||||
var injector = createInjector([provide('null', {useValue: null})]);
|
var injector = createInjector([{provide: 'null', useValue: null}]);
|
||||||
expect(injector.get('null')).toBe(null);
|
expect(injector.get('null')).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -883,7 +880,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
it('should not use the child providers when resolving the dependencies of a parent provider',
|
it('should not use the child providers when resolving the dependencies of a parent provider',
|
||||||
() => {
|
() => {
|
||||||
var parent = createInjector([Car, Engine]);
|
var parent = createInjector([Car, Engine]);
|
||||||
var child = createInjector([provide(Engine, {useClass: TurboEngine})], parent);
|
var child = createInjector([{provide: Engine, useClass: TurboEngine}], parent);
|
||||||
|
|
||||||
var carFromChild = child.get(Car);
|
var carFromChild = child.get(Car);
|
||||||
expect(carFromChild.engine).toBeAnInstanceOf(Engine);
|
expect(carFromChild.engine).toBeAnInstanceOf(Engine);
|
||||||
|
@ -891,7 +888,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
|
|
||||||
it('should create new instance in a child injector', () => {
|
it('should create new instance in a child injector', () => {
|
||||||
var parent = createInjector([Engine]);
|
var parent = createInjector([Engine]);
|
||||||
var child = createInjector([provide(Engine, {useClass: TurboEngine})], parent);
|
var child = createInjector([{provide: Engine, useClass: TurboEngine}], parent);
|
||||||
|
|
||||||
var engineFromParent = parent.get(Engine);
|
var engineFromParent = parent.get(Engine);
|
||||||
var engineFromChild = child.get(Engine);
|
var engineFromChild = child.get(Engine);
|
||||||
|
@ -906,20 +903,22 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
describe('@Self()', () => {
|
describe('@Self()', () => {
|
||||||
it('should return a dependency from self', () => {
|
it('should return a dependency from self', () => {
|
||||||
var inj = createInjector([
|
var inj = createInjector([
|
||||||
Engine,
|
Engine, {
|
||||||
provide(
|
provide: Car,
|
||||||
Car,
|
useFactory: (e: Engine) => new Car(e),
|
||||||
{useFactory: (e: Engine) => new Car(e), deps: [[Engine, new SelfMetadata()]]})
|
deps: [[Engine, new SelfMetadata()]]
|
||||||
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(inj.get(Car)).toBeAnInstanceOf(Car);
|
expect(inj.get(Car)).toBeAnInstanceOf(Car);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw when not requested provider on self', () => {
|
it('should throw when not requested provider on self', () => {
|
||||||
expect(() => createInjector([provide(Car, {
|
expect(() => createInjector([{
|
||||||
|
provide: Car,
|
||||||
useFactory: (e: Engine) => new Car(e),
|
useFactory: (e: Engine) => new Car(e),
|
||||||
deps: [[Engine, new SelfMetadata()]]
|
deps: [[Engine, new SelfMetadata()]]
|
||||||
})]))
|
}]))
|
||||||
.toThrowError(/No provider for Engine/g);
|
.toThrowError(/No provider for Engine/g);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -929,8 +928,8 @@ function declareTests({useJit}: {useJit: boolean}) {
|
||||||
var parent = createInjector([Engine]);
|
var parent = createInjector([Engine]);
|
||||||
var child = createInjector(
|
var child = createInjector(
|
||||||
[
|
[
|
||||||
provide(Engine, {useClass: TurboEngine}),
|
{provide: Engine, useClass: TurboEngine},
|
||||||
provide(Car, {useFactory: (e: Engine) => new Car(e), deps: [Engine]})
|
{provide: Car, useFactory: (e: Engine) => new Car(e), deps: [Engine]}
|
||||||
],
|
],
|
||||||
parent);
|
parent);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {NgFor, NgIf} from '@angular/common';
|
import {NgFor, NgIf} from '@angular/common';
|
||||||
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, InjectMetadata, Input, Optional, Pipe, PipeTransform, Self, SkipSelfMetadata, TemplateRef, Type, ViewContainerRef, ViewMetadata, forwardRef, provide} from '@angular/core';
|
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, InjectMetadata, Input, Optional, Pipe, PipeTransform, Self, SkipSelfMetadata, TemplateRef, Type, ViewContainerRef, ViewMetadata, forwardRef} from '@angular/core';
|
||||||
import {ComponentFixture, TestComponentBuilder, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
import {ComponentFixture, TestComponentBuilder, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||||
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {CompilerOptions, ComponentFactory, ComponentMetadataType, ComponentStillLoadingError, DirectiveMetadataType, Injector, ModuleWithComponentFactories, NgModule, NgModuleFactory, NgModuleMetadataType, NgModuleRef, NgZone, OpaqueToken, PipeMetadataType, PlatformRef, Provider, ReflectiveInjector, SchemaMetadata, assertPlatform, createPlatform, getPlatform} from '../index';
|
import {CompilerOptions, ComponentMetadataType, ComponentStillLoadingError, DirectiveMetadataType, Injector, ModuleWithComponentFactories, NgModule, NgModuleFactory, NgModuleMetadataType, NgModuleRef, NgZone, OpaqueToken, PipeMetadataType, PlatformRef, Provider, SchemaMetadata} from '../index';
|
||||||
import {ListWrapper} from '../src/facade/collection';
|
import {ListWrapper} from '../src/facade/collection';
|
||||||
import {BaseException} from '../src/facade/exceptions';
|
import {BaseException} from '../src/facade/exceptions';
|
||||||
import {FunctionWrapper, isPresent, stringify} from '../src/facade/lang';
|
import {FunctionWrapper, stringify} from '../src/facade/lang';
|
||||||
import {Type} from '../src/type';
|
import {Type} from '../src/type';
|
||||||
import {AsyncTestCompleter} from './async_test_completer';
|
import {AsyncTestCompleter} from './async_test_completer';
|
||||||
import {ComponentFixture} from './component_fixture';
|
import {ComponentFixture} from './component_fixture';
|
||||||
|
@ -147,7 +147,7 @@ export class TestBed implements Injector {
|
||||||
private _directiveOverrides: [Type<any>, MetadataOverride<DirectiveMetadataType>][] = [];
|
private _directiveOverrides: [Type<any>, MetadataOverride<DirectiveMetadataType>][] = [];
|
||||||
private _pipeOverrides: [Type<any>, MetadataOverride<PipeMetadataType>][] = [];
|
private _pipeOverrides: [Type<any>, MetadataOverride<PipeMetadataType>][] = [];
|
||||||
|
|
||||||
private _providers: Array<Type<any>|Provider|any[]|any> = [];
|
private _providers: Provider[] = [];
|
||||||
private _declarations: Array<Type<any>|any[]|any> = [];
|
private _declarations: Array<Type<any>|any[]|any> = [];
|
||||||
private _imports: Array<Type<any>|any[]|any> = [];
|
private _imports: Array<Type<any>|any[]|any> = [];
|
||||||
private _schemas: Array<SchemaMetadata|any[]> = [];
|
private _schemas: Array<SchemaMetadata|any[]> = [];
|
||||||
|
|
|
@ -12,10 +12,8 @@
|
||||||
* allows tests to be asynchronous by either returning a promise or using a 'done' parameter.
|
* allows tests to be asynchronous by either returning a promise or using a 'done' parameter.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {SchemaMetadata} from '../index';
|
|
||||||
|
|
||||||
import {resetFakeAsyncZone} from './fake_async';
|
import {resetFakeAsyncZone} from './fake_async';
|
||||||
import {TestBed, TestModuleMetadata, getTestBed} from './test_bed';
|
import {TestBed} from './test_bed';
|
||||||
|
|
||||||
declare var global: any;
|
declare var global: any;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {provide} from '../index';
|
|
||||||
import {StringMapWrapper} from '../src/facade/collection';
|
import {StringMapWrapper} from '../src/facade/collection';
|
||||||
import {Math, global, isFunction, isPromise} from '../src/facade/lang';
|
import {Math, global, isFunction, isPromise} from '../src/facade/lang';
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ import {WORKER_RENDER_PLATFORM, WORKER_RENDER_APPLICATION, WORKER_SCRIPT} from "
|
||||||
import {platform} from "angular2/core";
|
import {platform} from "angular2/core";
|
||||||
|
|
||||||
platform([WORKER_RENDER_PLATFORM])
|
platform([WORKER_RENDER_PLATFORM])
|
||||||
.application([WORKER_RENDER_APPLICATION, new Provider(WORKER_SCRIPT, {useValue: "loader.js"});
|
.application([WORKER_RENDER_APPLICATION, {provide: WORKER_SCRIPT, useValue: "loader.js"};
|
||||||
```
|
```
|
||||||
```JavaScript
|
```JavaScript
|
||||||
// loader.js
|
// loader.js
|
||||||
|
@ -125,7 +125,7 @@ class HelloWorld {
|
||||||
|
|
||||||
main(List<String> args, SendPort replyTo) {
|
main(List<String> args, SendPort replyTo) {
|
||||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||||
platform([WORKER_APP_PLATFORM, new Provider(RENDER_SEND_PORT, useValue: replyTo)])
|
platform([WORKER_APP_PLATFORM, {provide: RENDER_SEND_PORT, useValue: replyTo}])
|
||||||
.application([WORKER_APP_APPLICATION])
|
.application([WORKER_APP_APPLICATION])
|
||||||
.bootstrap(RootComponent);
|
.bootstrap(RootComponent);
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ import {WORKER_RENDER_PLATFORM, WORKER_RENDER_APPLICATION, WORKER_SCRIPT, Messag
|
||||||
import {platform} from "angular2/core";
|
import {platform} from "angular2/core";
|
||||||
|
|
||||||
let appRef = platform([WORKER_RENDER_PLATFORM])
|
let appRef = platform([WORKER_RENDER_PLATFORM])
|
||||||
.application([WORKER_RENDER_APPLICATION, new Provider(WORKER_SCRIPT, {useValue: "loader.js"});
|
.application([WORKER_RENDER_APPLICATION, {provide: WORKER_SCRIPT, useValue: "loader.js"};
|
||||||
let bus = appRef.injector.get(MessageBus);
|
let bus = appRef.injector.get(MessageBus);
|
||||||
bus.initChannel("My Custom Channel");
|
bus.initChannel("My Custom Channel");
|
||||||
```
|
```
|
||||||
|
@ -243,7 +243,7 @@ import {WORKER_RENDER_PLATFORM, WORKER_RENDER_APPLICATION, WORKER_SCRIPT, Messag
|
||||||
import {platform} from "angular2/core";
|
import {platform} from "angular2/core";
|
||||||
|
|
||||||
let appRef = platform([WORKER_RENDER_PLATFORM])
|
let appRef = platform([WORKER_RENDER_PLATFORM])
|
||||||
.application([WORKER_RENDER_APPLICATION, new Provider(WORKER_SCRIPT, {useValue: "loader.js"});
|
.application([WORKER_RENDER_APPLICATION, {provide: WORKER_SCRIPT, useValue: "loader.js"};
|
||||||
let bus = appRef.injector.get(MessageBus);
|
let bus = appRef.injector.get(MessageBus);
|
||||||
bus.initChannel("My Custom Channel");
|
bus.initChannel("My Custom Channel");
|
||||||
bus.to("My Custom Channel").emit("Hello from the UI");
|
bus.to("My Custom Channel").emit("Hello from the UI");
|
||||||
|
@ -335,7 +335,7 @@ during bootstrap like so:
|
||||||
In TypeScript:
|
In TypeScript:
|
||||||
```TypeScript
|
```TypeScript
|
||||||
// index.ts, running on the UI side
|
// index.ts, running on the UI side
|
||||||
import {platform, Provider, APP_INITIALIZER, Injector} from 'angular2/core';
|
import {platform, APP_INITIALIZER, Injector} from 'angular2/core';
|
||||||
import {
|
import {
|
||||||
WORKER_RENDER_PLATFORM,
|
WORKER_RENDER_PLATFORM,
|
||||||
WORKER_RENDER_APPLICATION_COMMON,
|
WORKER_RENDER_APPLICATION_COMMON,
|
||||||
|
@ -345,18 +345,18 @@ import {
|
||||||
|
|
||||||
var bus = new MyAwesomeMessageBus();
|
var bus = new MyAwesomeMessageBus();
|
||||||
platform([WORKER_RENDER_PLATFORM])
|
platform([WORKER_RENDER_PLATFORM])
|
||||||
.application([WORKER_RENDER_APPLICATION_COMMON, new Provider(MessageBus, {useValue: bus}),
|
.application([WORKER_RENDER_APPLICATION_COMMON, {provide: MessageBus, useValue: bus},
|
||||||
new Provider(APP_INITIALIZER, {
|
{ provide: APP_INITIALIZER,
|
||||||
useFactory: (injector) => () => initializeGenericWorkerRenderer(injector),
|
useFactory: (injector) => () => initializeGenericWorkerRenderer(injector),
|
||||||
deps: [Injector],
|
deps: [Injector],
|
||||||
multi: true
|
multi: true
|
||||||
})
|
}
|
||||||
]);
|
]);
|
||||||
```
|
```
|
||||||
```TypeScript
|
```TypeScript
|
||||||
// background_index.ts, running on the application side
|
// background_index.ts, running on the application side
|
||||||
import {WORKER_APP_PLATFORM, genericWorkerAppProviders} from "angular2/platform/worker_app";
|
import {WORKER_APP_PLATFORM, genericWorkerAppProviders} from "angular2/platform/worker_app";
|
||||||
import {NgZone, platform, Provider} from "angular/core";
|
import {NgZone, platform} from "angular/core";
|
||||||
import {MyApp} from './app';
|
import {MyApp} from './app';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -365,8 +365,8 @@ import {MyApp} from './app';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
platform([WORKER_APP_PLATFORM_PROVIDERS])
|
platform([WORKER_APP_PLATFORM_PROVIDERS])
|
||||||
.application([WORKER_APP_APPLICATION_COMMON, new Provider(MessageBus, {useValue: bus}),
|
.application([WORKER_APP_APPLICATION_COMMON, {provide: MessageBus, useValue: bus},
|
||||||
new Provider(APP_INITIALIZER, {useFactory: (zone, bus) => () => initAppThread(zone, bus), multi: true, deps: [NgZone, MessageBus]})])
|
{provide: APP_INITIALIZER, useFactory: (zone, bus) => () => initAppThread(zone, bus), multi: true, deps: [NgZone, MessageBus]}])
|
||||||
.bootstrap(MyApp);
|
.bootstrap(MyApp);
|
||||||
|
|
||||||
function initAppThread(zone: NgZone, bus: MyAwesomeMessageBus): void{
|
function initAppThread(zone: NgZone, bus: MyAwesomeMessageBus): void{
|
||||||
|
@ -406,7 +406,7 @@ import {WORKER_RENDER_PLATFORM, WORKER_RENDER_APPLICATION, WORKER_SCRIPT, Servic
|
||||||
import {platform} from "angular2/core";
|
import {platform} from "angular2/core";
|
||||||
|
|
||||||
let appRef = platform([WORKER_RENDER_PLATFORM])
|
let appRef = platform([WORKER_RENDER_PLATFORM])
|
||||||
.application([WORKER_RENDER_APPLICATION, new Provider(WORKER_SCRIPT, {useValue: "loader.js"});
|
.application([WORKER_RENDER_APPLICATION, {provide: WORKER_SCRIPT, useValue: "loader.js"};
|
||||||
let injector = instance.injector;
|
let injector = instance.injector;
|
||||||
var broker = injector.get(ServiceMessageBrokerFactory).createMessageBroker("My Broker Channel");
|
var broker = injector.get(ServiceMessageBrokerFactory).createMessageBroker("My Broker Channel");
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {UrlResolver} from '@angular/compiler';
|
import {UrlResolver} from '@angular/compiler';
|
||||||
import {provide} from '@angular/core';
|
|
||||||
import {bootstrap} from '@angular/platform-browser-dynamic';
|
import {bootstrap} from '@angular/platform-browser-dynamic';
|
||||||
|
|
||||||
var MyApp: any;
|
var MyApp: any;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {XHR, analyzeAppProvidersForDeprecatedConfiguration, platformCoreDynamic} from '@angular/compiler';
|
import {XHR, analyzeAppProvidersForDeprecatedConfiguration, platformCoreDynamic} from '@angular/compiler';
|
||||||
import {ApplicationRef, COMPILER_OPTIONS, CUSTOM_ELEMENTS_SCHEMA, CompilerFactory, CompilerOptions, ComponentRef, NgModule, PlatformRef, Type, createPlatformFactory} from '@angular/core';
|
import {ApplicationRef, COMPILER_OPTIONS, CUSTOM_ELEMENTS_SCHEMA, CompilerFactory, CompilerOptions, ComponentRef, NgModule, PlatformRef, Provider, Type, createPlatformFactory} from '@angular/core';
|
||||||
import {BrowserModule, WORKER_SCRIPT, WorkerAppModule, platformWorkerUi} from '@angular/platform-browser';
|
import {BrowserModule, WORKER_SCRIPT, WorkerAppModule, platformWorkerUi} from '@angular/platform-browser';
|
||||||
|
|
||||||
import {Console} from './core_private';
|
import {Console} from './core_private';
|
||||||
|
@ -15,11 +15,12 @@ import {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './src/platform_provid
|
||||||
import {CachedXHR} from './src/xhr/xhr_cache';
|
import {CachedXHR} from './src/xhr/xhr_cache';
|
||||||
import {XHRImpl} from './src/xhr/xhr_impl';
|
import {XHRImpl} from './src/xhr/xhr_impl';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export const CACHED_TEMPLATE_PROVIDER: Array<any /*Type | Provider | any[]*/> =
|
export const CACHED_TEMPLATE_PROVIDER: Provider[] = [{provide: XHR, useClass: CachedXHR}];
|
||||||
[{provide: XHR, useClass: CachedXHR}];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @experimental API related to bootstrapping are still under review.
|
* @experimental API related to bootstrapping are still under review.
|
||||||
|
@ -107,8 +108,7 @@ export const platformBrowserDynamic = createPlatformFactory(
|
||||||
*/
|
*/
|
||||||
// Note: We are using typescript overloads here to have 2 function signatures!
|
// Note: We are using typescript overloads here to have 2 function signatures!
|
||||||
export function bootstrap<C>(
|
export function bootstrap<C>(
|
||||||
appComponentType: Type<C>,
|
appComponentType: Type<C>, customProviders?: Provider[]): Promise<ComponentRef<C>> {
|
||||||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<C>> {
|
|
||||||
let compilerOptions: CompilerOptions;
|
let compilerOptions: CompilerOptions;
|
||||||
let declarations: any[] = [];
|
let declarations: any[] = [];
|
||||||
let entryComponents: any[] = [];
|
let entryComponents: any[] = [];
|
||||||
|
@ -145,13 +145,13 @@ export function bootstrap<C>(
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export function bootstrapWorkerUi(
|
export function bootstrapWorkerUi(
|
||||||
workerScriptUri: string,
|
workerScriptUri: string, customProviders: Provider[] = []): Promise<PlatformRef> {
|
||||||
customProviders: Array<any /*Type | Provider | any[]*/> = []): Promise<PlatformRef> {
|
|
||||||
// For now, just creates the worker ui platform...
|
// For now, just creates the worker ui platform...
|
||||||
return Promise.resolve(platformWorkerUi([{
|
return Promise.resolve(platformWorkerUi(([{
|
||||||
provide: WORKER_SCRIPT,
|
provide: WORKER_SCRIPT,
|
||||||
useValue: workerScriptUri,
|
useValue: workerScriptUri,
|
||||||
}].concat(customProviders)));
|
}] as Provider[])
|
||||||
|
.concat(customProviders)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {XHR} from '@angular/compiler';
|
import {XHR} from '@angular/compiler';
|
||||||
import {Component, bind} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {TestBed, async, fakeAsync, flushMicrotasks, inject, tick} from '@angular/core/testing';
|
import {TestBed, async, fakeAsync, inject, tick} from '@angular/core/testing';
|
||||||
|
|
||||||
import {XHRImpl} from '../src/xhr/xhr_impl';
|
import {XHRImpl} from '../src/xhr/xhr_impl';
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {ClassProvider, ExistingProvider, FactoryProvider, TypeProvider, ValueProvider} from '@angular/core';
|
||||||
|
|
||||||
import * as browser from './src/browser';
|
import * as browser from './src/browser';
|
||||||
import * as ng_proble from './src/dom/debug/ng_probe';
|
import * as ng_proble from './src/dom/debug/ng_probe';
|
||||||
import * as dom_adapter from './src/dom/dom_adapter';
|
import * as dom_adapter from './src/dom/dom_adapter';
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {CommonModule, PlatformLocation} from '@angular/common';
|
import {CommonModule, PlatformLocation} from '@angular/common';
|
||||||
import {ApplicationModule, ExceptionHandler, NgModule, NgModuleFactory, NgModuleRef, NgZone, OpaqueToken, PLATFORM_INITIALIZER, PlatformRef, ReflectiveInjector, RootRenderer, SanitizationService, Testability, assertPlatform, createPlatform, createPlatformFactory, getPlatform, isDevMode, platformCore} from '@angular/core';
|
import {ApplicationModule, ExceptionHandler, NgModule, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, SanitizationService, Testability, createPlatformFactory, platformCore} from '@angular/core';
|
||||||
|
|
||||||
import {wtfInit} from '../core_private';
|
import {wtfInit} from '../core_private';
|
||||||
import {AnimationDriver} from '../src/dom/animation_driver';
|
import {AnimationDriver} from '../src/dom/animation_driver';
|
||||||
|
@ -25,10 +25,9 @@ import {EVENT_MANAGER_PLUGINS, EventManager} from './dom/events/event_manager';
|
||||||
import {HAMMER_GESTURE_CONFIG, HammerGestureConfig, HammerGesturesPlugin} from './dom/events/hammer_gestures';
|
import {HAMMER_GESTURE_CONFIG, HammerGestureConfig, HammerGesturesPlugin} from './dom/events/hammer_gestures';
|
||||||
import {KeyEventsPlugin} from './dom/events/key_events';
|
import {KeyEventsPlugin} from './dom/events/key_events';
|
||||||
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
|
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
|
||||||
import {isBlank} from './facade/lang';
|
|
||||||
import {DomSanitizationService, DomSanitizationServiceImpl} from './security/dom_sanitization_service';
|
import {DomSanitizationService, DomSanitizationServiceImpl} from './security/dom_sanitization_service';
|
||||||
|
|
||||||
export const INTERNAL_BROWSER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
export const INTERNAL_BROWSER_PLATFORM_PROVIDERS: Provider[] = [
|
||||||
{provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true},
|
{provide: PLATFORM_INITIALIZER, useValue: initDomAdapter, multi: true},
|
||||||
{provide: PlatformLocation, useClass: BrowserPlatformLocation}
|
{provide: PlatformLocation, useClass: BrowserPlatformLocation}
|
||||||
];
|
];
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseException, ExceptionHandler, Injectable, Injector, NgZone, OpaqueToken, PLATFORM_INITIALIZER, PlatformRef, ReflectiveInjector, RootRenderer, Testability, assertPlatform, createPlatform, createPlatformFactory, getPlatform, isDevMode, platformCore} from '@angular/core';
|
import {BaseException, ExceptionHandler, Injectable, Injector, NgZone, OpaqueToken, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, Testability, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
|
||||||
|
|
||||||
import {wtfInit} from '../core_private';
|
import {wtfInit} from '../core_private';
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import {EVENT_MANAGER_PLUGINS, EventManager} from './dom/events/event_manager';
|
||||||
import {HAMMER_GESTURE_CONFIG, HammerGestureConfig, HammerGesturesPlugin} from './dom/events/hammer_gestures';
|
import {HAMMER_GESTURE_CONFIG, HammerGestureConfig, HammerGesturesPlugin} from './dom/events/hammer_gestures';
|
||||||
import {KeyEventsPlugin} from './dom/events/key_events';
|
import {KeyEventsPlugin} from './dom/events/key_events';
|
||||||
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
|
import {DomSharedStylesHost, SharedStylesHost} from './dom/shared_styles_host';
|
||||||
import {isBlank} from './facade/lang';
|
|
||||||
import {ON_WEB_WORKER} from './web_workers/shared/api';
|
import {ON_WEB_WORKER} from './web_workers/shared/api';
|
||||||
import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from './web_workers/shared/client_message_broker';
|
import {ClientMessageBrokerFactory, ClientMessageBrokerFactory_} from './web_workers/shared/client_message_broker';
|
||||||
import {MessageBus} from './web_workers/shared/message_bus';
|
import {MessageBus} from './web_workers/shared/message_bus';
|
||||||
|
@ -70,7 +69,7 @@ export const WORKER_UI_STARTABLE_MESSAGING_SERVICE =
|
||||||
/**
|
/**
|
||||||
* @experimental WebWorker support is currently experimental.
|
* @experimental WebWorker support is currently experimental.
|
||||||
*/
|
*/
|
||||||
export const _WORKER_UI_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
export const _WORKER_UI_PLATFORM_PROVIDERS: Provider[] = [
|
||||||
{provide: NgZone, useFactory: createNgZone, deps: []},
|
{provide: NgZone, useFactory: createNgZone, deps: []},
|
||||||
MessageBasedRenderer,
|
MessageBasedRenderer,
|
||||||
{provide: WORKER_UI_STARTABLE_MESSAGING_SERVICE, useExisting: MessageBasedRenderer, multi: true},
|
{provide: WORKER_UI_STARTABLE_MESSAGING_SERVICE, useExisting: MessageBasedRenderer, multi: true},
|
||||||
|
@ -88,7 +87,7 @@ export const _WORKER_UI_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*
|
||||||
{provide: SharedStylesHost, useExisting: DomSharedStylesHost},
|
{provide: SharedStylesHost, useExisting: DomSharedStylesHost},
|
||||||
{provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_},
|
{provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_},
|
||||||
{provide: ClientMessageBrokerFactory, useClass: ClientMessageBrokerFactory_},
|
{provide: ClientMessageBrokerFactory, useClass: ClientMessageBrokerFactory_},
|
||||||
{provide: AnimationDriver, useFactory: _resolveDefaultAnimationDriver},
|
{provide: AnimationDriver, useFactory: _resolveDefaultAnimationDriver, deps: []},
|
||||||
Serializer,
|
Serializer,
|
||||||
{provide: ON_WEB_WORKER, useValue: false},
|
{provide: ON_WEB_WORKER, useValue: false},
|
||||||
RenderStore,
|
RenderStore,
|
||||||
|
|
|
@ -7,12 +7,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {XHR} from '@angular/compiler';
|
import {XHR} from '@angular/compiler';
|
||||||
import {APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Component, Directive, ExceptionHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, ReflectiveInjector, createPlatform, createPlatformFactory, provide} from '@angular/core';
|
import {APP_INITIALIZER, Component, Directive, ExceptionHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, createPlatformFactory} from '@angular/core';
|
||||||
import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref';
|
import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref';
|
||||||
import {Console} from '@angular/core/src/console';
|
import {Console} from '@angular/core/src/console';
|
||||||
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
||||||
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
||||||
import {ComponentFixture} from '@angular/core/testing';
|
|
||||||
import {AsyncTestCompleter, Log, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, Log, afterEach, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it} from '@angular/core/testing/testing_internal';
|
||||||
import {BrowserModule} from '@angular/platform-browser';
|
import {BrowserModule} from '@angular/platform-browser';
|
||||||
import {bootstrap, platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
import {bootstrap, platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ReflectiveInjector, provide} from '@angular/core';
|
import {ReflectiveInjector} from '@angular/core';
|
||||||
import {ApplicationRef, ApplicationRef_} from '@angular/core/src/application_ref';
|
import {ApplicationRef, ApplicationRef_} from '@angular/core/src/application_ref';
|
||||||
import {SpyObject} from '@angular/core/testing/testing_internal';
|
import {SpyObject} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {NgIf} from '@angular/common';
|
|
||||||
import {CompilerConfig, XHR} from '@angular/compiler';
|
import {CompilerConfig, XHR} from '@angular/compiler';
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA, Component, ComponentFactoryResolver, ComponentMetadata, Directive, DirectiveMetadata, HostBinding, Injectable, Input, NgModule, NgModuleMetadata, Pipe, PipeMetadata, ViewMetadata, provide} from '@angular/core';
|
import {CUSTOM_ELEMENTS_SCHEMA, Component, Directive, Injectable, Input, NgModule, Pipe} from '@angular/core';
|
||||||
import {TestBed, async, fakeAsync, inject, tick, withModule} from '@angular/core/testing';
|
import {TestBed, async, fakeAsync, inject, tick, withModule} from '@angular/core/testing';
|
||||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {provide} from '@angular/core';
|
|
||||||
import {beforeEach, beforeEachProviders, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal';
|
import {beforeEach, beforeEachProviders, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal';
|
||||||
import {ON_WEB_WORKER} from '@angular/platform-browser/src/web_workers/shared/api';
|
import {ON_WEB_WORKER} from '@angular/platform-browser/src/web_workers/shared/api';
|
||||||
import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store';
|
import {RenderStore} from '@angular/platform-browser/src/web_workers/shared/render_store';
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {LocationStrategy} from '@angular/common';
|
import {APP_ID, NgModule, NgZone, PLATFORM_INITIALIZER, PlatformRef, Provider, createPlatformFactory, platformCore} from '@angular/core';
|
||||||
import {APP_ID, NgModule, NgZone, OpaqueToken, PLATFORM_INITIALIZER, PlatformRef, ReflectiveInjector, assertPlatform, createPlatform, createPlatformFactory, getPlatform, platformCore} from '@angular/core';
|
|
||||||
|
|
||||||
import {BrowserModule} from '../src/browser';
|
import {BrowserModule} from '../src/browser';
|
||||||
import {BrowserDomAdapter} from '../src/browser/browser_adapter';
|
import {BrowserDomAdapter} from '../src/browser/browser_adapter';
|
||||||
|
@ -25,7 +24,7 @@ function createNgZone(): NgZone {
|
||||||
return new NgZone({enableLongStackTrace: true});
|
return new NgZone({enableLongStackTrace: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
const _TEST_BROWSER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
const _TEST_BROWSER_PLATFORM_PROVIDERS: Provider[] =
|
||||||
[{provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true}];
|
[{provide: PLATFORM_INITIALIZER, useValue: initBrowserTests, multi: true}];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -113,7 +113,7 @@ export class UpgradeAdapter {
|
||||||
*/
|
*/
|
||||||
private ng1ComponentsToBeUpgraded: {[name: string]: UpgradeNg1ComponentAdapterBuilder} = {};
|
private ng1ComponentsToBeUpgraded: {[name: string]: UpgradeNg1ComponentAdapterBuilder} = {};
|
||||||
/* @internal */
|
/* @internal */
|
||||||
private providers: Array<Type<any>|Provider|any[]|any> = [];
|
private providers: Provider[] = [];
|
||||||
|
|
||||||
// the ng2AppModule param should be required once the deprecated @Component.directives prop is
|
// the ng2AppModule param should be required once the deprecated @Component.directives prop is
|
||||||
// removed
|
// removed
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {bind} from '@angular/core/src/di';
|
|
||||||
import {Options} from './common';
|
import {Options} from './common';
|
||||||
|
|
||||||
export * from './common';
|
export * from './common';
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export {Injector, OpaqueToken, ReflectiveInjector, bind, provide} from '@angular/core/src/di';
|
export {Injector, OpaqueToken, ReflectiveInjector} from '@angular/core/src/di';
|
||||||
export {Options} from './src/common_options';
|
export {Options} from './src/common_options';
|
||||||
export {MeasureValues} from './src/measure_values';
|
export {MeasureValues} from './src/measure_values';
|
||||||
export {Metric} from './src/metric';
|
export {Metric} from './src/metric';
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {OpaqueToken, Provider, bind} from '@angular/core';
|
import {OpaqueToken, Provider} from '@angular/core';
|
||||||
import {StringMapWrapper} from '@angular/facade/src/collection';
|
import {StringMapWrapper} from '@angular/facade/src/collection';
|
||||||
import {isNumber} from '@angular/facade/src/lang';
|
import {isNumber} from '@angular/facade/src/lang';
|
||||||
|
|
||||||
|
@ -68,7 +68,8 @@ export class UserMetric extends Metric {
|
||||||
describe(): {[key: string]: any} { return this._userMetrics; }
|
describe(): {[key: string]: any} { return this._userMetrics; }
|
||||||
}
|
}
|
||||||
|
|
||||||
var _PROVIDERS = [bind(UserMetric)
|
var _PROVIDERS: Provider[] = [{
|
||||||
.toFactory(
|
provide: UserMetric,
|
||||||
(userMetrics, wdAdapter) => new UserMetric(userMetrics, wdAdapter),
|
useFactory: (userMetrics, wdAdapter) => new UserMetric(userMetrics, wdAdapter),
|
||||||
[Options.USER_METRICS, WebDriverAdapter])];
|
deps: [Options.USER_METRICS, WebDriverAdapter]
|
||||||
|
}];
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ReflectiveInjector} from '@angular/core';
|
import {Provider, ReflectiveInjector} from '@angular/core';
|
||||||
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, afterEach, beforeEach, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||||
import {StringMapWrapper} from '@angular/facade/src/collection';
|
import {StringMapWrapper} from '@angular/facade/src/collection';
|
||||||
import {Json, isBlank, isPresent} from '@angular/facade/src/lang';
|
import {Json, isBlank, isPresent} from '@angular/facade/src/lang';
|
||||||
import {Injector, Metric, MultiMetric, Options, PerfLogFeatures, PerflogMetric, UserMetric, WebDriverAdapter, WebDriverExtension, bind, provide} from 'benchpress/common';
|
import {Injector, Metric, MultiMetric, Options, PerfLogFeatures, PerflogMetric, UserMetric, WebDriverAdapter, WebDriverExtension} from 'benchpress/common';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
var wdAdapter: MockDriverAdapter;
|
var wdAdapter: MockDriverAdapter;
|
||||||
|
@ -26,10 +26,10 @@ export function main() {
|
||||||
userMetrics = StringMapWrapper.create();
|
userMetrics = StringMapWrapper.create();
|
||||||
}
|
}
|
||||||
wdAdapter = new MockDriverAdapter();
|
wdAdapter = new MockDriverAdapter();
|
||||||
var bindings = [
|
var bindings: Provider[] = [
|
||||||
Options.DEFAULT_PROVIDERS, UserMetric.PROVIDERS,
|
Options.DEFAULT_PROVIDERS, UserMetric.PROVIDERS,
|
||||||
bind(Options.USER_METRICS).toValue(userMetrics),
|
{provide: Options.USER_METRICS, useValue: userMetrics},
|
||||||
provide(WebDriverAdapter, {useValue: wdAdapter})
|
{provide: WebDriverAdapter, useValue: wdAdapter}
|
||||||
];
|
];
|
||||||
return ReflectiveInjector.resolveAndCreate(bindings).get(UserMetric);
|
return ReflectiveInjector.resolveAndCreate(bindings).get(UserMetric);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ export declare class AsyncPipe implements OnDestroy {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare const COMMON_DIRECTIVES: any[];
|
export declare const COMMON_DIRECTIVES: Provider[];
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare const COMMON_PIPES: (typeof AsyncPipe | typeof SlicePipe | typeof I18nPluralPipe | typeof I18nSelectPipe)[];
|
export declare const COMMON_PIPES: (typeof AsyncPipe | typeof SlicePipe | typeof I18nPluralPipe | typeof I18nSelectPipe)[];
|
||||||
|
|
|
@ -185,25 +185,6 @@ export declare class BaseException extends Error {
|
||||||
toString(): string;
|
toString(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
export declare function bind(token: any): ProviderBuilder;
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
export declare class Binding extends Provider {
|
|
||||||
/** @deprecated */ toAlias: any;
|
|
||||||
/** @deprecated */ toClass: Type<any>;
|
|
||||||
/** @deprecated */ toFactory: Function;
|
|
||||||
/** @deprecated */ toValue: any;
|
|
||||||
constructor(token: any, {toClass, toValue, toAlias, toFactory, deps, multi}: {
|
|
||||||
toClass?: Type<any>;
|
|
||||||
toValue?: any;
|
|
||||||
toAlias?: any;
|
|
||||||
toFactory: Function;
|
|
||||||
deps?: Object[];
|
|
||||||
multi?: boolean;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare enum ChangeDetectionStrategy {
|
export declare enum ChangeDetectionStrategy {
|
||||||
OnPush = 0,
|
OnPush = 0,
|
||||||
|
@ -229,6 +210,13 @@ export interface ClassDefinition {
|
||||||
[x: string]: Type<any> | Function | any[];
|
[x: string]: Type<any> | Function | any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @stable */
|
||||||
|
export interface ClassProvider {
|
||||||
|
multi?: boolean;
|
||||||
|
provide: any;
|
||||||
|
useClass: Type<any>;
|
||||||
|
}
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare class CollectionChangeRecord {
|
export declare class CollectionChangeRecord {
|
||||||
currentIndex: number;
|
currentIndex: number;
|
||||||
|
@ -558,11 +546,26 @@ export declare class ExceptionHandler {
|
||||||
static exceptionToString(exception: any, stackTrace?: any, reason?: string): string;
|
static exceptionToString(exception: any, stackTrace?: any, reason?: string): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @stable */
|
||||||
|
export interface ExistingProvider {
|
||||||
|
multi?: boolean;
|
||||||
|
provide: any;
|
||||||
|
useExisting: any;
|
||||||
|
}
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare class ExpressionChangedAfterItHasBeenCheckedException extends BaseException {
|
export declare class ExpressionChangedAfterItHasBeenCheckedException extends BaseException {
|
||||||
constructor(oldValue: any, currValue: any, context: any);
|
constructor(oldValue: any, currValue: any, context: any);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @stable */
|
||||||
|
export interface FactoryProvider {
|
||||||
|
deps: any[];
|
||||||
|
multi?: boolean;
|
||||||
|
provide: any;
|
||||||
|
useFactory: Function;
|
||||||
|
}
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare function forwardRef(forwardRefFn: ForwardRefFn): Type<any>;
|
export declare function forwardRef(forwardRefFn: ForwardRefFn): Type<any>;
|
||||||
|
|
||||||
|
@ -967,44 +970,8 @@ export declare abstract class PlatformRef {
|
||||||
abstract onDestroy(callback: () => void): void;
|
abstract onDestroy(callback: () => void): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated */
|
/** @stable */
|
||||||
export declare function provide(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
|
export declare type Provider = TypeProvider | ValueProvider | ClassProvider | ExistingProvider | FactoryProvider | any[];
|
||||||
useClass?: Type<any>;
|
|
||||||
useValue?: any;
|
|
||||||
useExisting?: any;
|
|
||||||
useFactory?: Function;
|
|
||||||
deps?: Object[];
|
|
||||||
multi?: boolean;
|
|
||||||
}): Provider;
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
export declare class Provider {
|
|
||||||
dependencies: Object[];
|
|
||||||
multi: boolean;
|
|
||||||
token: any;
|
|
||||||
useClass: Type<any>;
|
|
||||||
useExisting: any;
|
|
||||||
useFactory: Function;
|
|
||||||
useValue: any;
|
|
||||||
constructor(token: any, {useClass, useValue, useExisting, useFactory, deps, multi}: {
|
|
||||||
useClass?: Type<any>;
|
|
||||||
useValue?: any;
|
|
||||||
useExisting?: any;
|
|
||||||
useFactory?: Function;
|
|
||||||
deps?: Object[];
|
|
||||||
multi?: boolean;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
export declare class ProviderBuilder {
|
|
||||||
token: any;
|
|
||||||
constructor(token: any);
|
|
||||||
toAlias(aliasToken: any): Provider;
|
|
||||||
toClass(type: Type<any>): Provider;
|
|
||||||
toFactory(factory: Function, dependencies?: any[]): Provider;
|
|
||||||
toValue(value: any): Provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare class QueryList<T> {
|
export declare class QueryList<T> {
|
||||||
|
@ -1048,18 +1015,12 @@ export declare abstract class ReflectiveInjector implements Injector {
|
||||||
createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector;
|
createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector;
|
||||||
abstract get(token: any, notFoundValue?: any): any;
|
abstract get(token: any, notFoundValue?: any): any;
|
||||||
instantiateResolved(provider: ResolvedReflectiveProvider): any;
|
instantiateResolved(provider: ResolvedReflectiveProvider): any;
|
||||||
resolveAndCreateChild(providers: Array<Type<any> | Provider | {
|
resolveAndCreateChild(providers: Provider[]): ReflectiveInjector;
|
||||||
[k: string]: any;
|
resolveAndInstantiate(provider: Provider): any;
|
||||||
} | any[]>): ReflectiveInjector;
|
|
||||||
resolveAndInstantiate(provider: Type<any> | Provider): any;
|
|
||||||
/** @deprecated */ static fromResolvedBindings(providers: ResolvedReflectiveProvider[]): ReflectiveInjector;
|
/** @deprecated */ static fromResolvedBindings(providers: ResolvedReflectiveProvider[]): ReflectiveInjector;
|
||||||
/** @experimental */ static fromResolvedProviders(providers: ResolvedReflectiveProvider[], parent?: Injector): ReflectiveInjector;
|
/** @experimental */ static fromResolvedProviders(providers: ResolvedReflectiveProvider[], parent?: Injector): ReflectiveInjector;
|
||||||
static resolve(providers: Array<Type<any> | Provider | {
|
static resolve(providers: Provider[]): ResolvedReflectiveProvider[];
|
||||||
[k: string]: any;
|
static resolveAndCreate(providers: Provider[], parent?: Injector): ReflectiveInjector;
|
||||||
} | any[]>): ResolvedReflectiveProvider[];
|
|
||||||
static resolveAndCreate(providers: Array<Type<any> | Provider | {
|
|
||||||
[k: string]: any;
|
|
||||||
} | any[]>, parent?: Injector): ReflectiveInjector;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
|
@ -1277,6 +1238,17 @@ export interface TypeDecorator {
|
||||||
Class(obj: ClassDefinition): Type<any>;
|
Class(obj: ClassDefinition): Type<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @stable */
|
||||||
|
export interface TypeProvider extends Type<any> {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @stable */
|
||||||
|
export interface ValueProvider {
|
||||||
|
multi?: boolean;
|
||||||
|
provide: any;
|
||||||
|
useValue: any;
|
||||||
|
}
|
||||||
|
|
||||||
/** @stable */
|
/** @stable */
|
||||||
export declare var ViewChild: ViewChildMetadataFactory;
|
export declare var ViewChild: ViewChildMetadataFactory;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
export declare function bootstrap<C>(appComponentType: Type<C>, customProviders?: Array<any>): Promise<ComponentRef<C>>;
|
export declare function bootstrap<C>(appComponentType: Type<C>, customProviders?: Provider[]): Promise<ComponentRef<C>>;
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare function bootstrapWorkerUi(workerScriptUri: string, customProviders?: Array<any>): Promise<PlatformRef>;
|
export declare function bootstrapWorkerUi(workerScriptUri: string, customProviders?: Provider[]): Promise<PlatformRef>;
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare const CACHED_TEMPLATE_PROVIDER: Array<any>;
|
export declare const CACHED_TEMPLATE_PROVIDER: Provider[];
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare const platformBrowserDynamic: (extraProviders?: any[]) => PlatformRef;
|
export declare const platformBrowserDynamic: (extraProviders?: any[]) => PlatformRef;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare const _WORKER_UI_PLATFORM_PROVIDERS: Array<any>;
|
export declare const _WORKER_UI_PLATFORM_PROVIDERS: Provider[];
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare abstract class AnimationDriver {
|
export declare abstract class AnimationDriver {
|
||||||
|
|
Loading…
Reference in New Issue