This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(ngAnimate): avoid repeated calls to addClass/removeClass when an…
…imation has no duration Background: ngAnimate writes helper classes to DOM elements to see if animations are defined on them. If many elements have the same definition, we can cache the definition and skip the application of the helper classes altogether. This helps particularly with large ngRepeat collections. Closes #14165 Closes #14166
- Loading branch information
Showing
12 changed files
with
408 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
/** @this */ | ||
var $$AnimateCacheProvider = function() { | ||
|
||
var KEY = '$$ngAnimateParentKey'; | ||
var parentCounter = 0; | ||
var cache = Object.create(null); | ||
|
||
this.$get = [function() { | ||
return { | ||
cacheKey: function(node, method, addClass, removeClass) { | ||
var parentNode = node.parentNode; | ||
var parentID = parentNode[KEY] || (parentNode[KEY] = ++parentCounter); | ||
var parts = [parentID, method, node.getAttribute('class')]; | ||
if (addClass) { | ||
parts.push(addClass); | ||
} | ||
if (removeClass) { | ||
parts.push(removeClass); | ||
} | ||
return parts.join(' '); | ||
}, | ||
|
||
containsCachedAnimationWithoutDuration: function(key) { | ||
var entry = cache[key]; | ||
|
||
// nothing cached, so go ahead and animate | ||
// otherwise it should be a valid animation | ||
return (entry && !entry.isValid) || false; | ||
}, | ||
|
||
flush: function() { | ||
cache = Object.create(null); | ||
}, | ||
|
||
count: function(key) { | ||
var entry = cache[key]; | ||
return entry ? entry.total : 0; | ||
}, | ||
|
||
get: function(key) { | ||
var entry = cache[key]; | ||
return entry && entry.value; | ||
}, | ||
|
||
put: function(key, value, isValid) { | ||
if (!cache[key]) { | ||
cache[key] = { total: 1, value: value, isValid: isValid }; | ||
} else { | ||
cache[key].total++; | ||
cache[key].value = value; | ||
} | ||
} | ||
}; | ||
}]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.