Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ab45757

Browse files
committed
refactor($interval): do not use notify to trigger the callback
Do not use `$q.notify` to trigger the callback. This allows `$q` to be replaced with another Promise/A+ compilant library
1 parent 39ebb06 commit ab45757

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/ng/interval.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
function $IntervalProvider() {
5-
this.$get = ['$rootScope', '$window', '$q', '$$q',
6-
function($rootScope, $window, $q, $$q) {
5+
this.$get = ['$rootScope', '$window', '$q', '$$q', '$browser',
6+
function($rootScope, $window, $q, $$q, $browser) {
77
var intervals = {};
88

99

@@ -144,11 +144,14 @@ function $IntervalProvider() {
144144

145145
count = isDefined(count) ? count : 0;
146146

147-
promise.then(null, null, (!hasParams) ? fn : function() {
148-
fn.apply(null, args);
149-
});
150-
151147
promise.$$intervalId = setInterval(function tick() {
148+
if (intervals[promise.$$intervalId]) {
149+
if (skipApply) {
150+
$browser.defer(callback);
151+
} else {
152+
$rootScope.$evalAsync(callback);
153+
}
154+
}
152155
deferred.notify(iteration++);
153156

154157
if (count > 0 && iteration >= count) {
@@ -164,6 +167,14 @@ function $IntervalProvider() {
164167
intervals[promise.$$intervalId] = deferred;
165168

166169
return promise;
170+
171+
function callback() {
172+
if (!hasParams) {
173+
fn(iteration);
174+
} else {
175+
fn.apply(null, args);
176+
}
177+
}
167178
}
168179

169180

0 commit comments

Comments
 (0)