1
+ /** @module ng1 */ /** */
1
2
import { State } from "../../state/stateObject" ;
2
3
import { PathNode } from "../../path/node" ;
3
4
import { ResolveContext } from "../../resolve/resolveContext" ;
4
5
import { map } from "../../common/common" ;
5
6
import { resolvablesBuilder } from "../../state/stateBuilder" ;
6
7
7
- export const resolveFactory = ( ) => ( {
8
+ /**
9
+ * Implementation of the legacy `$resolve` service for angular 1.
10
+ */
11
+ var $resolve = {
8
12
/**
13
+ * Asynchronously injects a resolve block.
14
+ *
9
15
* This emulates most of the behavior of the ui-router 0.2.x $resolve.resolve() service API.
10
- * @param invocables an object, with keys as resolve names and values as injectable functions
16
+ *
17
+ * Given an object `invocables`, where keys are strings and values are injectable functions,
18
+ * injects each function, and waits for the resulting promise to resolve.
19
+ * When all resulting promises are resolved, returns the results as an object.
20
+ *
21
+ * @example
22
+ * ```js
23
+ *
24
+ * let invocables = {
25
+ * foo: [ '$http', ($http) =>
26
+ * $http.get('/api/foo').then(resp => resp.data) ],
27
+ * bar: [ 'foo', '$http', (foo, $http) =>
28
+ * $http.get('/api/bar/' + foo.barId).then(resp => resp.data) ]
29
+ * }
30
+ * $resolve.resolve(invocables)
31
+ * .then(results => console.log(results.foo, results.bar))
32
+ * // Logs foo and bar:
33
+ * // { id: 123, barId: 456, fooData: 'foo data' }
34
+ * // { id: 456, barData: 'bar data' }
35
+ * ```
36
+ *
37
+ * @param invocables an object which looks like an [[StateDefinition.resolve]] object; keys are resolve names and values are injectable functions
11
38
* @param locals key/value pre-resolved data (locals)
12
39
* @param parent a promise for a "parent resolve"
13
40
*/
@@ -32,4 +59,7 @@ export const resolveFactory = () => ({
32
59
33
60
return parent ? parent . then ( resolveData ) : resolveData ( { } ) ;
34
61
}
35
- } ) ;
62
+ } ;
63
+
64
+ /** @hidden */
65
+ export const resolveFactory = ( ) => $resolve ;
0 commit comments