Skip to content

Commit

Permalink
BREAKING CHANGE: Remove UIInjector.native infavor of `UIInjector.ge…
Browse files Browse the repository at this point in the history
…tNative()`

BREAKING CHANGE: Remove `stateProvider` from core. Use `stateRegistry`
and `stateService` in 88c6494
  • Loading branch information
christopherthielen committed Sep 22, 2016
1 parent d6c2580 commit d11b7dc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
41 changes: 31 additions & 10 deletions src/common/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import {noop} from "./common";

/**
* An interface for getting values from dependency injection.
*
* This injector primarily returns resolve values (using a [[ResolveContext]]) that match the given token.
* If no resolve is found for a token, then it will delegate to the native injector.
* The native injector may be Angular 1 `$injector`, Angular 2 `Injector`, or a naive polyfill.
*
* In Angular 2, the native injector might be the root Injector,
* or it might be a lazy loaded `NgModule` injector scoped to a lazy load state tree.
*/
export interface UIInjector {
/**
Expand All @@ -25,18 +32,17 @@ export interface UIInjector {
* injector.get(StateService).go('home');
* ```
*
* Note:
* The code that implements this interface may be Angular 1 `$injector`, Angular 2 `Injector`,
* a [[ResolveContext]], or a `ResolveContext` that delegates to the ng1/ng2 injector if keys are missing.
*
* @param key the key for the value to get. May be a string or arbitrary object.
* @return the Dependency Injection value that matches the key
* @param token the key for the value to get. May be a string or arbitrary object.
* @return the Dependency Injection value that matches the token
*/
get(key: any): any;
get(token: any): any;

/**
* Asynchronously gets a value from the injector
*
* If the [[ResolveContext]] has a [[Resolvable]] matching the token, it will be
* asynchronously resolved.
*
* Returns a promise for a value from the injector.
* Returns resolve values and/or values from the native injector (ng1/ng2).
*
Expand All @@ -48,8 +54,23 @@ export interface UIInjector {
* });
* ```
*
* @param key the key for the value to get. May be a string or arbitrary object.
* @return a Promise for the Dependency Injection value that matches the key
* @param token the key for the value to get. May be a string or arbitrary object.
* @return a Promise for the Dependency Injection value that matches the token
*/
getAsync(token: any): Promise<any>;

/**
* Gets a value from the native injector
*
* Returns a value from the native injector, bypassing anything in the [[ResolveContext]].
*
* Example:
* ```js
* let someThing = injector.getNative(SomeToken);
* ```
*
* @param token the key for the value to get. May be a string or arbitrary object.
* @return the Dependency Injection value that matches the token
*/
getAsync(key: any): any;
getNative(token: any): any;
}
24 changes: 0 additions & 24 deletions src/ng1/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,30 +301,6 @@ export const getLocals = (ctx: ResolveContext) => {
return tuples.reduce(applyPairs, {});
};

/** Adds the angular 1 `$injector` to the `UIInjector` interface */
declare module "../common/interface" {
/**
* This enhances the [[common.UIInjector]] interface by adding the `$injector` service as the [[native]] injector.
*/
interface UIInjector {
/**
* The native Angular 1 `$injector` service
*
* When you have access to a `UIInjector`, this property will contain the native `$injector` Angular 1 service.
*
* @example:
* ```js
*
* $transition.onStart({}, function(transition) {
* var uiInjector = transition.injector();
* var $injector = uiInjector.native;
* var val = $injector.invoke(someFunction);
* });
*/
native: $InjectorLike;
}
}

/** Injectable services */

/**
Expand Down
6 changes: 5 additions & 1 deletion src/resolve/resolveContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class ResolveContext {
let matching = availableResolvables.filter(r => r.token === token);
if (matching.length) return tail(matching);

let fromInjector = this.injector().get(token);
let fromInjector = this.injector().getNative(token);
if (!fromInjector) {
throw new Error("Could not find Dependency Injection token: " + stringify(token));
}
Expand Down Expand Up @@ -194,4 +194,8 @@ class UIInjectorImpl implements UIInjector {
if (resolvable) return resolvable.get(this.context);
return services.$q.when(this.native.get(token));
}

getNative(token: any) {
return this.native.get(token);
}
}

0 comments on commit d11b7dc

Please sign in to comment.