Compare commits
6 Commits
68589e968c
...
81d208b964
| Author | SHA1 | Date | |
|---|---|---|---|
| 81d208b964 | |||
| 4590d0924f | |||
| cef9bf9b97 | |||
| 4ae317e36d | |||
| e8f1f534be | |||
| 69cb4416f2 |
@@ -33,4 +33,4 @@
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/export function damper(e,p=300,t){let s;return(...i)=>new Promise(((r,u)=>{clearTimeout(s),"number"==typeof t&&i[t]?("number"==typeof t&&(i=[...i.splice(0,t),...i.splice(t+1)]),i.push(r,u),e.apply(this,i)):("number"==typeof t&&(i=[...i.splice(0,t),...i.splice(t+1)]),i.push(r,u),s=setTimeout((()=>e.apply(this,i)),p))}))}
|
||||
*/export default function damper(e,p=300,t){let s;return(...i)=>new Promise(((r,u)=>{clearTimeout(s),"number"==typeof t&&i[t]?("number"==typeof t&&(i=[...Array.from(i).splice(0,t),...Array.from(i).splice(t + 1)]),i.push(r,u),e.apply(this,i)):("number"==typeof t&&(i=[...Array.from(i).splice(0,t),...Array.from(i).splice(t + 1)]),i.push(r,u),s=setTimeout((()=>e.apply(this,i)),p))}))}
|
||||
10
damper.mjs
10
damper.mjs
@@ -35,7 +35,7 @@
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
export function damper(func, timeout = 300, force) {
|
||||
export default function damper(func, timeout = 300, force) {
|
||||
// Declaring the timer for executing the function
|
||||
let timer;
|
||||
|
||||
@@ -49,8 +49,8 @@ export function damper(func, timeout = 300, force) {
|
||||
|
||||
// Deleting the force argument
|
||||
if (typeof force === "number") args = [
|
||||
...args.splice(0, force),
|
||||
...args.splice(force + 1)
|
||||
...Array.from(args).splice(0, force),
|
||||
...Array.from(args).splice(force + 1)
|
||||
];
|
||||
|
||||
// Writing promise handlers into the arguments variable
|
||||
@@ -63,8 +63,8 @@ export function damper(func, timeout = 300, force) {
|
||||
|
||||
// Deleting the force argument
|
||||
if (typeof force === "number") args = [
|
||||
...args.splice(0, force),
|
||||
...args.splice(force + 1)
|
||||
...Array.from(args).splice(0, force),
|
||||
...Array.from(args).splice(force + 1)
|
||||
];
|
||||
|
||||
// Writing promise handlers into the arguments variable
|
||||
|
||||
Reference in New Issue
Block a user