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

Commit

Permalink
fix(ngAnimate): cut down on extra $timeout calls
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko authored and mhevery committed Sep 4, 2013
1 parent d11a34a commit 4382df0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 169 deletions.
8 changes: 4 additions & 4 deletions src/ng/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var $AnimateProvider = ['$provide', function($provide) {
forEach(element, function(node) {
parentNode.insertBefore(node, afterNextSibling);
});
$timeout(done || noop, 0, false);
done && $timeout(done, 0, false);
},

/**
Expand All @@ -115,7 +115,7 @@ var $AnimateProvider = ['$provide', function($provide) {
*/
leave : function(element, done) {
element.remove();
$timeout(done || noop, 0, false);
done && $timeout(done, 0, false);
},

/**
Expand Down Expand Up @@ -157,7 +157,7 @@ var $AnimateProvider = ['$provide', function($provide) {
className :
isArray(className) ? className.join(' ') : '';
element.addClass(className);
$timeout(done || noop, 0, false);
done && $timeout(done, 0, false);
},

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

enabled : noop
Expand Down
13 changes: 7 additions & 6 deletions src/ngAnimate/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ angular.module('ngAnimate', ['ng'])
enter : function(element, parent, after, done) {
$delegate.enter(element, parent, after);
performAnimation('enter', 'ng-enter', element, parent, after, function() {
$timeout(done || noop, 0, false);
done && $timeout(done, 0, false);
});
},

Expand Down Expand Up @@ -353,7 +353,7 @@ angular.module('ngAnimate', ['ng'])
move : function(element, parent, after, done) {
$delegate.move(element, parent, after);
performAnimation('move', 'ng-move', element, null, null, function() {
$timeout(done || noop, 0, false);
done && $timeout(done, 0, false);
});
},

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

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

$timeout(done, duration * 1000, false);

//this will automatically be called by $animate so
//there is no need to attach this internally to the
Expand Down
6 changes: 2 additions & 4 deletions test/ng/directive/ngClassSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,29 +321,27 @@ describe('ngClass animations', function() {
expect($animate.queue.length).toBe(0);

$rootScope.val = 'one';
$timeout.flush();

$rootScope.$digest();
$animate.flushNext('addClass');
$animate.flushNext('addClass');
$timeout.flush();
expect($animate.queue.length).toBe(0);

$rootScope.val = '';
$rootScope.$digest();
$animate.flushNext('removeClass'); //only removeClass is called
expect($animate.queue.length).toBe(0);
$timeout.flush();

$rootScope.val = 'one';
$rootScope.$digest();
$animate.flushNext('addClass');
$timeout.flush();
expect($animate.queue.length).toBe(0);

$rootScope.val = 'two';
$rootScope.$digest();
$animate.flushNext('removeClass');
$animate.flushNext('addClass');
$timeout.flush();
expect($animate.queue.length).toBe(0);
}));
});
Loading

0 comments on commit 4382df0

Please sign in to comment.