@angular-wave/angular.ts 0.0.59 → 0.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +3 -0
  2. package/dist/angular-ts.esm.js +2 -2
  3. package/dist/angular-ts.umd.js +2 -2
  4. package/package.json +5 -1
  5. package/src/core/parser/lexer.html +18 -0
  6. package/src/core/parser/lexer.spec.js +300 -0
  7. package/src/core/parser/parse.js +19 -0
  8. package/src/core/parser/parser.js +1 -1
  9. package/src/core/parser/parser.test.js +19 -0
  10. package/src/core/q/q.js +46 -289
  11. package/src/core/q/q.md +229 -0
  12. package/src/core/sanitize/sanitize-uri.js +2 -3
  13. package/src/core/scope/scope.js +18 -8
  14. package/src/directive/if/if.js +6 -1
  15. package/src/filters/limit-to.js +5 -2
  16. package/src/loader.js +1 -5
  17. package/src/router/params/param-type.js +2 -1
  18. package/src/router/state/views.js +3 -0
  19. package/src/router/transition/reject-factory.js +1 -0
  20. package/src/router/url/url-rule.js +1 -1
  21. package/src/router/url/url-service.js +4 -4
  22. package/src/services/http/http.js +7 -5
  23. package/src/services/template-request.js +2 -7
  24. package/src/shared/common.js +1 -1
  25. package/src/shared/utils.js +1 -1
  26. package/src/types.js +9 -1
  27. package/types/core/parser/parse.d.ts +3 -4
  28. package/types/core/parser/parser.d.ts +1 -1
  29. package/types/core/q/q.d.ts +2 -2
  30. package/types/core/sanitize/sanitize-uri.d.ts +4 -5
  31. package/types/core/scope/scope.d.ts +19 -7
  32. package/types/loader.d.ts +0 -4
  33. package/types/router/params/param-type.d.ts +2 -1
  34. package/types/router/state/views.d.ts +2 -0
  35. package/types/router/transition/reject-factory.d.ts +1 -0
  36. package/types/router/url/url-rule.d.ts +0 -1
  37. package/types/router/url/url-service.d.ts +7 -7
  38. package/types/services/template-request.d.ts +4 -9
  39. package/types/types.d.ts +6 -1
  40. package/src/core/parser/parse.test.js +0 -12
  41. package/types-back/README.md +0 -2
  42. package/types-back/angular.d.ts +0 -146
  43. package/types-back/index.d.ts +0 -2126
  44. package/types-back/jqlite.d.ts +0 -374
  45. package/types-back/router/core/common/common.d.ts +0 -416
  46. package/types-back/router/core/common/coreservices.d.ts +0 -77
  47. package/types-back/router/core/common/glob.d.ts +0 -60
  48. package/types-back/router/core/common/hof.d.ts +0 -168
  49. package/types-back/router/core/common/index.d.ts +0 -8
  50. package/types-back/router/core/common/predicates.d.ts +0 -25
  51. package/types-back/router/core/common/queue.d.ts +0 -15
  52. package/types-back/router/core/common/safeConsole.d.ts +0 -5
  53. package/types-back/router/core/common/strings.d.ts +0 -66
  54. package/types-back/router/core/common/trace.d.ts +0 -126
  55. package/types-back/router/core/globals.d.ts +0 -43
  56. package/types-back/router/core/hooks/coreResolvables.d.ts +0 -6
  57. package/types-back/router/core/hooks/ignoredTransition.d.ts +0 -4
  58. package/types-back/router/core/hooks/invalidTransition.d.ts +0 -4
  59. package/types-back/router/core/hooks/lazyLoad.d.ts +0 -17
  60. package/types-back/router/core/hooks/onEnterExitRetain.d.ts +0 -10
  61. package/types-back/router/core/hooks/redirectTo.d.ts +0 -4
  62. package/types-back/router/core/hooks/resolve.d.ts +0 -11
  63. package/types-back/router/core/hooks/updateGlobals.d.ts +0 -4
  64. package/types-back/router/core/hooks/url.d.ts +0 -4
  65. package/types-back/router/core/hooks/views.d.ts +0 -7
  66. package/types-back/router/core/index.d.ts +0 -11
  67. package/types-back/router/core/interface.d.ts +0 -91
  68. package/types-back/router/core/params/index.d.ts +0 -12
  69. package/types-back/router/core/params/interface.d.ts +0 -606
  70. package/types-back/router/core/params/param.d.ts +0 -77
  71. package/types-back/router/core/params/paramType.d.ts +0 -65
  72. package/types-back/router/core/params/paramTypes.d.ts +0 -193
  73. package/types-back/router/core/params/stateParams.d.ts +0 -15
  74. package/types-back/router/core/path/index.d.ts +0 -2
  75. package/types-back/router/core/path/pathNode.d.ts +0 -60
  76. package/types-back/router/core/path/pathUtils.d.ts +0 -105
  77. package/types-back/router/core/resolve/index.d.ts +0 -3
  78. package/types-back/router/core/resolve/interface.d.ts +0 -210
  79. package/types-back/router/core/resolve/resolvable.d.ts +0 -75
  80. package/types-back/router/core/resolve/resolveContext.d.ts +0 -97
  81. package/types-back/router/core/router.d.ts +0 -57
  82. package/types-back/router/core/state/index.d.ts +0 -28
  83. package/types-back/router/core/state/interface.d.ts +0 -732
  84. package/types-back/router/core/state/stateBuilder.d.ts +0 -107
  85. package/types-back/router/core/state/stateMatcher.d.ts +0 -13
  86. package/types-back/router/core/state/stateObject.d.ts +0 -170
  87. package/types-back/router/core/state/stateQueueManager.d.ts +0 -27
  88. package/types-back/router/core/state/stateRegistry.d.ts +0 -138
  89. package/types-back/router/core/state/stateService.d.ts +0 -386
  90. package/types-back/router/core/state/targetState.d.ts +0 -105
  91. package/types-back/router/core/transition/hookBuilder.d.ts +0 -49
  92. package/types-back/router/core/transition/hookRegistry.d.ts +0 -115
  93. package/types-back/router/core/transition/index.d.ts +0 -20
  94. package/types-back/router/core/transition/interface.d.ts +0 -862
  95. package/types-back/router/core/transition/rejectFactory.d.ts +0 -103
  96. package/types-back/router/core/transition/transition.d.ts +0 -575
  97. package/types-back/router/core/transition/transitionEventType.d.ts +0 -26
  98. package/types-back/router/core/transition/transitionHook.d.ts +0 -96
  99. package/types-back/router/core/transition/transitionService.d.ts +0 -253
  100. package/types-back/router/core/url/index.d.ts +0 -8
  101. package/types-back/router/core/url/interface.d.ts +0 -169
  102. package/types-back/router/core/url/urlConfig.d.ts +0 -144
  103. package/types-back/router/core/url/urlMatcher.d.ts +0 -185
  104. package/types-back/router/core/url/urlMatcherFactory.d.ts +0 -56
  105. package/types-back/router/core/url/urlRouter.d.ts +0 -101
  106. package/types-back/router/core/url/urlRule.d.ts +0 -143
  107. package/types-back/router/core/url/urlRules.d.ts +0 -251
  108. package/types-back/router/core/url/urlService.d.ts +0 -205
  109. package/types-back/router/core/view/index.d.ts +0 -2
  110. package/types-back/router/core/view/interface.d.ts +0 -46
  111. package/types-back/router/core/view/view.d.ts +0 -176
  112. package/types-back/router/directives/viewDirective.d.ts +0 -144
  113. package/types-back/router/index.d.ts +0 -17
  114. package/types-back/router/interface.d.ts +0 -500
  115. package/types-back/router/legacy/resolveService.d.ts +0 -47
  116. package/types-back/router/legacy/stateEvents.d.ts +0 -124
  117. package/types-back/router/services.d.ts +0 -15
  118. package/types-back/router/stateFilters.d.ts +0 -10
  119. package/types-back/router/stateProvider.d.ts +0 -258
  120. package/types-back/router/statebuilders/onEnterExitRetain.d.ts +0 -13
  121. package/types-back/router/statebuilders/views.d.ts +0 -53
  122. package/types-back/router/templateFactory.d.ts +0 -104
  123. package/types-back/router/viewScroll.d.ts +0 -9
package/src/core/q/q.js CHANGED
@@ -1,221 +1,3 @@
1
- /**
2
- * @ngdoc service
3
- * @name $q
4
- * @requires $rootScope
5
- *
6
- * @description
7
- * A service that helps you run functions asynchronously, and use their return values (or exceptions)
8
- * when they are done processing.
9
- *
10
- * This is a [Promises/A+](https://promisesaplus.com/)-compliant implementation of promises/deferred
11
- * objects inspired by [Kris Kowal's Q](https://github.com/kriskowal/q).
12
- *
13
- * $q can be used in two fashions --- one which is more similar to Kris Kowal's Q or jQuery's Deferred
14
- * implementations, and the other which resembles ES6 (ES2015) promises to some degree.
15
- *
16
- * ## $q constructor
17
- *
18
- * The streamlined ES6 style promise is essentially just using $q as a constructor which takes a `resolver`
19
- * function as the first argument. This is similar to the native Promise implementation from ES6,
20
- * see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
21
- *
22
- * While the constructor-style use is supported, not all of the supporting methods from ES6 promises are
23
- * available yet.
24
- *
25
- * It can be used like so:
26
- *
27
- * ```js
28
- * // for the purpose of this example let's assume that variables `$q` and `okToGreet`
29
- * // are available in the current lexical scope (they could have been injected or passed in).
30
- *
31
- * function asyncGreet(name) {
32
- * // perform some asynchronous operation, resolve or reject the promise when appropriate.
33
- * return $q(function(resolve, reject) {
34
- * setTimeout(function() {
35
- * if (okToGreet(name)) {
36
- * resolve('Hello, ' + name + '!');
37
- * } else {
38
- * reject('Greeting ' + name + ' is not allowed.');
39
- * }
40
- * }, 1000);
41
- * });
42
- * }
43
- *
44
- * let promise = asyncGreet('Robin Hood');
45
- * promise.then(function(greeting) {
46
- * alert('Success: ' + greeting);
47
- * }, function(reason) {
48
- * alert('Failed: ' + reason);
49
- * });
50
- * ```
51
- *
52
- * Note: progress/notify callbacks are not currently supported via the ES6-style interface.
53
- *
54
- * Note: unlike ES6 behavior, an exception thrown in the constructor function will NOT implicitly reject the promise.
55
- *
56
- * However, the more traditional CommonJS-style usage is still available, and documented below.
57
- *
58
- * [The CommonJS Promise proposal](http://wiki.commonjs.org/wiki/Promises) describes a promise as an
59
- * interface for interacting with an object that represents the result of an action that is
60
- * performed asynchronously, and may or may not be finished at any given point in time.
61
- *
62
- * From the perspective of dealing with error handling, deferred and promise APIs are to
63
- * asynchronous programming what `try`, `catch` and `throw` keywords are to synchronous programming.
64
- *
65
- * ```js
66
- * // for the purpose of this example let's assume that variables `$q` and `okToGreet`
67
- * // are available in the current lexical scope (they could have been injected or passed in).
68
- *
69
- * function asyncGreet(name) {
70
- * let deferred = $q.defer();
71
- *
72
- * setTimeout(function() {
73
- * deferred.notify('About to greet ' + name + '.');
74
- *
75
- * if (okToGreet(name)) {
76
- * deferred.resolve('Hello, ' + name + '!');
77
- * } else {
78
- * deferred.reject('Greeting ' + name + ' is not allowed.');
79
- * }
80
- * }, 1000);
81
- *
82
- * return deferred.promise;
83
- * }
84
- *
85
- * let promise = asyncGreet('Robin Hood');
86
- * promise.then(function(greeting) {
87
- * alert('Success: ' + greeting);
88
- * }, function(reason) {
89
- * alert('Failed: ' + reason);
90
- * }, function(update) {
91
- * alert('Got notification: ' + update);
92
- * });
93
- * ```
94
- *
95
- * At first it might not be obvious why this extra complexity is worth the trouble. The payoff
96
- * comes in the way of guarantees that promise and deferred APIs make, see
97
- * https://github.com/kriskowal/uncommonjs/blob/master/promises/specification.md.
98
- *
99
- * Additionally the promise api allows for composition that is very hard to do with the
100
- * traditional callback ([CPS](http://en.wikipedia.org/wiki/Continuation-passing_style)) approach.
101
- * For more on this please see the [Q documentation](https://github.com/kriskowal/q) especially the
102
- * section on serial or parallel joining of promises.
103
- *
104
- * ## The Deferred API
105
- *
106
- * A new instance of deferred is constructed by calling `$q.defer()`.
107
- *
108
- * The purpose of the deferred object is to expose the associated Promise instance as well as APIs
109
- * that can be used for signaling the successful or unsuccessful completion, as well as the status
110
- * of the task.
111
- *
112
- * **Methods**
113
- *
114
- * - `resolve(value)` – resolves the derived promise with the `value`. If the value is a rejection
115
- * constructed via `$q.reject`, the promise will be rejected instead.
116
- * - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to
117
- * resolving it with a rejection constructed via `$q.reject`.
118
- * - `notify(value)` - provides updates on the status of the promise's execution. This may be called
119
- * multiple times before the promise is either resolved or rejected.
120
- *
121
- * **Properties**
122
- *
123
- * - promise – `{Promise}` – promise object associated with this deferred.
124
- *
125
- *
126
- * ## The Promise API
127
- *
128
- * A new promise instance is created when a deferred instance is created and can be retrieved by
129
- * calling `deferred.promise`.
130
- *
131
- * The purpose of the promise object is to allow for interested parties to get access to the result
132
- * of the deferred task when it completes.
133
- *
134
- * **Methods**
135
- *
136
- * - `then(successCallback, [errorCallback], [notifyCallback])` – regardless of when the promise was or
137
- * will be resolved or rejected, `then` calls one of the success or error callbacks asynchronously
138
- * as soon as the result is available. The callbacks are called with a single argument: the result
139
- * or rejection reason. Additionally, the notify callback may be called zero or more times to
140
- * provide a progress indication, before the promise is resolved or rejected.
141
- *
142
- * This method *returns a new promise* which is resolved or rejected via the return value of the
143
- * `successCallback`, `errorCallback` (unless that value is a promise, in which case it is resolved
144
- * with the value which is resolved in that promise using
145
- * [promise chaining](http://www.html5rocks.com/en/tutorials/es6/promises/#toc-promises-queues)).
146
- * It also notifies via the return value of the `notifyCallback` method. The promise cannot be
147
- * resolved or rejected from the notifyCallback method. The errorCallback and notifyCallback
148
- * arguments are optional.
149
- *
150
- * - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
151
- *
152
- * - `finally(callback, notifyCallback)` – allows you to observe either the fulfillment or rejection of a promise,
153
- * but to do so without modifying the final value. This is useful to release resources or do some
154
- * clean-up that needs to be done whether the promise was rejected or resolved. See the [full
155
- * specification](https://github.com/kriskowal/q/wiki/API-Reference#promisefinallycallback) for
156
- * more information.
157
- *
158
- * ## Chaining promises
159
- *
160
- * Because calling the `then` method of a promise returns a new derived promise, it is easily
161
- * possible to create a chain of promises:
162
- *
163
- * ```js
164
- * promiseB = promiseA.then(function(result) {
165
- * return result + 1;
166
- * });
167
- *
168
- * // promiseB will be resolved immediately after promiseA is resolved and its value
169
- * // will be the result of promiseA incremented by 1
170
- * ```
171
- *
172
- * It is possible to create chains of any length and since a promise can be resolved with another
173
- * promise (which will defer its resolution further), it is possible to pause/defer resolution of
174
- * the promises at any point in the chain. This makes it possible to implement powerful APIs like
175
- * $http's response interceptors.
176
- *
177
- *
178
- * ## Differences between Kris Kowal's Q and $q
179
- *
180
- * There are two main differences:
181
- *
182
- * - $q is integrated with the {@link ng.$rootScope.Scope} Scope model observation
183
- * mechanism in AngularJS, which means faster propagation of resolution or rejection into your
184
- * models and avoiding unnecessary browser repaints, which would result in flickering UI.
185
- * - Q has many more features than $q, but that comes at a cost of bytes. $q is tiny, but contains
186
- * all the important functionality needed for common async tasks.
187
- *
188
- * ## Testing
189
- *
190
- * ```js
191
- * it('should simulate promise', inject(function($q, $rootScope) {
192
- * let deferred = $q.defer();
193
- * let promise = deferred.promise;
194
- * let resolvedValue;
195
- *
196
- * promise.then(function(value) { resolvedValue = value; });
197
- * expect(resolvedValue).toBeUndefined();
198
- *
199
- * // Simulate resolving of promise
200
- * deferred.resolve(123);
201
- * // Note that the 'then' function does not get called synchronously.
202
- * // This is because we want the promise API to always be async, whether or not
203
- * // it got called synchronously or asynchronously.
204
- * expect(resolvedValue).toBeUndefined();
205
- *
206
- * // Propagate promise resolution to 'then' functions using $apply().
207
- * $rootScope.$apply();
208
- * expect(resolvedValue).toEqual(123);
209
- * }));
210
- * ```
211
- *
212
- * @param {function(function, function)} resolver Function which is responsible for resolving or
213
- * rejecting the newly created promise. The first parameter is a function which resolves the
214
- * promise, the second parameter is a function which rejects the promise.
215
- *
216
- * @returns {Promise} The newly created promise.
217
- */
218
-
219
1
  /**
220
2
  * @template T
221
3
  * @typedef {Object} angular.QPromise
@@ -246,7 +28,6 @@
246
28
  import {
247
29
  forEach,
248
30
  minErr,
249
- extend,
250
31
  isUndefined,
251
32
  isFunction,
252
33
  isObject,
@@ -295,7 +76,7 @@ export function $QProvider() {
295
76
  * This feature is enabled by default.
296
77
  *
297
78
  * @param {boolean=} value Whether to generate an error when a rejected promise is not handled.
298
- * @returns {boolean|ng.$qProvider} Current value when called without a new value or self for
79
+ * @returns {boolean|$QProvider} Current value when called without a new value or self for
299
80
  * chaining otherwise.
300
81
  */
301
82
  this.errorOnUnhandledRejections = function (value) {
@@ -306,6 +87,7 @@ export function $QProvider() {
306
87
  return errorOnUnhandledRejections;
307
88
  };
308
89
  }
90
+
309
91
  export function $$QProvider() {
310
92
  let errorOnUnhandledRejections = true;
311
93
  this.$get = [
@@ -334,8 +116,8 @@ export function $$QProvider() {
334
116
  /**
335
117
  * Constructs a promise manager.
336
118
  *
337
- * @param {function(function)} nextTick Function for executing functions in the next turn.
338
- * @param {function(...*)} exceptionHandler Function into which unexpected exceptions are passed for
119
+ * @param {function(function):any} nextTick Function for executing functions in the next turn.
120
+ * @param {function(...any):any} exceptionHandler Function into which unexpected exceptions are passed for
339
121
  * debugging purposes.
340
122
  * @param {boolean=} errorOnUnhandledRejections Whether an error should be generated on unhandled
341
123
  * promises rejections.
@@ -378,41 +160,34 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
378
160
  this.$$state = { status: 0 };
379
161
  }
380
162
 
381
- extend(QPromise.prototype, {
382
- then(onFulfilled, onRejected, progressBack) {
383
- if (
384
- isUndefined(onFulfilled) &&
385
- isUndefined(onRejected) &&
386
- isUndefined(progressBack)
387
- ) {
388
- return this;
389
- }
390
- const result = new QPromise();
391
-
392
- this.$$state.pending = this.$$state.pending || [];
393
- this.$$state.pending.push([
394
- result,
395
- onFulfilled,
396
- onRejected,
397
- progressBack,
398
- ]);
399
- if (this.$$state.status > 0) scheduleProcessQueue(this.$$state);
400
-
401
- return result;
402
- },
163
+ QPromise.prototype.then = function (onFulfilled, onRejected, progressBack) {
164
+ if (
165
+ isUndefined(onFulfilled) &&
166
+ isUndefined(onRejected) &&
167
+ isUndefined(progressBack)
168
+ ) {
169
+ return this;
170
+ }
171
+ const result = new QPromise();
403
172
 
404
- catch(callback) {
405
- return this.then(null, callback);
406
- },
173
+ this.$$state.pending = this.$$state.pending || [];
174
+ this.$$state.pending.push([result, onFulfilled, onRejected, progressBack]);
175
+ if (this.$$state.status > 0) scheduleProcessQueue(this.$$state);
407
176
 
408
- finally(callback, progressBack) {
409
- return this.then(
410
- (value) => handleCallback(value, resolve, callback),
411
- (error) => handleCallback(error, reject, callback),
412
- progressBack,
413
- );
414
- },
415
- });
177
+ return result;
178
+ };
179
+
180
+ QPromise.prototype.catch = function (callback) {
181
+ return this.then(null, callback);
182
+ };
183
+
184
+ QPromise.prototype.finally = function (callback, progressBack) {
185
+ return this.then(
186
+ (value) => handleCallback(value, resolve, callback),
187
+ (error) => handleCallback(error, reject, callback),
188
+ progressBack,
189
+ );
190
+ };
416
191
 
417
192
  function processQueue(state) {
418
193
  let fn;
@@ -569,11 +344,6 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
569
344
  }
570
345
 
571
346
  /**
572
- * @ngdoc method
573
- * @name $q#reject
574
- * @kind function
575
- *
576
- * @description
577
347
  * Creates a promise that is resolved as rejected with the specified `reason`. This api should be
578
348
  * used to forward rejection in a chain of promises. If you are dealing with the last promise in
579
349
  * a promise chain, you don't need to worry about it.
@@ -602,7 +372,7 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
602
372
  * ```
603
373
  *
604
374
  * @param {*} reason Constant, message, exception or an object representing the rejection reason.
605
- * @returns {Promise} Returns a promise that was already resolved as rejected with the `reason`.
375
+ * @returns {QPromise} Returns a promise that was already resolved as rejected with the `reason`.
606
376
  */
607
377
  function reject(reason) {
608
378
  const result = new QPromise();
@@ -624,11 +394,6 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
624
394
  }
625
395
 
626
396
  /**
627
- * @ngdoc method
628
- * @name $q#when
629
- * @kind function
630
- *
631
- * @description
632
397
  * Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise.
633
398
  * This is useful when you are dealing with an object that might or might not be a promise, or if
634
399
  * the promise comes from a source that can't be trusted.
@@ -637,22 +402,17 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
637
402
  * @param {Function=} successCallback
638
403
  * @param {Function=} errorCallback
639
404
  * @param {Function=} progressCallback
640
- * @returns {Promise} Returns a promise of the passed value or promise
405
+ * @returns {QPromise} Returns a promise of the passed value or promise
641
406
  */
642
407
 
643
- function when(value, callback, errback, progressBack) {
408
+ function when(value, successCallback, errorCallback, progressCallback) {
644
409
  const result = new QPromise();
645
410
  resolvePromise(result, value);
646
- return result.then(callback, errback, progressBack);
411
+ return result.then(successCallback, errorCallback, progressCallback);
647
412
  }
648
413
 
649
414
  /**
650
- * @ngdoc method
651
- * @name $q#resolve
652
- * @kind function
653
- *
654
- * @description
655
- * Alias of {@link ng.$q#when when} to maintain naming consistency with ES6.
415
+ * Alias of {@link when} to maintain naming consistency with ES6.
656
416
  *
657
417
  * @param {*} value Value or a promise
658
418
  * @param {Function=} successCallback
@@ -663,16 +423,11 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
663
423
  let resolve = when;
664
424
 
665
425
  /**
666
- * @ngdoc method
667
- * @name $q#all
668
- * @kind function
669
- *
670
- * @description
671
426
  * Combines multiple promises into a single promise that is resolved when all of the input
672
427
  * promises are resolved.
673
428
  *
674
- * @param {Array.<Promise>|Object.<Promise>} promises An array or hash of promises.
675
- * @returns {Promise} Returns a single promise that will be resolved with an array/hash of values,
429
+ * @param {Array.<QPromise>} promises An array or hash of promises.
430
+ * @returns {QPromise} Returns a single promise that will be resolved with an array/hash of values,
676
431
  * each value corresponding to the promise at the same index/key in the `promises` array/hash.
677
432
  * If any of the promises is resolved with a rejection, this resulting promise will be rejected
678
433
  * with the same rejection value.
@@ -704,16 +459,11 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
704
459
  }
705
460
 
706
461
  /**
707
- * @ngdoc method
708
- * @name $q#race
709
- * @kind function
710
- *
711
- * @description
712
462
  * Returns a promise that resolves or rejects as soon as one of those promises
713
463
  * resolves or rejects, with the value or reason from that promise.
714
464
  *
715
- * @param {Array.<Promise>|Object.<Promise>} promises An array or hash of promises.
716
- * @returns {Promise} a promise that resolves or rejects as soon as one of the `promises`
465
+ * @param {Array.<QPromise>} promises An array or hash of promises.
466
+ * @returns {QPromise} a promise that resolves or rejects as soon as one of the `promises`
717
467
  * resolves or rejects, with the value or reason from that promise.
718
468
  */
719
469
 
@@ -727,6 +477,13 @@ function qFactory(nextTick, exceptionHandler, errorOnUnhandledRejections) {
727
477
  return deferred.promise;
728
478
  }
729
479
 
480
+ /**
481
+ * @param {function(function, function):any} resolver Function which is responsible for resolving or
482
+ * rejecting the newly created promise. The first parameter is a function which resolves the
483
+ * promise, the second parameter is a function which rejects the promise.
484
+ *
485
+ * @returns {QPromise} The newly created promise.
486
+ */
730
487
  function $Q(resolver) {
731
488
  if (!isFunction(resolver)) {
732
489
  throw $qMinErr("norslvr", "Expected resolverFn, got '{0}'", resolver);
@@ -0,0 +1,229 @@
1
+ /\*\*
2
+
3
+ - A service that helps you run functions asynchronously, and use their return values (or exceptions)
4
+ - when they are done processing.
5
+ -
6
+ - This is a [Promises/A+](https://promisesaplus.com/)-compliant implementation of promises/deferred
7
+ - objects inspired by [Kris Kowal's Q](https://github.com/kriskowal/q).
8
+ -
9
+ - $q can be used in two fashions --- one which is more similar to Kris Kowal's Q or jQuery's Deferred
10
+ - implementations, and the other which resembles ES6 (ES2015) promises to some degree.
11
+ -
12
+ - ## $q constructor
13
+ -
14
+ - The streamlined ES6 style promise is essentially just using $q as a constructor which takes a `resolver`
15
+ - function as the first argument. This is similar to the native Promise implementation from ES6,
16
+ - see [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
17
+ -
18
+ - While the constructor-style use is supported, not all of the supporting methods from ES6 promises are
19
+ - available yet.
20
+ -
21
+ - It can be used like so:
22
+ -
23
+ - ```js
24
+
25
+ ```
26
+
27
+ - // for the purpose of this example let's assume that variables `$q` and `okToGreet`
28
+ - // are available in the current lexical scope (they could have been injected or passed in).
29
+ -
30
+ - function asyncGreet(name) {
31
+ - // perform some asynchronous operation, resolve or reject the promise when appropriate.
32
+ - return $q(function(resolve, reject) {
33
+ - setTimeout(function() {
34
+ - if (okToGreet(name)) {
35
+ - resolve('Hello, ' + name + '!');
36
+ - } else {
37
+ - reject('Greeting ' + name + ' is not allowed.');
38
+ - }
39
+ - }, 1000);
40
+ - });
41
+ - }
42
+ -
43
+ - let promise = asyncGreet('Robin Hood');
44
+ - promise.then(function(greeting) {
45
+ - alert('Success: ' + greeting);
46
+ - }, function(reason) {
47
+ - alert('Failed: ' + reason);
48
+ - });
49
+ - ```
50
+
51
+ ```
52
+
53
+ -
54
+ - Note: progress/notify callbacks are not currently supported via the ES6-style interface.
55
+ -
56
+ - Note: unlike ES6 behavior, an exception thrown in the constructor function will NOT implicitly reject the promise.
57
+ -
58
+ - However, the more traditional CommonJS-style usage is still available, and documented below.
59
+ -
60
+ - [The CommonJS Promise proposal](http://wiki.commonjs.org/wiki/Promises) describes a promise as an
61
+ - interface for interacting with an object that represents the result of an action that is
62
+ - performed asynchronously, and may or may not be finished at any given point in time.
63
+ -
64
+ - From the perspective of dealing with error handling, deferred and promise APIs are to
65
+ - asynchronous programming what `try`, `catch` and `throw` keywords are to synchronous programming.
66
+ -
67
+ - ```js
68
+
69
+ ```
70
+
71
+ - // for the purpose of this example let's assume that variables `$q` and `okToGreet`
72
+ - // are available in the current lexical scope (they could have been injected or passed in).
73
+ -
74
+ - function asyncGreet(name) {
75
+ - let deferred = $q.defer();
76
+ -
77
+ - setTimeout(function() {
78
+ - deferred.notify('About to greet ' + name + '.');
79
+ -
80
+ - if (okToGreet(name)) {
81
+ - deferred.resolve('Hello, ' + name + '!');
82
+ - } else {
83
+ - deferred.reject('Greeting ' + name + ' is not allowed.');
84
+ - }
85
+ - }, 1000);
86
+ -
87
+ - return deferred.promise;
88
+ - }
89
+ -
90
+ - let promise = asyncGreet('Robin Hood');
91
+ - promise.then(function(greeting) {
92
+ - alert('Success: ' + greeting);
93
+ - }, function(reason) {
94
+ - alert('Failed: ' + reason);
95
+ - }, function(update) {
96
+ - alert('Got notification: ' + update);
97
+ - });
98
+ - ```
99
+
100
+ ```
101
+
102
+ -
103
+ - At first it might not be obvious why this extra complexity is worth the trouble. The payoff
104
+ - comes in the way of guarantees that promise and deferred APIs make, see
105
+ - https://github.com/kriskowal/uncommonjs/blob/master/promises/specification.md.
106
+ -
107
+ - Additionally the promise api allows for composition that is very hard to do with the
108
+ - traditional callback ([CPS](http://en.wikipedia.org/wiki/Continuation-passing_style)) approach.
109
+ - For more on this please see the [Q documentation](https://github.com/kriskowal/q) especially the
110
+ - section on serial or parallel joining of promises.
111
+ -
112
+ - ## The Deferred API
113
+ -
114
+ - A new instance of deferred is constructed by calling `$q.defer()`.
115
+ -
116
+ - The purpose of the deferred object is to expose the associated Promise instance as well as APIs
117
+ - that can be used for signaling the successful or unsuccessful completion, as well as the status
118
+ - of the task.
119
+ -
120
+ - **Methods**
121
+ -
122
+ - - `resolve(value)` – resolves the derived promise with the `value`. If the value is a rejection
123
+ - constructed via `$q.reject`, the promise will be rejected instead.
124
+ - - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to
125
+ - resolving it with a rejection constructed via `$q.reject`.
126
+ - - `notify(value)` - provides updates on the status of the promise's execution. This may be called
127
+ - multiple times before the promise is either resolved or rejected.
128
+ -
129
+ - **Properties**
130
+ -
131
+ - - promise – `{Promise}` – promise object associated with this deferred.
132
+ -
133
+ -
134
+ - ## The Promise API
135
+ -
136
+ - A new promise instance is created when a deferred instance is created and can be retrieved by
137
+ - calling `deferred.promise`.
138
+ -
139
+ - The purpose of the promise object is to allow for interested parties to get access to the result
140
+ - of the deferred task when it completes.
141
+ -
142
+ - **Methods**
143
+ -
144
+ - - `then(successCallback, [errorCallback], [notifyCallback])` – regardless of when the promise was or
145
+ - will be resolved or rejected, `then` calls one of the success or error callbacks asynchronously
146
+ - as soon as the result is available. The callbacks are called with a single argument: the result
147
+ - or rejection reason. Additionally, the notify callback may be called zero or more times to
148
+ - provide a progress indication, before the promise is resolved or rejected.
149
+ -
150
+ - This method _returns a new promise_ which is resolved or rejected via the return value of the
151
+ - `successCallback`, `errorCallback` (unless that value is a promise, in which case it is resolved
152
+ - with the value which is resolved in that promise using
153
+ - [promise chaining](http://www.html5rocks.com/en/tutorials/es6/promises/#toc-promises-queues)).
154
+ - It also notifies via the return value of the `notifyCallback` method. The promise cannot be
155
+ - resolved or rejected from the notifyCallback method. The errorCallback and notifyCallback
156
+ - arguments are optional.
157
+ -
158
+ - - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
159
+ -
160
+ - - `finally(callback, notifyCallback)` – allows you to observe either the fulfillment or rejection of a promise,
161
+ - but to do so without modifying the final value. This is useful to release resources or do some
162
+ - clean-up that needs to be done whether the promise was rejected or resolved. See the [full
163
+ - specification](https://github.com/kriskowal/q/wiki/API-Reference#promisefinallycallback) for
164
+ - more information.
165
+ -
166
+ - ## Chaining promises
167
+ -
168
+ - Because calling the `then` method of a promise returns a new derived promise, it is easily
169
+ - possible to create a chain of promises:
170
+ -
171
+ - ```js
172
+
173
+ ```
174
+
175
+ - promiseB = promiseA.then(function(result) {
176
+ - return result + 1;
177
+ - });
178
+ -
179
+ - // promiseB will be resolved immediately after promiseA is resolved and its value
180
+ - // will be the result of promiseA incremented by 1
181
+ - ```
182
+
183
+ ```
184
+
185
+ -
186
+ - It is possible to create chains of any length and since a promise can be resolved with another
187
+ - promise (which will defer its resolution further), it is possible to pause/defer resolution of
188
+ - the promises at any point in the chain. This makes it possible to implement powerful APIs like
189
+ - $http's response interceptors.
190
+ -
191
+ -
192
+ - ## Differences between Kris Kowal's Q and $q
193
+ -
194
+ - There are two main differences:
195
+ -
196
+ - - $q is integrated with the {@link ng.$rootScope.Scope} Scope model observation
197
+ - mechanism in AngularJS, which means faster propagation of resolution or rejection into your
198
+ - models and avoiding unnecessary browser repaints, which would result in flickering UI.
199
+ - - Q has many more features than $q, but that comes at a cost of bytes. $q is tiny, but contains
200
+ - all the important functionality needed for common async tasks.
201
+ -
202
+ - ## Testing
203
+ -
204
+ - ```js
205
+
206
+ ```
207
+
208
+ - it('should simulate promise', inject(function($q, $rootScope) {
209
+ - let deferred = $q.defer();
210
+ - let promise = deferred.promise;
211
+ - let resolvedValue;
212
+ -
213
+ - promise.then(function(value) { resolvedValue = value; });
214
+ - expect(resolvedValue).toBeUndefined();
215
+ -
216
+ - // Simulate resolving of promise
217
+ - deferred.resolve(123);
218
+ - // Note that the 'then' function does not get called synchronously.
219
+ - // This is because we want the promise API to always be async, whether or not
220
+ - // it got called synchronously or asynchronously.
221
+ - expect(resolvedValue).toBeUndefined();
222
+ -
223
+ - // Propagate promise resolution to 'then' functions using $apply().
224
+ - $rootScope.$apply();
225
+ - expect(resolvedValue).toEqual(123);
226
+ - }));
227
+ - ```
228
+ */
229
+ ```
@@ -28,7 +28,7 @@ export function SanitizeUriProvider() {
28
28
  * to the DOM it is inactive and potentially malicious code will not be executed.
29
29
  *
30
30
  * @param {RegExp=} regexp New regexp to trust urls with.
31
- * @returns {RegExp|ng.ICompileProvider} Current RegExp if called without value or self for
31
+ * @returns {RegExp|SanitizeUriProvider} Current RegExp if called without value or self for
32
32
  * chaining otherwise.
33
33
  */
34
34
  this.aHrefSanitizationTrustedUrlList = function (regexp) {
@@ -58,8 +58,7 @@ export function SanitizeUriProvider() {
58
58
  * to the DOM it is inactive and potentially malicious code will not be executed.
59
59
  *
60
60
  * @param {RegExp=} regexp New regexp to trust urls with.
61
- * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
62
- * chaining otherwise.
61
+ * @returns {RegExp|SanitizeUriProvider} Current RegExp if called without value or self for chaining otherwise.
63
62
  */
64
63
  this.imgSrcSanitizationTrustedUrlList = function (regexp) {
65
64
  if (isDefined(regexp)) {