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: add maxWait parameter to useDebouncedCallback hook #131

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

xobotyi
Copy link
Contributor

@xobotyi xobotyi commented Jun 16, 2021

maxWait defines maximum amount of milliseconds that function can be delayed before it's force execution. 0 means no max wait (default).

should be merged after #130

Checklist

  • Have you read contribution guideline?
  • Does the code have comments in hard-to-understand areas?
  • Is there an existing issue for this PR?
    • link issue here
  • Have the files been linted and formatted?
  • Have the docs been updated?
  • Have the tests been added to cover new hook?
  • Have you run the tests locally to confirm they pass?

@xobotyi xobotyi added the ✨ enhancement New feature or request label Jun 16, 2021
@xobotyi xobotyi requested a review from JoeDuncko June 16, 2021 09:00
@codecov
Copy link

codecov bot commented Jun 16, 2021

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##            master      #131    +/-   ##
==========================================
  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 77f66d7...ae8dc44. Read the comment docs.

@JoeDuncko
Copy link
Contributor

While we are here, should we also implement leading and trailing options, to copy lodash's implementation ?

@xobotyi
Copy link
Contributor Author

xobotyi commented Jun 16, 2021

Leading and trailing is only a matter of single implementation for both, throttle and debounce (if you look their throttle - it is only rewrapped debounce).
I prefer more specialized and therefore short and simple implementations.

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.

LGTM, but see comments above

src/useDebouncedCallback/useDebouncedCallback.ts Outdated Show resolved Hide resolved
@xobotyi xobotyi force-pushed the improve-useDebouncedCallback branch from 8207e8a to ae8dc44 Compare June 16, 2021 14:50
@xobotyi xobotyi merged commit 600baa8 into master Jun 16, 2021
@xobotyi xobotyi deleted the improve-useDebouncedCallback branch June 16, 2021 14:56
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