8000 Fixes for ngAnimate in 1.3 by matsko · Pull Request #12603 · angular/angular.js · GitHub
[go: up one dir, main page]

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

Fixes for ngAnimate in 1.3 #12603

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix($animate): clear class animations cache if animation is not started
Closes #12604
Closes #12603
  • Loading branch information
matsko committed Aug 17, 2015
commit 64b3a142f72284e852b9d3ab7b57ae16275c8f68
9 changes: 5 additions & 4 deletions src/ngAnimate/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,12 @@ angular.module('ngAnimate', ['ng'])
}

return cache.promise = runAnimationPostDigest(function(done) {
var parentNode, parentElement, elementNode = extractElementNode(element);
var cache, parentNode, parentElement, elementNode = extractElementNode(element);
var DOM_FRAGMENT = 11;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like DOM_FRAGMENT is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get removed when it was merged to master: 2c03a35

if (elementNode) {
cache = element.data(STORAGE_KEY);
element.removeData(STORAGE_KEY);

parentElement = element.parent();
parentNode = elementNode.parentNode;
}
Expand All @@ -1206,9 +1210,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
40 changes: 39 additions & 1 deletion test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,44 @@ 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 Expand Up @@ -4559,8 +4597,8 @@ describe("ngAnimate", function() {
});
});
inject(function($compile, $rootScope, $animate, $sniffer, $rootElement) {

$rootElement.addClass('animated');

$animate.addClass($rootElement, 'green');
$rootScope.$digest();
$animate.triggerReflow();
Expand Down
0