logo

/Code Snippet|v2.3.3

Module

Static Methods

debounce(fn, delay)debounce.jsline 39

Creates a debounced function that delays invoking fn until after delay milliseconds has elapsed
since the last time the debouced function was invoked.

PARAMETERS
NameTypeDescription

fn

function

The function to debounce.

delay

number = 0

The number of milliseconds to delay

RETURNS:
{

function

} - debounced function.
EXAMPLES
// ES6
import debounce from 'tui-code-snippet/tricks/debounce';

// CommonJS
const debounce = require('tui-code-snippet/tricks/debounce');

function someMethodToInvokeDebounced() {}

const debounced = debounce(someMethodToInvokeDebounced, 300);

// invoke repeatedly
debounced();
debounced();
debounced();
debounced();
debounced();
debounced();    // last invoke of debounced()

// invoke someMethodToInvokeDebounced() after 300 milliseconds.

throttle(fn, interval)throttle.jsline 41

Creates a throttled function that only invokes fn at most once per every interval milliseconds.
You can use this throttle short time repeatedly invoking functions. (e.g MouseMove, Resize ...)
if you need reuse throttled method. you must remove slugs (e.g. flag variable) related with throttling.

PARAMETERS
NameTypeDescription

fn

function

function to throttle

interval

number = 0

the number of milliseconds to throttle invocations to.

RETURNS:
{

function

} - throttled function
EXAMPLES
// ES6
import throttle from 'tui-code-snippet/tricks/throttle';

// CommonJS
const throttle = require('tui-code-snippet/tricks/throttle');

function someMethodToInvokeThrottled() {}

const throttled = throttle(someMethodToInvokeThrottled, 300);

// invoke repeatedly
throttled();    // invoke (leading)
throttled();
throttled();    // invoke (near 300 milliseconds)
throttled();
throttled();
throttled();    // invoke (near 600 milliseconds)
// ...
// invoke (trailing)

// if you need reuse throttled method. then invoke reset()
throttled.reset();
Resizable