Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix($animateCss): don't unregister events when empty #13514

Closed
wants to merge 1 commit into from

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Dec 11, 2015

No description provided.

@Narretz Narretz added this to the 1.5.0-rc.1 milestone Dec 11, 2015
@Narretz Narretz force-pushed the fix-animate-endevent-10387 branch from f79f435 to 6d32907 Compare December 11, 2015 16:11
@Narretz Narretz force-pushed the fix-animate-endevent-10387 branch from 6d32907 to 6e876cd Compare December 11, 2015 16:27
Narretz added a commit to Narretz/angular.js that referenced this pull request Dec 11, 2015
Previously, when an animation was closed because no animation styles
where found, it would call .off() with an empty string as the argument.

For both jquery/jqlite this is the same as calling .off() without any
argument, which deregisters all event listeners on an element.

Closes angular#13514
@Narretz Narretz force-pushed the fix-animate-endevent-10387 branch from 6e876cd to 2292497 Compare December 11, 2015 16:44
Narretz added a commit to Narretz/angular.js that referenced this pull request Dec 11, 2015
Previously, when an animation was closed because no animation styles
where found, it would call .off() with an empty string as the argument.

For both jquery/jqlite this is the same as calling .off() without any
argument, which deregisters all event listeners on an element.

Closes angular#13514
@Narretz Narretz force-pushed the fix-animate-endevent-10387 branch from 2292497 to dc88816 Compare December 11, 2015 17:07
Narretz added a commit to Narretz/angular.js that referenced this pull request Dec 11, 2015
Previously, when an animation was closed because no animation styles
where found, it would call .off() with an empty string as the argument.

For both jquery/jqlite this is the same as calling .off() without any
argument, which deregisters all event listeners on an element.

Closes angular#13514
@@ -750,7 +750,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
}

// Remove the transitionend / animationend listener(s)
if (events) {
if (events && events.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: events will always be truthy, since it is initialized to [].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a nitpick, good catch!

@gkalpak
Copy link
Member

gkalpak commented Dec 11, 2015

We need to make sure that we will not call .on() if events is empty, because then event listeners will be registered for '' (empty string) and they will never be deregistered.
I haven't checked if there are other conditions that ensure we never reach the .on(events.join(' '), ...) call, but if there aren't, we should check explicitly. (In fact, it would be better to check explicitly eitherway, unless I missed something obvious.)

@Narretz
Copy link
Contributor Author

Narretz commented Dec 12, 2015

Hmm. I think we should only test behavior. The unit tests should not be concerned with the events variable or if it can be empty or not. I realize that keeping implementation out of unit tests isn't always easy. For example, with $animateCss, you have to base the tests on the assumption that an animation will only actually start after a requestAnimationFrame.

I will have another look at the code and see if there are other cases where the animation process gets aborted before the events are registered.

@gkalpak
Copy link
Member

gkalpak commented Dec 14, 2015

I probably wasn't clear enough. By "check" I didn't mean in unit tests, I meant in the actual code that sets up the listeners. I.e. change this line:

// Before:
element.on(events.join(' '), onAnimationProgress);
// ^-- If events is empty, a listener will be registered for '' (and never deregistered)

// After:
if (events.length) element.on(events.join(' '), onAnimationProgress);

@Narretz Narretz force-pushed the fix-animate-endevent-10387 branch from dc88816 to 7ed2336 Compare December 14, 2015 09:57
Narretz added a commit to Narretz/angular.js that referenced this pull request Dec 14, 2015
…en added

Previously, when an animation was closed because no animation styles
where found, it would call .off() with an empty string as the argument.

For both jquery/jqlite this is the same as calling .off() without any
argument, which deregisters all event listeners on an element.

Closes angular#13514
@Narretz
Copy link
Contributor Author

Narretz commented Dec 14, 2015

Ok, I see what you mean. I don't think events can be empty when listeners are added, but the if can't hurt.

…dded

Previously, when an animation was closed because no animation styles
where found, it would call .off() with an empty string as the argument.

For both jquery/jqlite this is the same as calling .off() without any
argument, which deregisters all event listeners on an element.

Closes angular#13514
@Narretz Narretz force-pushed the fix-animate-endevent-10387 branch from 7ed2336 to 11357cc Compare December 14, 2015 10:57
@@ -749,8 +749,8 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
options.onDone();
}

// Remove the transitionend / animationend listener(s)
if (events) {
if (events && events.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually possible that events is undefined, because if no node is detected, the animation is closed before a bunch of variables are even declared.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I missed that 😞

@petebacondarwin
Copy link
Contributor

LGTM

@Narretz Narretz closed this in 959f2bb Jan 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants