@common-utilities/debounce
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "@common-utilities/debounce", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A basic implementation of the common utility function, Debounce 🏓", | ||
@@ -31,3 +31,3 @@ "main": "dist/index.js", | ||
], | ||
"gitHead": "0c2892395dbb2963f10f5cddda5b311591d2dbad" | ||
"gitHead": "306640dddfb574cc3958dd3b312fdae5c8933d5f" | ||
} |
@@ -10,28 +10,3 @@ # @common-utilities/debounce 🧰 🏓 | ||
## Install | ||
Check out the [debounce page](https://www.common-utilities.com/utilities/packages/debounce) in the [docs](https://www.common-utilities.com)! License, MIT | ||
```bash | ||
yarn add @common-utilities/debounce -D | ||
``` | ||
## Usage | ||
```javascript | ||
let result = 1 | ||
const add1 = (val) => { | ||
result = val + 1 | ||
} | ||
debounce(add1, 1000)(1) // returns 2, after 1 second | ||
``` | ||
--- | ||
## Common Utilities 🧰 | ||
**No cruft. No bloat. No dependencies.** | ||
Simple, typed, functional, documented, and tested javascript utility functions. | ||
--- | ||
View other [common utilities](https://github.com/yowainwright/common-utilities). |
@@ -11,7 +11,9 @@ type Fn = (args?: unknown) => void | ||
*/ | ||
export const debounce = (fn: Fn, delay: number, timeout = 0): Fn => (args?: unknown) => { | ||
clearTimeout(timeout) | ||
// adds `as unknown as number` to ensure setTimeout returns a number | ||
// like window.setTimeout | ||
timeout = (setTimeout((): void => fn(args), delay) as unknown) as number | ||
} | ||
export const debounce = | ||
(fn: Fn, delay: number, timeout = 0): Fn => | ||
(args?: unknown) => { | ||
clearTimeout(timeout) | ||
// adds `as unknown as number` to ensure setTimeout returns a number | ||
// like window.setTimeout | ||
timeout = setTimeout((): void => fn(args), delay) as unknown as number | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
78
5067
12