Add "running" property to debounce wrapper
This commit is contained in:
parent
364ada6a45
commit
550c917b08
2 changed files with 4 additions and 1 deletions
|
@ -15,5 +15,6 @@ export default (action, delay=1e3) => {
|
||||||
func.cancel()
|
func.cancel()
|
||||||
return action(...args)
|
return action(...args)
|
||||||
}
|
}
|
||||||
|
Object.defineProperty(func, "running", {get() {return Boolean(timeout)}})
|
||||||
return func
|
return func
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,12 +41,14 @@
|
||||||
|
|
||||||
<h2>Methods</h2>
|
<h2>Methods</h2>
|
||||||
<p>
|
<p>
|
||||||
The returned wrapper function has two methods:
|
The returned wrapper function has the following methods and properties:
|
||||||
<dl>
|
<dl>
|
||||||
<dt><code>cancel()</code></dt>
|
<dt><code>cancel()</code></dt>
|
||||||
<dd>Cancels the running timeout without calling the target function.</dd>
|
<dd>Cancels the running timeout without calling the target function.</dd>
|
||||||
<dt><code>now(...)</code></dt>
|
<dt><code>now(...)</code></dt>
|
||||||
<dd>Cancels the running timeout and calls the target function immediately.</dd>
|
<dd>Cancels the running timeout and calls the target function immediately.</dd>
|
||||||
|
<dt><code>running</code></dt>
|
||||||
|
<dd><code>true</code> if there is a timeout currently running, <code>false</code> otherwise.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
Loading…
Reference in a new issue