15 lines
No EOL
302 B
JavaScript
15 lines
No EOL
302 B
JavaScript
export default function debounce(fn) {
|
|
var pending;
|
|
return function () {
|
|
if (!pending) {
|
|
pending = new Promise(function (resolve) {
|
|
Promise.resolve().then(function () {
|
|
pending = undefined;
|
|
resolve(fn());
|
|
});
|
|
});
|
|
}
|
|
|
|
return pending;
|
|
};
|
|
} |