MCPcopy
hub / github.com/angular-ui/ui-router / $$IntervalFactoryProvider

Function $$IntervalFactoryProvider

test/angular/1.7/angular.js:14235–14279  ·  view source on GitHub ↗

@this

()

Source from the content-addressed store, hash-verified

14233
14234/** @this */
14235function $$IntervalFactoryProvider() {
14236 this.$get = ['$browser', '$q', '$$q', '$rootScope',
14237 function($browser, $q, $$q, $rootScope) {
14238 return function intervalFactory(setIntervalFn, clearIntervalFn) {
14239 return function intervalFn(fn, delay, count, invokeApply) {
14240 var hasParams = arguments.length > 4,
14241 args = hasParams ? sliceArgs(arguments, 4) : [],
14242 iteration = 0,
14243 skipApply = isDefined(invokeApply) && !invokeApply,
14244 deferred = (skipApply ? $$q : $q).defer(),
14245 promise = deferred.promise;
14246
14247 count = isDefined(count) ? count : 0;
14248
14249 function callback() {
14250 if (!hasParams) {
14251 fn(iteration);
14252 } else {
14253 fn.apply(null, args);
14254 }
14255 }
14256
14257 function tick() {
14258 if (skipApply) {
14259 $browser.defer(callback);
14260 } else {
14261 $rootScope.$evalAsync(callback);
14262 }
14263 deferred.notify(iteration++);
14264
14265 if (count > 0 && iteration >= count) {
14266 deferred.resolve(iteration);
14267 clearIntervalFn(promise.$$intervalId);
14268 }
14269
14270 if (!skipApply) $rootScope.$apply();
14271 }
14272
14273 promise.$$intervalId = setIntervalFn(tick, delay, deferred, skipApply);
14274
14275 return promise;
14276 };
14277 };
14278 }];
14279}
14280
14281/**
14282 * @ngdoc service

Callers

nothing calls this directly

Calls 3

sliceArgsFunction · 0.70
isDefinedFunction · 0.70
setIntervalFnFunction · 0.70

Tested by

no test coverage detected