From b1e604e38ceec1714174fb54cc91590a7fe99a92 Mon Sep 17 00:00:00 2001 From: Matias Niemelä Date: Wed, 9 Oct 2013 01:12:03 -0400 Subject: fix($animate): perform internal caching on getComputedStyle to boost the performance of CSS3 transitions/animations Closes #4011 Closes #4124 --- test/ngAnimate/animateSpec.js | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 3652e450..cae25266 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -726,10 +726,10 @@ describe("ngAnimate", function() { it('should re-evaluate the CSS classes for an animation each time', inject(function($animate, $rootScope, $sniffer, $rootElement, $timeout, $compile) { - ss.addRule('.abc', '-webkit-transition:22s linear all;' + - 'transition:22s linear all;'); - ss.addRule('.xyz', '-webkit-transition:11s linear all;' + - 'transition:11s linear all;'); + ss.addRule('.abc.ng-enter', '-webkit-transition:22s linear all;' + + 'transition:22s linear all;'); + ss.addRule('.xyz.ng-enter', '-webkit-transition:11s linear all;' + + 'transition:11s linear all;'); var parent = $compile('
')($rootScope); var element = parent.find('span'); @@ -1875,4 +1875,49 @@ describe("ngAnimate", function() { expect(intercepted).toBe(true); }); }); + + it("should cache the response from getComputedStyle if each successive element has the same className value and parent until the first reflow hits", function() { + var count = 0; + module(function($provide) { + $provide.value('$window', { + document : jqLite(window.document), + getComputedStyle: function(element) { + count++; + return window.getComputedStyle(element); + } + }); + }); + + inject(function($animate, $rootScope, $compile, $rootElement, $timeout, $document, $sniffer) { + if(!$sniffer.transitions) return; + + $animate.enabled(true); + + var element = $compile('
')($rootScope); + $rootElement.append(element); + jqLite($document[0].body).append($rootElement); + + for(var i=0;i<20;i++) { + var kid = $compile('
')($rootScope); + $animate.enter(kid, element); + } + $rootScope.$digest(); + $timeout.flush(); + + expect(count).toBe(2); + + dealoc(element); + count = 0; + + for(var i=0;i<20;i++) { + var kid = $compile('
')($rootScope); + $animate.enter(kid, element); + } + + $rootScope.$digest(); + $timeout.flush(); + + expect(count).toBe(40); + }); + }); }); -- cgit v1.2.3