vue-debounce
Version:
A simple vue directive for debounce
2 lines (1 loc) • 606 B
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).debounce=n()}(this,(function(){"use strict";return function(e,n){let t=null;const o="number"==typeof n?n:function(e){const[n,t="ms"]=String(e).split(/(ms|s)/i);return Number(n)*{ms:1,s:1e3}[t]}(n),i=function(){for(var n=arguments.length,i=new Array(n),u=0;u<n;u++)i[u]=arguments[u];clearTimeout(t),t=setTimeout((()=>{t=null,e.apply(this,i)}),o),t||e.apply(this,i)};return i.cancel=()=>{clearTimeout(t),t=null},i}}));