|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +(function() { |
| 4 | + var app = angular.module('repeatAnimateBenchmark'); |
| 5 | + |
| 6 | + app.config(function($compileProvider, $animateProvider) { |
| 7 | + if ($compileProvider.debugInfoEnabled) { |
| 8 | + $compileProvider.debugInfoEnabled(false); |
| 9 | + } |
| 10 | + |
| 11 | + }); |
| 12 | + |
| 13 | + app.run(function($animate) { |
| 14 | + if ($animate.enabled) { |
| 15 | + $animate.enabled(true); |
| 16 | + } |
| 17 | + }); |
| 18 | + |
| 19 | + app.controller('DataController', function($scope, $rootScope, $animate) { |
| 20 | + var totalRows = 500; |
| 21 | + var totalColumns = 20; |
| 22 | + |
| 23 | + var data = $scope.data = []; |
| 24 | + |
| 25 | + function fillData() { |
| 26 | + if ($animate.enabled) { |
| 27 | + $animate.enabled($scope.benchmarkType !== 'globallyDisabled'); |
| 28 | + } |
| 29 | + |
| 30 | + for (var i = 0; i < totalRows; i++) { |
| 31 | + data[i] = []; |
| 32 | + for (var j = 0; j < totalColumns; j++) { |
| 33 | + data[i][j] = { |
| 34 | + i: i |
| 35 | + }; |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + benchmarkSteps.push({ |
| 41 | + name: 'enter', |
| 42 | + fn: function() { |
| 43 | + $scope.$apply(function() { |
| 44 | + fillData(); |
| 45 | + }); |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + benchmarkSteps.push({ |
| 50 | + name: 'leave', |
| 51 | + fn: function() { |
| 52 | + $scope.$apply(function() { |
| 53 | + data = $scope.data = []; |
| 54 | + }); |
| 55 | + } |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + app.directive('disableAnimations', function($animate) { |
| 60 | + return { |
| 61 | + link: { |
| 62 | + pre: function(s, e) { |
| 63 | + $animate.enabled(e, false); |
| 64 | + } |
| 65 | + } |
| 66 | + }; |
| 67 | + }); |
| 68 | + |
| 69 | + app.directive('noop', function($animate) { |
| 70 | + return { |
| 71 | + link: { |
| 72 | + pre: angular.noop |
| 73 | + } |
| 74 | + }; |
| 75 | + }); |
| 76 | + |
| 77 | + app.directive('baseline', function($document) { |
| 78 | + return { |
| 79 | + restrict: 'E', |
| 80 | + link: function($scope, $element) { |
| 81 | + var document = $document[0]; |
| 82 | + |
| 83 | + var i, j, row, cell, comment; |
| 84 | + var template = document.createElement('span'); |
| 85 | + template.setAttribute('ng-repeat', 'foo in foos'); |
| 86 | + template.classList.add('ng-scope'); |
| 87 | + template.appendChild(document.createElement('span')); |
| 88 | + template.appendChild(document.createTextNode(':')); |
| 89 | + |
| 90 | + function createList() { |
| 91 | + for (i = 0; i < $scope.data.length; i++) { |
| 92 | + row = document.createElement('div'); |
| 93 | + $element[0].appendChild(row); |
| 94 | + for (j = 0; j < $scope.data[i].length; j++) { |
| 95 | + cell = template.cloneNode(true); |
| 96 | + row.appendChild(cell); |
| 97 | + cell.childNodes[0].textContent = i; |
| 98 | + cell.ng339 = 'xxx'; |
| 99 | + comment = document.createComment('ngRepeat end: bar in foo'); |
| 100 | + row.appendChild(comment); |
| 101 | + } |
| 102 | + |
| 103 | + comment = document.createComment('ngRepeat end: foo in foos'); |
| 104 | + $element[0].appendChild(comment); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + $scope.$watch('data.length', function(newVal) { |
| 109 | + if (newVal === 0) { |
| 110 | + while ($element[0].firstChild) { |
| 111 | + $element[0].removeChild($element[0].firstChild); |
| 112 | + } |
| 113 | + } else { |
| 114 | + createList(); |
| 115 | + } |
| 116 | + }); |
| 117 | + } |
| 118 | + }; |
| 119 | + }); |
| 120 | +})(); |
0 commit comments