Skip to content

Commit 0db7603

Browse files
bvangennepRoopeHakulinen
authored andcommitted
Replace $timeout with $interval (#47)
1 parent 0e19789 commit 0db7603

File tree

7 files changed

+20
-20
lines changed

7 files changed

+20
-20
lines changed

demo/javascripts/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ $.fn.putCursorAtEnd = function () {
3232

3333
// Demo controller
3434
var app = angular.module('demoApp', ['ngFlash', 'ngAnimate']);
35-
app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$timeout', function ($rootScope, $scope, Flash, $timeout) {
35+
app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$interval', function ($rootScope, $scope, Flash, $interval) {
3636
$scope.success = function () {
3737
var message = '<strong>Well done!</strong> You successfully read this important alert message.';
3838
Flash.create('success', message);
@@ -138,10 +138,10 @@ app.controller('FlashDemoCtrl', ['$rootScope', '$scope', 'Flash', '$timeout', fu
138138
$('#newList').on('keypress', function (e) {
139139
if ($(this).val() !== '') {
140140
if (e.which == 13) {
141-
$timeout(function () {
141+
$interval(function () {
142142
$scope.add();
143143
return false;
144-
}, 100);
144+
}, 100, 1);
145145
}
146146
}
147147
});

dist/angular-flash.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-flash.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-flash.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-flash.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-flash.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ app.provider('Flash', function() {
132132
this.setShowClose(true);
133133
this.setTemplatePreset('bootstrap');
134134

135-
this.$get = ['$rootScope', '$timeout', function($rootScope, $timeout) {
135+
this.$get = ['$rootScope', '$interval', function($rootScope, $interval) {
136136
const dataFactory = {};
137137
let counter = 0;
138138

@@ -162,15 +162,15 @@ app.provider('Flash', function() {
162162
}
163163
$rootScope.flashes.push(flash);
164164
if (flash.timeout) {
165-
flash.timeoutObj = $timeout(function() {
165+
flash.timeoutObj = $interval(function() {
166166
$this.dismiss(flash.id);
167-
}, flash.timeout);
167+
}, flash.timeout, 1);
168168
}
169169
return flash.id;
170170
};
171171
dataFactory.pause = function(index) {
172172
if ($rootScope.flashes[index].timeoutObj) {
173-
$timeout.cancel($rootScope.flashes[index].timeoutObj);
173+
$interval.cancel($rootScope.flashes[index].timeoutObj);
174174
}
175175
};
176176
dataFactory.dismiss = function(id) {

test/angular-flash_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('Unit testing Angular Flash', function() {
22
var $compile,
33
$rootScope,
4-
$timeout,
4+
$interval,
55
node,
66
Flash;
77

@@ -10,11 +10,11 @@ describe('Unit testing Angular Flash', function() {
1010

1111
// Store references to $rootScope and $compile
1212
// so they are available to all tests in this describe block
13-
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, _Flash_) {
13+
beforeEach(inject(function(_$compile_, _$rootScope_, _$interval_, _Flash_) {
1414
// The injector unwraps the underscores (_) from around the parameter names when matching
1515
$compile = _$compile_;
1616
$rootScope = _$rootScope_;
17-
$timeout = _$timeout_;
17+
$interval = _$interval_;
1818
Flash = _Flash_;
1919
}));
2020

@@ -79,7 +79,7 @@ describe('Unit testing Angular Flash', function() {
7979
var contents = node.contents()[0];
8080
expect(contents.querySelectorAll('.alert').length).toEqual(1);
8181

82-
$timeout.flush();
82+
$interval.flush();
8383
$rootScope.$digest();
8484
expect(contents.querySelectorAll('.alert').length).toEqual(0);
8585
});

0 commit comments

Comments
 (0)