Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effects: sync .stop/.finish with .tick to maintain proper queue (#3497) #3501

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ jQuery.speed = function( speed, easing, fn ) {

return opt;
};

var lis = [];
jQuery.fn.extend( {
fadeTo: function( speed, to, easing, callback ) {

Expand Down Expand Up @@ -552,6 +552,7 @@ jQuery.fn.extend( {

timers[ index ].anim.stop( gotoEnd );
dequeue = false;
lis.push( index );
timers.splice( index, 1 );
}
}
Expand Down Expand Up @@ -590,6 +591,7 @@ jQuery.fn.extend( {
for ( index = timers.length; index--; ) {
if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
timers[ index ].anim.stop( true );
lis.push( index );
timers.splice( index, 1 );
}
}
Expand Down Expand Up @@ -631,15 +633,25 @@ jQuery.each( {
} );

jQuery.timers = [];
var oldLength = 0;
jQuery.fx.tick = function() {
var timer,
i = 0,
timers = jQuery.timers;

fxNow = jQuery.now();
oldLength = timers.length;
for ( ; i < oldLength; i++ ) {
var removedTimers = 0;

for ( ; i < timers.length; i++ ) {
timer = timers[ i ];
for ( var j = 0; j < lis.length; j++ ) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm hoping to avoid O(N²) operations and extra global variables, and was thinking we'd do this by checking/clearing timer.elem since that's already cleared in an always callback.

Copy link
Author

@preethi26 preethi26 Jan 16, 2017

Choose a reason for hiding this comment

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

ok ! not a problem.
I would like to know if the second bug about extra processing was handled?
As I wasn't sure about it I did not mark it in the checklist.

Copy link
Member

Choose a reason for hiding this comment

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

Probably not, but we'll see. This PR will also require unit tests that don't pass without the updated code.

Copy link
Author

@preethi26 preethi26 Jan 30, 2017

Choose a reason for hiding this comment

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

hey @gibson042 ,

jQuery.timers = [];
jQuery.fx.tick = function() {

var timer,
	i = 0,
	timers = jQuery.timers;

fxNow = jQuery.now();
for ( ; i < timers.length; i++ ) {
	timer = timers[ i ];
	var x  = timers.indexOf(timer)
	
	if (  !timer()  ) {
		if( x > timers.indexOf(timer)) {
			i = i - ( x - timers.indexOf(timer) )
		}

		if( timers[ i ] === timer ) {
			timers.splice( i--, 1 );
		}
	}
}

if ( !timers.length ) {
	jQuery.fx.stop();
}
fxNow = undefined;

};
This is the edited [ jQuery.fx.tick()] https://github.com/jquery/jquery/blob/master/src/effects.js#L644) function.
I would like to know if this fixes the first part of the bug before proceeding further.

Thank you,
Preethi.

Copy link
Author

@preethi26 preethi26 Feb 3, 2017

Choose a reason for hiding this comment

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

@gibson042. Sorry, just realized that it wouldn't work. Coz we need to check the value of "timer" 's index in between consecutive iterations ( which is not done here ).

Copy link
Author

Choose a reason for hiding this comment

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

@gibson042
error_bug_1

In every iteration, making the value of the iterator equal to the value of the previous timer that successfully ran + 1.

if ( lis[ j ] <= i ) {
removedTimers++;
}
lis.splice( j, 1 );
}
i = i - removedTimers;
timer = timers[ i ];

// Checks the timer has not already been removed
if ( !timer() && timers[ i ] === timer ) {
Expand Down