debounce<T, V>
Official
A standard debounce export function. Use this to have a time-delayed export function only be called once in a given timeframe.
Import:
import { debounce } from 'obsidian';Example:
const debounced = debounce((text: string) => { console.log(text);}, 1000, true);debounced('foo'); // this will not be printedawait sleep(500);debounced('bar'); // this will be printed to the console.Signature:
function debounce(cb: (...args: T) => V, timeout: number | undefined, resetTimer: boolean | undefined): Debouncer<T, V>Parameters:
| Parameter | Type | Description |
|---|---|---|
cb | (…args: T) => V | The export function to call. |
timeout | number | undefined | The timeout to wait, in milliseconds. |
resetTimer | boolean | undefined | Whether to reset the timeout when the debounce export function is called again. |
Returns: Debouncer<T, V> — a debounced export function that takes the same parameter as the original export function.
Example:
const debounced = debounce((text: string) => { console.log(text);}, 1000, true);debounced('foo'); // this will not be printedawait sleep(500);debounced('bar'); // this will be printed to the console.