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

Query : Use of _.debounce #397

Closed
nandita121189 opened this issue Jul 26, 2017 · 4 comments
Closed

Query : Use of _.debounce #397

nandita121189 opened this issue Jul 26, 2017 · 4 comments

Comments

@nandita121189
Copy link

Can you please explain the use of the following line in reflowable_view.js

_.debounce(updatePagination_, 100);

This line is causing the updatePagination_ function to be called twice on window resize, due to which a flickering is observed after the window resizes.

If I rewrite the code after removing the _.debounce, then flickering no longer occurs.

 var updatePagination = updatePagination_; 

Can you please guide me if rewriting the code can cause any regression issues. ?

@danielweck
Copy link
Member

This use of the _.debounce() function ensures that the updatePagination_() function is executed only once even though client code may invoke the debounced updatePagination() function several times in quick successions, before the 100ms time window elapses.
The "flickering" you are referring to seems to be the result of a 100ms period of "inactivity", as the updatePagination_() function is effectively not called instantly.

If you remove the "debouncer" you may indeed observe the immediate benefit of instant refresh, but in some other (edge?) cases the multiple quick-fire calls to updatePagination() will create worse problems.

So, could you please try to add the "true" function parameter after "100", so that the updatePagination_() function is invoked on the leading edge of the wait interval (immediately), rather than the trailing edge (deferred).
http://underscorejs.org/#debounce

Many thanks! :)

@nandita121189
Copy link
Author

Thanks @danielweck , the solution you suggested worked. Now the updatePagination_ function is called only once on window resize and flickering doesn't occur.

@rkwright
Copy link
Contributor

rkwright commented Aug 3, 2017

Appears resolved. Closing

@danielweck
Copy link
Member

Issue "migrated" to: #399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants