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
fix(ngAnimate): don't normalize classes on follow-up animations to jo… #13472
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,14 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { | |
join: [] | ||
}; | ||
|
||
function makeTruthyMapFromKeys(keys) { | ||
var map = Object.create(null); | ||
forEach(keys, function(key) { | ||
map[key] = true; | ||
}); | ||
return map; | ||
} | ||
|
||
function isAllowed(ruleType, element, currentAnimation, previousAnimation) { | ||
return rules[ruleType].some(function(fn) { | ||
return fn(element, currentAnimation, previousAnimation); | ||
|
@@ -59,11 +67,38 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { | |
}); | ||
|
||
rules.cancel.push(function(element, newAnimation, currentAnimation) { | ||
var nO = newAnimation.options; | ||
var cO = currentAnimation.options; | ||
var ONE_SPACE = ' '; | ||
|
||
var nA = newAnimation.options.addClass; | ||
var nR = newAnimation.options.removeClass; | ||
var cA = currentAnimation.options.addClass; | ||
var cR = currentAnimation.options.removeClass; | ||
|
||
// early detection to save the global CPU shortage :) | ||
if ((!isDefined(nA) && !isDefined(nR)) || (!isDefined(cA) && !isDefined(cR))) { | ||
return false; | ||
} | ||
|
||
var cancelSomething = false; | ||
|
||
cA = cA ? makeTruthyMapFromKeys(cA.split(ONE_SPACE)) : null; | ||
cR = cR ? makeTruthyMapFromKeys(cR.split(ONE_SPACE)) : null; | ||
|
||
if (cR && nA) { | ||
cancelSomething = nA.split(ONE_SPACE).some(function(className) { | ||
return cR[className]; | ||
}); | ||
|
||
if (cancelSomething) return true; | ||
} | ||
|
||
if (cA && nR) { | ||
cancelSomething = nR.split(ONE_SPACE).some(function(className) { | ||
return cA[className]; | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The repeated logic here could be moved into a function... return (hasMatchingClasses(nA, cR)) || (hasMatchingClasses(nR, cA)); function hasMatchingClasses(classString, classMap) {
if (classString && classMap) {
return classString.split(ONE_SPACE).some(function(className) {
return classMap[className];
});
}
} |
||
|
||
// if the exact same CSS class is added/removed then it's safe to cancel it | ||
return (nO.addClass && nO.addClass === cO.removeClass) || (nO.removeClass && nO.removeClass === cO.addClass); | ||
return cancelSomething; | ||
}); | ||
|
||
this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap', | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This repeated logic here could be moved into the
makeTrutyMapFromKeys
and perhaps be renamed tomakeCssClassMap