Overview
The API includes two common utility functions for controlling execution frequency.api.debounce(fn, delay?)
Returns a debounced version offn. The function only executes after delay milliseconds of inactivity.
Signature
| Parameter | Type | Description |
|---|---|---|
fn | function | Function to debounce |
delay | number | Debounce delay in ms. Default: 250 |
function — debounced wrapper
api.throttle(fn, limit?)
Returns a throttled version offn. The function executes at most once every limit milliseconds.
Signature
| Parameter | Type | Description |
|---|---|---|
fn | function | Function to throttle |
limit | number | Minimum interval between calls in ms. Default: 100 |
function — throttled wrapper
Debounce vs Throttle
| Debounce | Throttle | |
|---|---|---|
| Behavior | Waits for silence | Fires at fixed intervals |
| Best for | ”Do this after the user stops" | "Do this regularly while active” |
| Example | Auto-save after typing | Scroll position tracking |
| Default delay | 250ms | 100ms |