UNPKG

3.2 kBTypeScriptView Raw
1import { ResolvePolicy, ResolvableLiteral } from './interface';
2import { ResolveContext } from './resolveContext';
3import { Transition } from '../transition/transition';
4import { StateObject } from '../state/stateObject';
5export declare let defaultResolvePolicy: ResolvePolicy;
6/**
7 * The basic building block for the resolve system.
8 *
9 * Resolvables encapsulate a state's resolve's resolveFn, the resolveFn's declared dependencies, the wrapped (.promise),
10 * and the unwrapped-when-complete (.data) result of the resolveFn.
11 *
12 * Resolvable.get() either retrieves the Resolvable's existing promise, or else invokes resolve() (which invokes the
13 * resolveFn) and returns the resulting promise.
14 *
15 * Resolvable.get() and Resolvable.resolve() both execute within a context path, which is passed as the first
16 * parameter to those fns.
17 */
18export declare class Resolvable implements ResolvableLiteral {
19 token: any;
20 policy: ResolvePolicy;
21 resolveFn: Function;
22 deps: any[];
23 data: any;
24 resolved: boolean;
25 promise: Promise<any>;
26 static fromData: (token: any, data: any) => Resolvable;
27 /** This constructor creates a Resolvable copy */
28 constructor(resolvable: Resolvable);
29 /** This constructor creates a new Resolvable from the plain old [[ResolvableLiteral]] javascript object */
30 constructor(resolvable: ResolvableLiteral);
31 /**
32 * This constructor creates a new `Resolvable`
33 *
34 * #### Example:
35 * ```js
36 * var resolvable1 = new Resolvable('mytoken', http => http.get('foo.json').toPromise(), [Http]);
37 *
38 * var resolvable2 = new Resolvable(UserService, dep => new UserService(dep.data), [SomeDependency]);
39 *
40 * var resolvable1Clone = new Resolvable(resolvable1);
41 * ```
42 *
43 * @param token The new resolvable's injection token, such as `"userList"` (a string) or `UserService` (a class).
44 * When this token is used during injection, the resolved value will be injected.
45 * @param resolveFn The function that returns the resolved value, or a promise for the resolved value
46 * @param deps An array of dependencies, which will be injected into the `resolveFn`
47 * @param policy the [[ResolvePolicy]] defines when and how the Resolvable is processed
48 * @param data Pre-resolved data. If the resolve value is already known, it may be provided here.
49 */
50 constructor(token: any, resolveFn: Function, deps?: any[], policy?: ResolvePolicy, data?: any);
51 getPolicy(state: StateObject): ResolvePolicy;
52 /**
53 * Asynchronously resolve this Resolvable's data
54 *
55 * Given a ResolveContext that this Resolvable is found in:
56 * Wait for this Resolvable's dependencies, then invoke this Resolvable's function
57 * and update the Resolvable's state
58 */
59 resolve(resolveContext: ResolveContext, trans?: Transition): Promise<any>;
60 /**
61 * Gets a promise for this Resolvable's data.
62 *
63 * Fetches the data and returns a promise.
64 * Returns the existing promise if it has already been fetched once.
65 */
66 get(resolveContext: ResolveContext, trans?: Transition): Promise<any>;
67 toString(): string;
68 clone(): Resolvable;
69}