Skip to content

Commit c985f25

Browse files
committed
Merge pull request #670 from PascalPrecht/ngdocs
docs(state): wip documentation for state service
2 parents 8592142 + 51967c9 commit c985f25

8 files changed

+519
-85
lines changed

src/resolve.js

+66-39
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/**
2-
* Service (`ui-util`). Manages resolution of (acyclic) graphs of promises.
3-
* @module $resolve
2+
* @ngdoc object
3+
* @name ui.router.util.$resolve
4+
*
45
* @requires $q
56
* @requires $injector
7+
*
8+
* @description
9+
* Manages resolution of (acyclic) graphs of promises.
610
*/
711
$Resolve.$inject = ['$q', '$injector'];
812
function $Resolve( $q, $injector) {
@@ -16,15 +20,24 @@ function $Resolve( $q, $injector) {
1620

1721

1822
/**
23+
* @ngdoc function
24+
* @name ui.router.util.$resolve#study
25+
* @methodOf ui.router.util.$resolve
26+
*
27+
* @description
1928
* Studies a set of invocables that are likely to be used multiple times.
20-
* $resolve.study(invocables)(locals, parent, self)
29+
* <pre>
30+
* $resolve.study(invocables)(locals, parent, self)
31+
* </pre>
2132
* is equivalent to
22-
* $resolve.resolve(invocables, locals, parent, self)
23-
* but the former is more efficient (in fact `resolve` just calls `study` internally).
24-
* See {@link module:$resolve/resolve} for details.
25-
* @function
26-
* @param {Object} invocables
27-
* @return {Function}
33+
* <pre>
34+
* $resolve.resolve(invocables, locals, parent, self)
35+
* </pre>
36+
* but the former is more efficient (in fact `resolve` just calls `study`
37+
* internally).
38+
*
39+
* @param {object} invocables Invocable objects
40+
* @return {function} a function to pass in locals, parent and self
2841
*/
2942
this.study = function (invocables) {
3043
if (!isObject(invocables)) throw new Error("'invocables' must be an object");
@@ -160,51 +173,65 @@ function $Resolve( $q, $injector) {
160173
};
161174

162175
/**
163-
* Resolves a set of invocables. An invocable is a function to be invoked via `$injector.invoke()`,
164-
* and can have an arbitrary number of dependencies. An invocable can either return a value directly,
165-
* or a `$q` promise. If a promise is returned it will be resolved and the resulting value will be
166-
* used instead. Dependencies of invocables are resolved (in this order of precedence)
176+
* @ngdoc function
177+
* @name ui.router.util.$resolve#resolve
178+
* @methodOf ui.router.util.$resolve
179+
*
180+
* @description
181+
* Resolves a set of invocables. An invocable is a function to be invoked via
182+
* `$injector.invoke()`, and can have an arbitrary number of dependencies.
183+
* An invocable can either return a value directly,
184+
* or a `$q` promise. If a promise is returned it will be resolved and the
185+
* resulting value will be used instead. Dependencies of invocables are resolved
186+
* (in this order of precedence)
167187
*
168188
* - from the specified `locals`
169189
* - from another invocable that is part of this `$resolve` call
170-
* - from an invocable that is inherited from a `parent` call to `$resolve` (or recursively
171-
* from any ancestor `$resolve` of that parent).
190+
* - from an invocable that is inherited from a `parent` call to `$resolve`
191+
* (or recursively
192+
* - from any ancestor `$resolve` of that parent).
172193
*
173-
* The return value of `$resolve` is a promise for an object that contains (in this order of precedence)
194+
* The return value of `$resolve` is a promise for an object that contains
195+
* (in this order of precedence)
174196
*
175197
* - any `locals` (if specified)
176198
* - the resolved return values of all injectables
177199
* - any values inherited from a `parent` call to `$resolve` (if specified)
178200
*
179-
* The promise will resolve after the `parent` promise (if any) and all promises returned by injectables
180-
* have been resolved. If any invocable (or `$injector.invoke`) throws an exception, or if a promise
181-
* returned by an invocable is rejected, the `$resolve` promise is immediately rejected with the same error.
182-
* A rejection of a `parent` promise (if specified) will likewise be propagated immediately. Once the
183-
* `$resolve` promise has been rejected, no further invocables will be called.
201+
* The promise will resolve after the `parent` promise (if any) and all promises
202+
* returned by injectables have been resolved. If any invocable
203+
* (or `$injector.invoke`) throws an exception, or if a promise returned by an
204+
* invocable is rejected, the `$resolve` promise is immediately rejected with the
205+
* same error. A rejection of a `parent` promise (if specified) will likewise be
206+
* propagated immediately. Once the `$resolve` promise has been rejected, no
207+
* further invocables will be called.
184208
*
185-
* Cyclic dependencies between invocables are not permitted and will caues `$resolve` to throw an
186-
* error. As a special case, an injectable can depend on a parameter with the same name as the injectable,
187-
* which will be fulfilled from the `parent` injectable of the same name. This allows inherited values
188-
* to be decorated. Note that in this case any other injectable in the same `$resolve` with the same
209+
* Cyclic dependencies between invocables are not permitted and will caues `$resolve`
210+
* to throw an error. As a special case, an injectable can depend on a parameter
211+
* with the same name as the injectable, which will be fulfilled from the `parent`
212+
* injectable of the same name. This allows inherited values to be decorated.
213+
* Note that in this case any other injectable in the same `$resolve` with the same
189214
* dependency would see the decorated value, not the inherited value.
190215
*
191-
* Note that missing dependencies -- unlike cyclic dependencies -- will cause an (asynchronous) rejection
192-
* of the `$resolve` promise rather than a (synchronous) exception.
216+
* Note that missing dependencies -- unlike cyclic dependencies -- will cause an
217+
* (asynchronous) rejection of the `$resolve` promise rather than a (synchronous)
218+
* exception.
193219
*
194-
* Invocables are invoked eagerly as soon as all dependencies are available. This is true even for
195-
* dependencies inherited from a `parent` call to `$resolve`.
220+
* Invocables are invoked eagerly as soon as all dependencies are available.
221+
* This is true even for dependencies inherited from a `parent` call to `$resolve`.
196222
*
197-
* As a special case, an invocable can be a string, in which case it is taken to be a service name
198-
* to be passed to `$injector.get()`. This is supported primarily for backwards-compatibility with the
199-
* `resolve` property of `$routeProvider` routes.
223+
* As a special case, an invocable can be a string, in which case it is taken to
224+
* be a service name to be passed to `$injector.get()`. This is supported primarily
225+
* for backwards-compatibility with the `resolve` property of `$routeProvider`
226+
* routes.
200227
*
201-
* @function
202-
* @param {Object.<string, Function|string>} invocables functions to invoke or `$injector` services to fetch.
203-
* @param {Object.<string, *>} [locals] values to make available to the injectables
204-
* @param {Promise.<Object>} [parent] a promise returned by another call to `$resolve`.
205-
* @param {Object} [self] the `this` for the invoked methods
206-
* @return {Promise.<Object>} Promise for an object that contains the resolved return value
207-
* of all invocables, as well as any inherited and local values.
228+
* @param {object} invocables functions to invoke or
229+
* `$injector` services to fetch.
230+
* @param {object} locals values to make available to the injectables
231+
* @param {object} parent a promise returned by another call to `$resolve`.
232+
* @param {object} self the `this` for the invoked methods
233+
* @return {object} Promise for an object that contains the resolved return value
234+
* of all invocables, as well as any inherited and local values.
208235
*/
209236
this.resolve = function (invocables, locals, parent, self) {
210237
return this.study(invocables)(locals, parent, self);

0 commit comments

Comments
 (0)