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

Commit 4382df0

Browse files
matskomhevery
authored andcommitted
fix(ngAnimate): cut down on extra $timeout calls
1 parent d11a34a commit 4382df0

File tree

5 files changed

+38
-169
lines changed

5 files changed

+38
-169
lines changed

src/ng/animate.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ var $AnimateProvider = ['$provide', function($provide) {
9898
forEach(element, function(node) {
9999
parentNode.insertBefore(node, afterNextSibling);
100100
});
101-
$timeout(done || noop, 0, false);
101+
done && $timeout(done, 0, false);
102102
},
103103

104104
/**
@@ -115,7 +115,7 @@ var $AnimateProvider = ['$provide', function($provide) {
115115
*/
116116
leave : function(element, done) {
117117
element.remove();
118-
$timeout(done || noop, 0, false);
118+
done && $timeout(done, 0, false);
119119
},
120120

121121
/**
@@ -157,7 +157,7 @@ var $AnimateProvider = ['$provide', function($provide) {
157157
className :
158158
isArray(className) ? className.join(' ') : '';
159159
element.addClass(className);
160-
$timeout(done || noop, 0, false);
160+
done && $timeout(done, 0, false);
161161
},
162162

163163
/**
@@ -178,7 +178,7 @@ var $AnimateProvider = ['$provide', function($provide) {
178178
className :
179179
isArray(className) ? className.join(' ') : '';
180180
element.removeClass(className);
181-
$timeout(done || noop, 0, false);
181+
done && $timeout(done, 0, false);
182182
},
183183

184184
enabled : noop

src/ngAnimate/animate.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ angular.module('ngAnimate', ['ng'])
283283
enter : function(element, parent, after, done) {
284284
$delegate.enter(element, parent, after);
285285
performAnimation('enter', 'ng-enter', element, parent, after, function() {
286-
$timeout(done || noop, 0, false);
286+
done && $timeout(done, 0, false);
287287
});
288288
},
289289

@@ -353,7 +353,7 @@ angular.module('ngAnimate', ['ng'])
353353
move : function(element, parent, after, done) {
354354
$delegate.move(element, parent, after);
355355
performAnimation('move', 'ng-move', element, null, null, function() {
356-
$timeout(done || noop, 0, false);
356+
done && $timeout(done, 0, false);
357357
});
358358
},
359359

@@ -615,10 +615,11 @@ angular.module('ngAnimate', ['ng'])
615615
activeClassName += (i > 0 ? ' ' : '') + klass + '-active';
616616
});
617617

618-
$timeout(function() {
619-
element.addClass(activeClassName);
620-
$timeout(done, duration * 1000, false);
621-
},0,false);
618+
//this triggers a reflow which allows for the transition animation to kick in
619+
element.prop('clientWidth');
620+
element.addClass(activeClassName);
621+
622+
$timeout(done, duration * 1000, false);
622623

623624
//this will automatically be called by $animate so
624625
//there is no need to attach this internally to the

test/ng/directive/ngClassSpec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -321,29 +321,27 @@ describe('ngClass animations', function() {
321321
expect($animate.queue.length).toBe(0);
322322

323323
$rootScope.val = 'one';
324+
$timeout.flush();
325+
324326
$rootScope.$digest();
325327
$animate.flushNext('addClass');
326328
$animate.flushNext('addClass');
327-
$timeout.flush();
328329
expect($animate.queue.length).toBe(0);
329330

330331
$rootScope.val = '';
331332
$rootScope.$digest();
332333
$animate.flushNext('removeClass'); //only removeClass is called
333334
expect($animate.queue.length).toBe(0);
334-
$timeout.flush();
335335

336336
$rootScope.val = 'one';
337337
$rootScope.$digest();
338338
$animate.flushNext('addClass');
339-
$timeout.flush();
340339
expect($animate.queue.length).toBe(0);
341340

342341
$rootScope.val = 'two';
343342
$rootScope.$digest();
344343
$animate.flushNext('removeClass');
345344
$animate.flushNext('addClass');
346-
$timeout.flush();
347345
expect($animate.queue.length).toBe(0);
348346
}));
349347
});

0 commit comments

Comments
 (0)