UNPKG

3.58 kBTypeScriptView Raw
1import { UIRouter } from './router';
2/**
3 * An interface for getting values from dependency injection.
4 *
5 * This is primarily used to get resolve values for a given token.
6 * An instance of the `UIInjector` can be retrieved from the current transition using [[Transition.injector]].
7 *
8 * ---
9 *
10 * If no resolve is found for a token, then it will delegate to the native injector.
11 * The native injector may be Angular 1 `$injector`, Angular 2 `Injector`, or a simple polyfill.
12 *
13 * In Angular 2, the native injector might be the root Injector,
14 * or it might be a lazy loaded `NgModule` injector scoped to a lazy load state tree.
15 */
16export interface UIInjector {
17 /**
18 * Gets a value from the injector.
19 *
20 * For a given token, returns the value from the injector that matches the token.
21 * If the token is for a resolve that has not yet been fetched, this throws an error.
22 *
23 * #### Example:
24 * ```js
25 * var myResolve = injector.get('myResolve');
26 * ```
27 *
28 * #### ng1 Example:
29 * ```js
30 * // Fetch StateService
31 * injector.get('$state').go('home');
32 * ```
33 *
34 * #### ng2 Example:
35 * ```js
36 * import {StateService} from "ui-router-ng2";
37 * // Fetch StateService
38 * injector.get(StateService).go('home');
39 * ```
40 *
41 * #### Typescript Example:
42 * ```js
43 * var stringArray = injector.get<string[]>('myStringArray');
44 * ```
45 *
46 * ### `NOWAIT` policy
47 *
48 * When using [[ResolvePolicy.async]] === `NOWAIT`, the value returned from `get()` is a promise for the result.
49 * The promise is not automatically unwrapped.
50 *
51 * @param token the key for the value to get. May be a string, a class, or any arbitrary object.
52 * @return the Dependency Injection value that matches the token
53 */
54 get(token: any): any;
55 /** Gets a value as type `T` (generics parameter) */
56 get<T>(token: any): T;
57 /**
58 * Asynchronously gets a value from the injector
59 *
60 * For a given token, returns a promise for the value from the injector that matches the token.
61 * If the token is for a resolve that has not yet been fetched, this triggers the resolve to load.
62 *
63 * #### Example:
64 * ```js
65 * return injector.getAsync('myResolve').then(value => {
66 * if (value === 'declined') return false;
67 * });
68 * ```
69 *
70 * @param token the key for the value to get. May be a string or arbitrary object.
71 * @return a Promise for the Dependency Injection value that matches the token
72 */
73 getAsync(token: any): Promise<any>;
74 /** Asynchronously gets a value as type `T` (generics parameter) */
75 getAsync<T>(token: any): Promise<T>;
76 /**
77 * Gets a value from the native injector
78 *
79 * Returns a value from the native injector, bypassing anything in the [[ResolveContext]].
80 *
81 * Example:
82 * ```js
83 * let someThing = injector.getNative(SomeToken);
84 * ```
85 *
86 * @param token the key for the value to get. May be a string or arbitrary object.
87 * @return the Dependency Injection value that matches the token
88 */
89 getNative(token: any): any;
90 getNative<T>(token: any): T;
91}
92export interface UIRouterPlugin extends Disposable {
93 name: string;
94}
95export declare abstract class UIRouterPluginBase implements UIRouterPlugin, Disposable {
96 abstract name: string;
97 dispose(router: UIRouter): void;
98}
99export interface Disposable {
100 /** Instructs the Disposable to clean up any resources */
101 dispose(router?: UIRouter): any;
102}