UNPKG

4.11 kBJavaScriptView Raw
1/**
2 * State-based routing for AngularJS 1.x
3 * @version v1.0.30
4 * @link https://ui-router.github.io
5 * @license MIT License, http://www.opensource.org/licenses/MIT
6 */
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@uirouter/core'), require('angular')) :
9 typeof define === 'function' && define.amd ? define(['exports', '@uirouter/core', 'angular'], factory) :
10 (global = global || self, factory(global['@uirouter/angularjs-resolve-service'] = {}, global['@uirouter/core'], global.angular));
11}(this, (function (exports, core, angular) { 'use strict';
12
13 /** @publicapi @module ng1 */ /** */
14 /**
15 * Implementation of the legacy `$resolve` service for angular 1.
16 */
17 var $resolve = {
18 /**
19 * Asynchronously injects a resolve block.
20 *
21 * This emulates most of the behavior of the ui-router 0.2.x $resolve.resolve() service API.
22 *
23 * ### Not bundled by default
24 *
25 * This API is no longer not part of the standard `@uirouter/angularjs` bundle.
26 * For users of the prebuilt bundles, add the `release/resolveService.min.js` UMD bundle.
27 * For bundlers (webpack, browserify, etc), add `@uirouter/angularjs/lib/legacy/resolveService`.
28 *
29 * ---
30 *
31 * Given an object `invocables`, where keys are strings and values are injectable functions,
32 * injects each function, and waits for the resulting promise to resolve.
33 * When all resulting promises are resolved, returns the results as an object.
34 *
35 * #### Example:
36 * ```js
37 * let invocables = {
38 * foo: [ '$http', ($http) =>
39 * $http.get('/api/foo').then(resp => resp.data) ],
40 * bar: [ 'foo', '$http', (foo, $http) =>
41 * $http.get('/api/bar/' + foo.barId).then(resp => resp.data) ]
42 * }
43 * $resolve.resolve(invocables)
44 * .then(results => console.log(results.foo, results.bar))
45 * // Logs foo and bar:
46 * // { id: 123, barId: 456, fooData: 'foo data' }
47 * // { id: 456, barData: 'bar data' }
48 * ```
49 *
50 * @param invocables an object which looks like an [[StateDeclaration.resolve]] object; keys are resolve names and values are injectable functions
51 * @param locals key/value pre-resolved data (locals)
52 * @param parent a promise for a "parent resolve"
53 */
54 resolve: function (invocables, locals, parent) {
55 if (locals === void 0) { locals = {}; }
56 var parentNode = new core.PathNode(new core.StateObject({ params: {}, resolvables: [] }));
57 var node = new core.PathNode(new core.StateObject({ params: {}, resolvables: [] }));
58 var context = new core.ResolveContext([parentNode, node]);
59 context.addResolvables(core.resolvablesBuilder({ resolve: invocables }), node.state);
60 var resolveData = function (parentLocals) {
61 var rewrap = function (_locals) { return core.resolvablesBuilder({ resolve: core.mapObj(_locals, function (local) { return function () { return local; }; }) }); };
62 context.addResolvables(rewrap(parentLocals), parentNode.state);
63 context.addResolvables(rewrap(locals), node.state);
64 var tuples2ObjR = function (acc, tuple) {
65 acc[tuple.token] = tuple.value;
66 return acc;
67 };
68 return context.resolvePath().then(function (results) { return results.reduce(tuples2ObjR, {}); });
69 };
70 return parent ? parent.then(resolveData) : resolveData({});
71 },
72 };
73 /** @hidden */
74 var resolveFactory = function () { return $resolve; };
75 // The old $resolve service
76 angular.module('ui.router').factory('$resolve', resolveFactory);
77
78 exports.resolveFactory = resolveFactory;
79
80 Object.defineProperty(exports, '__esModule', { value: true });
81
82})));
83//# sourceMappingURL=resolveService.js.map