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

Conversation

preethi26
Copy link

@preethi26 preethi26 commented Jan 16, 2017

#3497

Summary

1.Whenever the .finish or the .stop functions modify the timers queue, we maintain all those indexes that are removed in a list ( i.e, lis[ ] ). Whenever the tick function iterates over the queue, we update the iterator based on the value of the indexes removed ( only when the indexes less than the current iterator value are removed there will be a skipping over the animations ).

  1. Handled extra processing of the same animation by doing as mentioned below:
    All the new animations that are added to the timers queue in the middle of a particular iteration of the tick function are processed in the next iteration.

Checklist

  • Handled the "skipping over multiple animations " of tick function.
  • Handled extra processing.

@mention-bot
Copy link

@preethi26, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jeresig, @gnarf and @timmywil to be potential reviewers.

…Handled repeated execution of animation in first tick. Fixes jquery#3497.

corrected syntax error

Fixes jquery#3497

Fixed. jquery#3497

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.

@markelog
Copy link
Member

@preethi26 friendly ping

@gibson042
Copy link
Member

This is really not what I'm looking for; see my comment about O(N²) operations and extra global variables. And note that a functional change will absolutely not be accepted without unit tests.

@preethi26
Copy link
Author

@gibson042 ,
Got it, and I am sorry for the previous mess. As I am less familiarised with the Source Code, I don't have much of clarity on what you meant in your first comment ( because of which I think I overlooked it and thought of some other solution that avoids O(N²) operations and new global variables, sorry for that ). Could you please brief me a little as I would like to fix and finish working on this issue ( if you didn't find the code that you were already working on ? )

@gibson042
Copy link
Member

No problem. As I mentioned in the comment, I think we can mostly cover this by checking and deleting the elem property of items in jQuery.timers instead of manipulating the array itself, at least inside iterations over it (i.e., extending already existing logic so jQuery.timers can temporarily hold zombie entries). Outside the iterations, though, we may well need a global mutex variable.

@timmywil timmywil added this to the 4.0.0 milestone Mar 13, 2017
@timmywil timmywil changed the title PR that Fixes #3497. Effects: sync .stop/.finish with .tick to maintain proper queue (#3497) Jul 24, 2017
Base automatically changed from master to main February 1, 2021 22:02
@mgol
Copy link
Member

mgol commented Sep 17, 2021

Closing & re-opening the PR to trigger the EasyCLA check...

@mgol mgol closed this Sep 17, 2021
@mgol mgol reopened this Sep 17, 2021
@linux-foundation-easycla
Copy link

CLA Not Signed

@mgol mgol modified the milestones: 4.0.0, Future Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants