sindresorhus / p-debounce

Debounce promise-returning & async functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `after` option

fregante opened this issue · comments

Honestly I don't know how to reconcile this with Promises. I thought this was needed to match debounce-fn but I can't make sense of return values of before:true, after: true function calls.

// Default values
const debouncedFn = pDebounce(expensiveCall, 200, {before: false, after: true});

for (const i of [1, 2, 3]) {
	debouncedFn(i).then(console.log);
}
//=> 3
//=> 3
//=> 3
// Current `leading: true`
const debouncedFn = pDebounce(expensiveCall, 200, {before: true, after: false});

for (const i of [1, 2, 3]) {
	debouncedFn(i).then(console.log);
}
//=> 1
//=> 1
//=> 1
// This proposal
const debouncedFn = pDebounce(expensiveCall, 200, {before: true, after: true});

for (const i of [1, 2, 3]) {
	debouncedFn(i).then(console.log);
}
//=> 1
//=> 1
//=> 1
// No changes?