Function: debounce()
ts
function debounce<Args>(fn, wait): Debounced<Args>;Delay fn until wait ms have passed without another call. Only the arguments of the last call are used.
Use it to throttle expensive work such as saving from onChange:
Type Parameters
| Type Parameter |
|---|
Args extends unknown[] |
Parameters
| Parameter | Type |
|---|---|
fn | (...args) => void |
wait | number |
Returns
Debounced<Args>
Example
ts
const save = debounce((editor: Editor) => api.save(editor.getJSON()), 500)
createEditor({ onChange: save, ... })
window.addEventListener('beforeunload', () => save.flush())