docs: add advanced skills for Vitest, Pinia, and Vue built-ins
Add comprehensive reference documentation for: - Vitest: environments, projects/workspaces, type testing, vi utilities - Pinia: HMR, Nuxt integration, SSR setup - Vue: built-in components (Transition, Teleport, Suspense, KeepAlive) and advanced directives
This commit is contained in:
57
.agents/skills/vueuse-functions/references/useThrottleFn.md
Normal file
57
.agents/skills/vueuse-functions/references/useThrottleFn.md
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
category: Utilities
|
||||
related: refThrottled, refDebounced, useDebounceFn
|
||||
---
|
||||
|
||||
# useThrottleFn
|
||||
|
||||
Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.
|
||||
|
||||
> Throttle is a spring that throws balls: after a ball flies out it needs some time to shrink back, so it cannot throw any more balls unless it's ready.
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { useThrottleFn } from '@vueuse/core'
|
||||
|
||||
const throttledFn = useThrottleFn(() => {
|
||||
// do something, it will be called at most 1 time per second
|
||||
}, 1000)
|
||||
|
||||
useEventListener(window, 'resize', throttledFn)
|
||||
```
|
||||
|
||||
## Recommended Reading
|
||||
|
||||
- [**Debounce vs Throttle**: Definitive Visual Guide](https://kettanaito.com/blog/debounce-vs-throttle)
|
||||
|
||||
## Type Declarations
|
||||
|
||||
```ts
|
||||
/**
|
||||
* Throttle execution of a function. Especially useful for rate limiting
|
||||
* execution of handlers on events like resize and scroll.
|
||||
*
|
||||
* @param fn A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
|
||||
* to `callback` when the throttled-function is executed.
|
||||
* @param ms A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
|
||||
* (default value: 200)
|
||||
*
|
||||
* @param [trailing] if true, call fn again after the time is up (default value: false)
|
||||
*
|
||||
* @param [leading] if true, call fn on the leading edge of the ms timeout (default value: true)
|
||||
*
|
||||
* @param [rejectOnCancel] if true, reject the last call if it's been cancel (default value: false)
|
||||
*
|
||||
* @return A new, throttled, function.
|
||||
*
|
||||
* @__NO_SIDE_EFFECTS__
|
||||
*/
|
||||
export declare function useThrottleFn<T extends FunctionArgs>(
|
||||
fn: T,
|
||||
ms?: MaybeRefOrGetter<number>,
|
||||
trailing?: boolean,
|
||||
leading?: boolean,
|
||||
rejectOnCancel?: boolean,
|
||||
): PromisifyFn<T>
|
||||
```
|
||||
Reference in New Issue
Block a user