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

Commit

Permalink
fix($animator): remove dependency on window.setTimeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Apr 23, 2013
1 parent de296f1 commit 021bdf3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
5 changes: 3 additions & 2 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -975,12 +975,13 @@ function bootstrap(element, modules) {
}]);
modules.unshift('ng');
var injector = createInjector(modules);
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
function(scope, element, compile, injector) {
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector', '$animator',
function(scope, element, compile, injector, animator) {
scope.$apply(function() {
element.data('$injector', injector);
compile(element)(scope);
});
animator.enabled(true);

This comment has been minimized.

Copy link
@damrbaby

damrbaby Jun 7, 2013

Contributor

When setting $animator.enabled(false) in a run block for an application that was bootstrapped with ng-app, animations will become enabled anyway due to this line of code.

This comment has been minimized.

Copy link
@damrbaby

damrbaby Jun 7, 2013

Contributor

Workaround would be to wrap $animator.enabled(false) in a setTimeout function with a run block.

setTimeout -> $animator.enabled false
}]
);
return injector;
Expand Down
8 changes: 0 additions & 8 deletions src/ng/animator.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ var $AnimatorProvider = function() {
this.$get = ['$animation', '$window', '$sniffer', '$rootElement', '$rootScope',
function($animation, $window, $sniffer, $rootElement, $rootScope) {
$rootElement.data(NG_ANIMATE_CONTROLLER, rootAnimateController);
var unregister = $rootScope.$watch(function() {
unregister();
if (rootAnimateController.running) {
$window.setTimeout(function() {
rootAnimateController.running = false;
}, 0);
}
});

/**
* @ngdoc function
Expand Down
33 changes: 17 additions & 16 deletions test/ng/animatorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,27 @@ describe("$animator", function() {
});
});

it("should disable and enable the animations", inject(function($animator, $rootScope, $window) {
expect($animator.enabled()).toBe(false);
it("should disable and enable the animations", function() {
var initialState = null;
var animator;

$rootScope.$digest();
$window.setTimeout.expect(0).process();
angular.bootstrap(body, [function() {
return function($animator) {
animator = $animator;
initialState = $animator.enabled();
}
}]);

expect($animator.enabled()).toBe(true);
expect(initialState).toBe(false);

expect($animator.enabled(0)).toBe(false);
expect($animator.enabled()).toBe(false);
expect(animator.enabled()).toBe(true);

expect($animator.enabled(1)).toBe(true);
expect($animator.enabled()).toBe(true);
}));
expect(animator.enabled(0)).toBe(false);
expect(animator.enabled()).toBe(false);

expect(animator.enabled(1)).toBe(true);
expect(animator.enabled()).toBe(true);
});

});

Expand Down Expand Up @@ -145,9 +152,6 @@ describe("$animator", function() {
ngAnimate : '{enter: \'custom\'}'
});

$rootScope.$digest(); // re-enable the animations;
window.setTimeout.expect(0).process();

expect(element.contents().length).toBe(0);
animator.enter(child, element);
window.setTimeout.expect(1).process();
Expand All @@ -158,9 +162,6 @@ describe("$animator", function() {
ngAnimate : '{leave: \'custom\'}'
});

$rootScope.$digest(); // re-enable the animations;
window.setTimeout.expect(0).process();

element.append(child);
expect(element.contents().length).toBe(1);
animator.leave(child, element);
Expand Down

0 comments on commit 021bdf3

Please sign in to comment.