Skip to content

Commit

Permalink
Optimise default types
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli committed Aug 26, 2023
1 parent 093873b commit 334e278
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
//
// Returns: <Function>
const throttle = (timeout, fn, ...args) => {
let timer;
let timer = null;
let wait = false;

const execute = args
? (...pars) => (pars ? fn(...args, ...pars) : fn(...args))
: (...pars) => (pars ? fn(...pars) : fn());

const delayed = (...pars) => {
timer = undefined;
timer = null;
if (wait) execute(...pars);
};

Expand All @@ -38,12 +38,15 @@ const throttle = (timeout, fn, ...args) => {
// fn - <Function>, to be debounced
// args - <Array>, arguments for fn, optional
const debounce = (timeout, fn, ...args) => {
let timer;
let timer = null;

const debounced = () => (args ? fn(...args) : fn());

const wrapped = () => {
if (timer) clearTimeout(timer);
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(debounced, timeout);
};

Expand Down

0 comments on commit 334e278

Please sign in to comment.