MCPcopy Index your code
hub / github.com/angular-ui/ui-router / qFactory

Function qFactory

test/angular/1.5/angular.js:16625–16987  ·  view source on GitHub ↗

* Constructs a promise manager. * * @param {function(function)} nextTick Function for executing functions in the next turn. * @param {function(...*)} exceptionHandler Function into which unexpected exceptions are passed for * debugging purposes. * @returns {object} Promise manager.

(nextTick, exceptionHandler)

Source from the content-addressed store, hash-verified

16623 * @returns {object} Promise manager.
16624 */
16625function qFactory(nextTick, exceptionHandler) {
16626 var $qMinErr = minErr('$q', TypeError);
16627
16628 /**
16629 * @ngdoc method
16630 * @name ng.$q#defer
16631 * @kind function
16632 *
16633 * @description
16634 * Creates a `Deferred` object which represents a task which will finish in the future.
16635 *
16636 * @returns {Deferred} Returns a new instance of deferred.
16637 */
16638 function defer() {
16639 var d = new Deferred();
16640 //Necessary to support unbound execution :/
16641 d.resolve = simpleBind(d, d.resolve);
16642 d.reject = simpleBind(d, d.reject);
16643 d.notify = simpleBind(d, d.notify);
16644 return d;
16645 }
16646
16647 function Promise() {
16648 this.$$state = { status: 0 };
16649 }
16650
16651 extend(Promise.prototype, {
16652 then: function(onFulfilled, onRejected, progressBack) {
16653 if (isUndefined(onFulfilled) && isUndefined(onRejected) && isUndefined(progressBack)) {
16654 return this;
16655 }
16656 var result = new Deferred();
16657
16658 this.$$state.pending = this.$$state.pending || [];
16659 this.$$state.pending.push([result, onFulfilled, onRejected, progressBack]);
16660 if (this.$$state.status > 0) scheduleProcessQueue(this.$$state);
16661
16662 return result.promise;
16663 },
16664
16665 'catch': function(callback) {
16666 return this.then(null, callback);
16667 },
16668
16669 'finally': function(callback, progressBack) {
16670 return this.then(function(value) {
16671 return handleCallback(value, resolve, callback);
16672 }, function(error) {
16673 return handleCallback(error, reject, callback);
16674 }, progressBack);
16675 }
16676 });
16677
16678 //Faster, more basic than angular.bind http://jsperf.com/angular-bind-vs-custom-vs-native
16679 function simpleBind(context, fn) {
16680 return function(value) {
16681 fn.call(context, value);
16682 };

Callers 2

$QProviderFunction · 0.70
$$QProviderFunction · 0.70

Calls 11

minErrFunction · 0.70
extendFunction · 0.70
isUndefinedFunction · 0.70
scheduleProcessQueueFunction · 0.70
handleCallbackFunction · 0.70
isObjectFunction · 0.70
isFunctionFunction · 0.70
simpleBindFunction · 0.70
rejectPromiseFunction · 0.70
nextTickFunction · 0.70
callbackFunction · 0.70

Tested by

no test coverage detected