forked from emmaguo/angular-poller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-poller.min.js
More file actions
2 lines (2 loc) · 2.08 KB
/
angular-poller.min.js
File metadata and controls
2 lines (2 loc) · 2.08 KB
1
2
/*! angular-poller v0.3.2 12-11-2014 */
!function(a,b,c){"use strict";b.module("emguo.poller",[]).constant("pollerConfig",{stopOnRouteChange:!1,stopOnStateChange:!1,resetOnRouteChange:!1,resetOnStateChange:!1,neverOverwrite:!1}).run(["$rootScope","poller","pollerConfig",function(a,b,c){c.stopOnRouteChange&&a.$on("$routeChangeStart",function(){b.stopAll()}),c.stopOnStateChange&&a.$on("$stateChangeStart",function(){b.stopAll()}),c.resetOnRouteChange&&a.$on("$routeChangeStart",function(){b.reset()}),c.resetOnStateChange&&a.$on("$stateChangeStart",function(){b.reset()})}]).factory("poller",["$interval","$q","$http","pollerConfig",function(a,d,e,f){var g=[],h={action:"get",argumentsArray:[],delay:5e3,smart:!1,catchError:!1},i=function(a,b){this.target=a,this.set(b)},j=function(a){var c=null;return f.neverOverwrite||b.forEach(g,function(d){b.equals(d.target,a)&&(c=d)}),c};return b.extend(i.prototype,{set:function(a){b.forEach(["action","argumentsArray","delay","smart","catchError"],function(b){a&&a[b]?this[b]=a[b]:this[b]||(this[b]=h[b])},this)},start:function(){function c(){l&&b.isDefined(f)&&!f.$resolved||(g=new Date,f=h[i].apply(n,j),f.$resolved=!1,(f.$promise||f).then(function(a){f.$resolved=!0,(b.isUndefined(n.stopTimestamp)||g>=n.stopTimestamp)&&n.deferred.notify(a)},function(a){f.$resolved=!0,m&&(b.isUndefined(n.stopTimestamp)||g>=n.stopTimestamp)&&n.deferred.notify(a)}))}var f,g,h=this.target,i=this.action,j=this.argumentsArray.slice(0),k=this.delay,l=this.smart,m=this.catchError,n=this;this.deferred=this.deferred||d.defer(),"string"==typeof h&&(j.unshift(h),h=e),c(),this.interval=a(c,k),this.promise=this.deferred.promise},stop:function(){b.isDefined(this.interval)&&(a.cancel(this.interval),this.interval=c,this.stopTimestamp=new Date)},restart:function(){this.stop(),this.start()}}),{get:function(a,b){var c=j(a);return c?(c.set(b),c.restart()):(c=new i(a,b),g.push(c),c.start()),c},size:function(){return g.length},stopAll:function(){b.forEach(g,function(a){a.stop()})},restartAll:function(){b.forEach(g,function(a){a.restart()})},reset:function(){this.stopAll(),g=[]}}}])}(window,window.angular);