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

fix(useThrottleFn): trailing option should be false by default #1687

Merged
merged 2 commits into from Jul 6, 2022

Conversation

webfansplz
Copy link
Member

@webfansplz webfansplz commented Jun 13, 2022

Description

Close #1684

Follow the design principles of throttle function,I think we shouldn't call fn again by default after the time is up .

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@antfu antfu mentioned this pull request Jul 4, 2022
8 tasks
@antfu antfu added this to the 9.0 milestone Jul 6, 2022
@antfu antfu changed the base branch from main to next July 6, 2022 17:54
@antfu antfu merged commit a76b207 into vueuse:next Jul 6, 2022
@septatrix
Copy link

I just saw this in the BREAKING CHANGES section of the release notes.

The correct behaviour should be to only call the function after expiration of the timeout if any throttled call occured since the last call which was forwarded to the wrapped function. This is also how underscore implements it IIRC.
In most cases (e.g. resize, scroll, input) you want to run the function one last time if a change occurred between the last time the wrapped function was called.

I am not sure what you refer to by "design principles of throttle function". The event will still only be called at most once per interval. And those which would like the other behaviour can use trailing: false though the cases where this is the correct behaviour are rare in comparison to the indented use cases like the ones given in the docs.

It remember there was a way to search all of github how some APIs were used which could be used to confirm that most people use the previous default though I am not sure how to do this (the normal github search is not really suited for this)

@septatrix
Copy link

@antfu I see that v9 is released now. Could this be reconsidered for v10?

@septatrix
Copy link

Or at least add a TIP/WARNING box like it is done for some other function about this behaviour

@septatrix
Copy link

Also all other throttle related helpers watchThrottled, refThrottled, throttleFilter default to trailing = true affirming my statement about it being the expected and more reasonable default in most cases.

@antfu
Copy link
Member

antfu commented Aug 3, 2022

Yeah I think it's reasonable to have it default to true, refer to loash https://lodash.com/docs#throttle

@septatrix You can send a PR to change it back and so we could ship it in v10

@septatrix
Copy link

@septatrix You can send a PR to change it back and so we could ship it in v10

Sure thing!

@septatrix
Copy link

Sorry I currently cannot say when I will have time to work on this

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

Successfully merging this pull request may close these issues.

useThrottleFn 快速点击会触发两次
3 participants