All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.angular-promise-tracker.promise-tracker.min.js Maven / Gradle / Ivy

There is a newer version: 0.9.6
Show newest version
/*
 * promise-tracker - v1.5.0 - 2014-01-02
 * http://github.com/ajoslin/angular-promise-tracker
 * Created by Andy Joslin; Licensed under Public Domain
 */

(function() {
function TrackerResponseInterceptor(a,b,c){var d;return function(a){d||(d=c.get("$http"));var e=d.pendingRequests[d.pendingRequests.length-1];return e.tracker&&(angular.isArray(e.tracker)||(e.tracker=[e.tracker]),angular.forEach(e.tracker,function(c){b(c).addPromise(a,e)})),a}}function TrackerHttpInterceptor(a,b){return{request:function(c){return c.tracker&&(angular.isArray(c.tracker)||(c.tracker=[c.tracker]),c.$promiseTrackerDeferred=c.$promiseTrackerDeferred||[],angular.forEach(c.tracker,function(a){var d=b(a).createPromise(c);c.$promiseTrackerDeferred.push(d)})),a.when(c)},response:function(b){return b.config&&b.config.$promiseTrackerDeferred&&angular.forEach(b.config.$promiseTrackerDeferred,function(a){a.resolve(b)}),a.when(b)},responseError:function(b){return b.config&&b.config.$promiseTrackerDeferred&&angular.forEach(b.config.$promiseTrackerDeferred,function(a){a.reject(b)}),a.reject(b)}}}angular.module("ajoslin.promise-tracker",[]),angular.module("ajoslin.promise-tracker").config(["$httpProvider",function(a){a.interceptors?a.interceptors.push(TrackerHttpInterceptor):a.responseInterceptors.push(TrackerResponseInterceptor)}]),TrackerResponseInterceptor.$inject=["$q","promiseTracker","$injector"],TrackerHttpInterceptor.$inject=["$q","promiseTracker"],angular.module("ajoslin.promise-tracker").provider("promiseTracker",function(){function a(){for(var a,c=b.length;c;){if(c--,a=b[c].charCodeAt(0),57===a)return b[c]="A",b.join("");if(90!==a)return b[c]=String.fromCharCode(a+1),b.join("");b[c]="0"}return b.unshift("0"),b.join("")}var b=["0","0","0"],c={};this.$get=["$q","$timeout",function(b,d){function e(c){function e(a){angular.forEach(h[a.event],function(b){b.call(g,a.value,a.id)})}function f(c){function f(){g._minDuration&&(g._minPromise=d(angular.noop,g._minDuration)),g._maxDuration&&(g._maxPromise=d(j.resolve,g._maxDuration))}function h(a){return function(c){(g._minPromise||b.when()).then(function(){var b=i.indexOf(j);i.splice(b,1),0===i.length&&(g._maxPromise&&(d.cancel(g._maxPromise),g._maxPromise=null),g._delayPromise&&(d.cancel(g._delayPromise),g._delayPromise=null)),e({event:a?"error":"success",id:k,value:c}),e({event:"done",id:k,value:c})})}}var j=b.defer(),k=a();return i.push(j),1===i.length&&(g._activationDelay?g._delayPromise=d(function(){g._delayPromise=null,f()},g._activationDelay):f()),e({event:"start",id:k,value:c}),j.promise.then(h(!1),h(!0)),j}var g=this,h={start:[],done:[],error:[],success:[]},i=[];c=c||{},g.setMinDuration=function(a){g._minDuration=a},g.setMinDuration(c.minDuration),g.setMaxDuration=function(a){g._maxDuration=a},g.setMaxDuration(c.maxDuration),g.setActivationDelay=function(a){g._activationDelay=a},g.setActivationDelay(c.activationDelay),g.active=function(){return g._delayPromise?!1:i.length>0},g.cancel=function(){angular.forEach(i,function(a){a.resolve()})},g.addPromise=function(a,c){var d=a&&(a.then||a.$then||a.$promise&&a.$promise.then);if(!d)throw new Error("promiseTracker#addPromise expects a promise object!");var e=f(c);return d(function(a){return e.resolve(a),a},function(a){return e.reject(a),b.reject(a)}),e},g.createPromise=f,g.on=g.bind=function(a,b){if(!h[a])throw new Error("Cannot bind callback for event '"+a+"'. Allowed types: 'start', 'done', 'error', 'success'");return h[a].push(b),g},g.off=g.unbind=function(a,b){if(!h[a])throw new Error("Cannot unbind callback for event '"+a+"'. Allowed types: 'start', 'done', 'error', 'success'");if(b){var c=h[a].indexOf(b);h[a].splice(c,1)}else h[a].length=0;return g}}return function(a,b){return c[a]||(c[a]=new e(b)),c[a]}}]});
}());




© 2015 - 2025 Weber Informatics LLC | Privacy Policy