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

feat: change args for useThrottledCallback and useDebouncedCallback #132

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

xobotyi
Copy link
Contributor

@xobotyi xobotyi commented Jun 16, 2021

useThrottledCallback and useDebouncedCallback has different arguments order comparing to useCallback (delay argument is before deps list). It is mentally harder to handle such differences.

BREAKING CHANGE:
delay and deps arguments are swapped position for useThrottledCallback and useDebouncedCallback hooks to be aligned with useCallback signature.

merge after #131

Checklist

  • Have you read contribution guideline?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Is there an existing issue for this PR?
    • link issue here
  • Have the files been linted and formatted?
  • Have the docs been updated to match the changes in the PR?
  • Have the tests been updated to match the changes in the PR?
  • Have you run the tests locally to confirm they pass?

@xobotyi xobotyi added the ✨ enhancement New feature or request label Jun 16, 2021
@codecov
Copy link

codecov bot commented Jun 16, 2021

Codecov Report

Merging #132 (c383b58) into master (021d02a) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            master      #132    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           15        32    +17     
  Lines          111       543   +432     
  Branches        14       100    +86     
==========================================
+ Hits           111       543   +432     
Impacted Files Coverage Δ
src/useFirstMountState/useFirstMountState.ts 100.00% <ø> (ø)
src/useIsMounted/useIsMounted.ts 100.00% <ø> (ø)
src/useMountEffect/useMountEffect.ts 100.00% <ø> (ø)
src/usePrevious/usePrevious.ts 100.00% <ø> (ø)
src/useUnmountEffect/useUnmountEffect.ts 100.00% <ø> (ø)
src/index.ts 100.00% <100.00%> (ø)
src/useAsync/useAsync.ts 100.00% <100.00%> (ø)
src/useConditionalEffect/useConditionalEffect.ts 100.00% <100.00%> (ø)
...ditionalUpdateEffect/useConditionalUpdateEffect.ts 100.00% <100.00%> (ø)
src/useCookieValue/useCookieValue.ts 100.00% <100.00%> (ø)
... and 40 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 600baa8...c383b58. Read the comment docs.

Copy link
Contributor

@JoeDuncko JoeDuncko left a comment

Choose a reason for hiding this comment

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

Actually, I think I'm less convinced that the dependency list shouldn't be the last argument. How do other libraries handle this?

Thinking about this more, I'm wondering if we should move to an options object here like lodash.

@xobotyi
Copy link
Contributor Author

xobotyi commented Jun 16, 2021

Disagree about options object, since is longer record:

useDebouncedEffect(()=>{}, [], 200, 600);

vs

useDebouncedEffect(()=>{}, [], { delay: 200, maxWait: 600 });

Options object is more obvious though, but most IDE highlight arguments so this should not be an issue.

If there would be more options - i would agree, but at leas for now, on my taste, arguments are better solution

@xobotyi
Copy link
Contributor Author

xobotyi commented Jun 16, 2021

How do other libraries handle this?

Have no idea, havent watched any other solutions =)

Ed: react-use have delay right after the function, but as you see i disagree with that.
IMO API should be aligned with react's useCallback

Copy link
Contributor

@JoeDuncko JoeDuncko left a comment

Choose a reason for hiding this comment

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

kk, you've convinced me. Until we have more args this should be fine.

@xobotyi xobotyi force-pushed the change_debounced_and_throttled_hooks branch from 27fd0e3 to 72c491a Compare June 16, 2021 15:01
BREAKING CHANGE:
`delay` and `deps` arguments are swapped position for
`useThrottledCallback` and `useDebouncedCallback` hooks to be aligned
with `useCallback` signature.
@xobotyi xobotyi force-pushed the change_debounced_and_throttled_hooks branch from 72c491a to c383b58 Compare June 16, 2021 15:09
@xobotyi xobotyi merged commit 131d98e into master Jun 16, 2021
@xobotyi xobotyi deleted the change_debounced_and_throttled_hooks branch June 16, 2021 15:12
github-actions bot pushed a commit that referenced this pull request Jun 16, 2021
# [3.0.0](v2.2.0...v3.0.0) (2021-06-16)

### Bug Fixes

* rename useThrottleCallback and useDebounceCallback ([#130](#130)) ([77f66d7](77f66d7)), closes [#129](#129)

### Features

* add `maxWait` parameter to `useDebouncedCallback` hook ([#131](#131)) ([600baa8](600baa8))
* change args for `useThrottledCallback` and `useDebouncedCallback` ([#132](#132)) ([131d98e](131d98e))
* new hooks `useDebouncedEffect` and `useDebouncedState` ([#133](#133)) ([1d164ff](1d164ff))

### BREAKING CHANGES

* `delay` and `deps` arguments are swapped position for
`useThrottledCallback` and `useDebouncedCallback` hooks to be aligned
with `useCallback` signature.
* `useDebounceCallback` renamed to `useDebouncedCallback`
`useThrottleCallback` renamed to `useThrottledCallback`
@xobotyi
Copy link
Contributor Author

xobotyi commented Jun 16, 2021

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request released
Development

Successfully merging this pull request may close these issues.

2 participants