8000 ngClass[Odd/Even] overhaul by gkalpak · Pull Request #15228 · 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.

ngClass[Odd/Even] overhaul #15228

Closed
wants to merge 15 commits into from
Closed
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
Next Next commit
perf(ngClass): only access the element's data once
  • Loading branch information
gkalpak committed Oct 7, 2016
commit 89268afb341487aa4e26148d87ad6d6c66e09d3c
14 changes: 10 additions & 4 deletions src/ng/directive/ngClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ function classDirective(name, selector) {
return {
restrict: 'AC',
link: function(scope, element, attr) {
var classCounts = element.data('$classCounts');
var oldVal;

if (!classCounts) {
// Use createMap() to prevent class assumptions involving property
// names in Object.prototype
classCounts = createMap();
element.data('$classCounts', classCounts);
}

if (name !== 'ngClass') {
scope.$watch('$index', function($index, old$index) {
/* eslint-disable no-bitwise */
Expand Down Expand Up @@ -44,10 +52,8 @@ function classDirective(name, selector) {
}

function digestClassCounts(classes, count) {
// Use createMap() to prevent class assumptions involving property
// names in Object.prototype
var classCounts = element.data('$classCounts') || createMap();
var classesToUpdate = [];

forEach(classes, function(className) {
if (count > 0 || classCounts[className]) {
classCounts[className] = (classCounts[className] || 0) + count;
Expand All @@ -56,7 +62,7 @@ function classDirective(name, selector) {
}
}
});
element.data('$classCounts', classCounts);

return classesToUpdate.join(' ');
}

Expand Down
0