From 550c917b08ca9f923a5914b90f885ab7c198bd44 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Tue, 8 Feb 2022 15:27:55 +0100 Subject: [PATCH] Add "running" property to debounce wrapper --- debounce.js | 1 + page/debounce.html | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/debounce.js b/debounce.js index a69689e..adebbd6 100644 --- a/debounce.js +++ b/debounce.js @@ -15,5 +15,6 @@ export default (action, delay=1e3) => { func.cancel() return action(...args) } + Object.defineProperty(func, "running", {get() {return Boolean(timeout)}}) return func } diff --git a/page/debounce.html b/page/debounce.html index 789380b..40af18a 100644 --- a/page/debounce.html +++ b/page/debounce.html @@ -41,12 +41,14 @@

Methods

- The returned wrapper function has two methods: + The returned wrapper function has the following methods and properties:

cancel()
Cancels the running timeout without calling the target function.
now(...)
Cancels the running timeout and calls the target function immediately.
+
running
+
true if there is a timeout currently running, false otherwise.