/tlence

debounce and throttle techniques for performance

Primary LanguageJavaScriptMIT LicenseMIT

tlence

tlence

NPM

install size dependencies

Version License Downloads Build Status

debounce and throttle techniques for performance

install

npm install tlence

use

Throttle

import { throttle } from 'tlence';

function log(server) {
  console.log('connecting to', server);
}

const throttleLog = throttle(log, 5000);
// just run first call to 5s
throttleLog('local');
throttleLog('local');
throttleLog('local');
throttleLog('local');
throttleLog('local');
throttleLog('local');

Debounce

import { debounce, delay } from 'tlence';
const debounceLog = debounce(log, 5000);
// just run last call to 5s
debounceLog('local');
debounceLog('local');
debounceLog('local');
debounceLog('local');
debounceLog('local');
debounceLog('local');

Delay

import { delay } from 'tlence';
console.log('delay 1');
await delay(5000);
// run after 5s
console.log('delay 2');