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

throttle function implements as debounce #792

Open
zepster opened this issue Jul 30, 2021 · 3 comments
Open

throttle function implements as debounce #792

zepster opened this issue Jul 30, 2021 · 3 comments

Comments

@zepster
Copy link

zepster commented Jul 30, 2021

https://github.com/impress/impress.js/blob/master/src/lib/util.js#L65-L74

        var throttle = function( fn, delay ) {
            var timer = null;
            return function() {
                var context = this, args = arguments;
                window.clearTimeout( timer );
                timer = window.setTimeout( function() {
                    fn.apply( context, args );
                }, delay );
            };
        };
@henrikingo
Copy link
Member

Sorry, what is the issue you're raising here?

@zepster
Copy link
Author

zepster commented Aug 3, 2021

var throttle works like debounce
If is ok for you - you should rename throttle to debounce.
If you expect throttle behavior - function is not implemented it

https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function

@henrikingo
Copy link
Member

I see. Thanks for the link.

It's actually a good question which behavior is "correct" or wanted here. It's subjective I guess, and also back in 2012 there may have been a higher priority to just resize once (debounce) whereas looking at this today I wouldn't mind throttle behavior either, as it would allow to drag the border of a browser window many seconds and see the presentation follow behind.

Interestingly, the code comment references the very same blog post from Remy Sharp as your StackOverflow answer: https://remysharp.com/2010/07/21/throttling-function-calls Clearly the function body is the debounce function from that blog post, yet for some reason the creator of impress.js chose to call it throttle.

I think it's ok to rename as debounce, to be semantically correct, and thanks for opening this issue.

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

No branches or pull requests

2 participants