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

Commit

Permalink
fix($animate): clear class animations cache if animation is not started
Browse files Browse the repository at this point in the history
Closes #12604
Closes #12603
  • Loading branch information
matsko committed Aug 18, 2015
1 parent 6b72598 commit 2c03a35
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ngAnimate/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,11 @@ angular.module('ngAnimate', ['ng'])
}

return cache.promise = runAnimationPostDigest(function(done) {
var parentNode, parentElement, elementNode = extractElementNode(element);
var cache, parentNode, parentElement, elementNode = extractElementNode(element);
if (elementNode) {
cache = element.data(STORAGE_KEY);
element.removeData(STORAGE_KEY);

parentElement = element.parent();
parentNode = elementNode.parentNode;
}
Expand All @@ -1206,9 +1209,6 @@ angular.module('ngAnimate', ['ng'])
return;
}

var cache = element.data(STORAGE_KEY);
element.removeData(STORAGE_KEY);

var state = element.data(NG_ANIMATE_STATE) || {};
var classes = resolveElementClasses(element, cache, state.active);
return !classes
Expand Down
37 changes: 37 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,43 @@ describe("ngAnimate", function() {
});
});

it("should clear the setClass element animation cache before the next animation runs", function() {
var animateSpy = jasmine.createSpy();
module(function($animateProvider) {
$animateProvider.register('.track-me', function() {
return {
addClass: animateSpy,
removeClass: animateSpy,
setClass: animateSpy
};
});
});
inject(function($animate, $rootScope, $sniffer, $$rAF) {
var orphanChild = jqLite('<div class="track-me"></div>');
element.append(orphanChild);
orphanChild.remove();

var doneSpy = jasmine.createSpy();

$animate.setClass(orphanChild, 'red', 'blue').then(doneSpy);
$rootScope.$digest();
$animate.triggerCallbacks();

expect(doneSpy).toHaveBeenCalled();
expect(animateSpy).not.toHaveBeenCalled();

var specialChild = jqLite('<div class="track-me"></div>');
element.append(specialChild);

$animate.setClass(specialChild, 'blue', 'gold').then(doneSpy);
$rootScope.$digest();
$animate.triggerReflow();
$animate.triggerCallbacks();

expect(animateSpy).toHaveBeenCalled();
});
});

it("should exclusively animate the setClass animation event with native dom elements", function() {
var count = 0, fallback = jasmine.createSpy('callback');
module(function($animateProvider) {
Expand Down

0 comments on commit 2c03a35

Please sign in to comment.