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

Commit e31104f

Browse files
matskomhevery
authored andcommitted
fix($animate): make animation onComplete callbacks async
1 parent 15389b0 commit e31104f

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

src/ngAnimate/animate.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ angular.module('ngAnimate', ['ng'])
203203
var NG_ANIMATE_STATE = '$$ngAnimateState';
204204
var rootAnimateState = {running:true};
205205

206-
$provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement',
207-
function($delegate, $injector, $sniffer, $rootElement) {
206+
$provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement', '$timeout',
207+
function($delegate, $injector, $sniffer, $rootElement, $timeout) {
208208

209209
var noop = angular.noop;
210210
var forEach = angular.forEach;
@@ -463,7 +463,8 @@ angular.module('ngAnimate', ['ng'])
463463
if ((parent.inheritedData(NG_ANIMATE_STATE) || disabledAnimation).running) {
464464
//avoid calling done() since there is no need to remove any
465465
//data or className values since this happens earlier than that
466-
(onComplete || noop)();
466+
//and also use a timeout so that it won't be asynchronous
467+
$timeout(onComplete || noop, 0, false);
467468
return;
468469
}
469470

test/ngAnimate/animateSpec.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ describe("ngAnimate", function() {
3232

3333
describe("enable / disable", function() {
3434

35-
beforeEach(function() {
36-
module(function($animateProvider, $provide) {
37-
$provide.value('$window', angular.mock.createMockWindow());
38-
});
39-
});
40-
4135
it("should disable and enable the animations", function() {
4236
var $animate, initialState = null;
4337

@@ -259,8 +253,8 @@ describe("ngAnimate", function() {
259253

260254
$animate.removeClass(element, 'ng-hide');
261255
if($sniffer.transitions) {
262-
$timeout.flushNext(1);
263256
$timeout.flushNext(0);
257+
$timeout.flushNext(1);
264258
}
265259
$timeout.flushNext(0);
266260
expect(element.text()).toBe('memento');
@@ -510,7 +504,7 @@ describe("ngAnimate", function() {
510504
}));
511505

512506
it("should skip animations if disabled and run when enabled",
513-
inject(function($animate, $rootScope, $compile, $sniffer) {
507+
inject(function($animate, $rootScope, $compile, $sniffer, $timeout) {
514508
$animate.enabled(false);
515509
var style = 'animation: some_animation 2s linear 0s 1 alternate;' +
516510
vendorPrefix + 'animation: some_animation 2s linear 0s 1 alternate;'
@@ -519,6 +513,7 @@ describe("ngAnimate", function() {
519513
element.addClass('ng-hide');
520514
expect(element).toBeHidden();
521515
$animate.removeClass(element, 'ng-hide');
516+
$timeout.flush();
522517
expect(element).toBeShown();
523518
}));
524519

@@ -563,9 +558,9 @@ describe("ngAnimate", function() {
563558
element.addClass('ng-hide');
564559
expect(element).toBeHidden();
565560
$animate.removeClass(element, 'ng-hide');
566-
expect(element).toBeShown();
567-
568561
$timeout.flushNext(0);
562+
$timeout.flushNext(0);
563+
expect(element).toBeShown();
569564

570565
$animate.enabled(true);
571566

@@ -591,6 +586,7 @@ describe("ngAnimate", function() {
591586
$timeout.flushNext(1);
592587
$timeout.flushNext(2000);
593588
}
589+
$timeout.flush();
594590
expect(element).toBeShown();
595591
}));
596592

@@ -604,10 +600,10 @@ describe("ngAnimate", function() {
604600

605601
element.addClass('ng-hide');
606602
$animate.removeClass(element, 'ng-hide');
603+
$timeout.flushNext(0);
604+
$timeout.flushNext(0);
607605
expect(element).toBeShown();
608606

609-
$timeout.flushNext(0); //callback which is called
610-
611607
$animate.enabled(true);
612608

613609
element.addClass('ng-hide');
@@ -618,7 +614,7 @@ describe("ngAnimate", function() {
618614
$timeout.flushNext(1);
619615
$timeout.flushNext(3000);
620616
}
621-
$timeout.flushNext(0);
617+
$timeout.flush();
622618
expect(element).toBeShown();
623619
}));
624620

test/ngRoute/directive/ngViewSpec.js

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('ngView', function() {
66
beforeEach(module('ngRoute'));
77

88
beforeEach(module(function($provide) {
9-
$provide.value('$window', angular.mock.createMockWindow());
109
return function($rootScope, $compile, $animate) {
1110
element = $compile('<div><ng:view onload="load()"></ng:view></div>')($rootScope);
1211
};
@@ -539,7 +538,6 @@ describe('ngView animations', function() {
539538

540539

541540
beforeEach(module(function($provide, $routeProvider) {
542-
$provide.value('$window', angular.mock.createMockWindow());
543541
$routeProvider.when('/foo', {controller: noop, templateUrl: '/foo.html'});
544542
$routeProvider.when('/bar', {controller: noop, templateUrl: '/bar.html'});
545543
return function($templateCache) {
@@ -611,7 +609,6 @@ describe('ngView animations', function() {
611609

612610
var window;
613611
module(function($routeProvider, $animateProvider, $provide) {
614-
$provide.value('$window', window = angular.mock.createMockWindow());
615612
$routeProvider.when('/foo', {template: '<div ng-repeat="i in [1,2]">{{i}}</div>'});
616613
$routeProvider.when('/bar', {template: '<div ng-repeat="i in [3,4]">{{i}}</div>'});
617614
$animateProvider.register('.my-animation', function() {

0 commit comments

Comments
 (0)