aboutsummaryrefslogtreecommitdiff
path: root/src/debounce.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/debounce.js')
-rw-r--r--src/debounce.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/debounce.js b/src/debounce.js
new file mode 100644
index 0000000..02f1a1a
--- /dev/null
+++ b/src/debounce.js
@@ -0,0 +1,8 @@
+export default function debounce (func, wait) {
+ let timeout
+ return function (...args) {
+ const context = this
+ clearTimeout(timeout)
+ timeout = setTimeout(() => func.apply(context, args), wait)
+ }
+}