UNPKG

vue-debounce-component

Version:
2 lines (1 loc) 1.01 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).vueDebounce=t()}(this,function(){"use strict";function r(o,e){void 0===e&&(e=300);var i=function(e){var t=String(e).split(/(ms|s)/i),n=t[0],o=t[1],i=void 0===o?"ms":o;return Number(n)*{ms:1,s:1e3}[i]}(String(e)),s=void 0;return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=this;clearTimeout(s),s=setTimeout(function(){o.apply(n,e)},i)}}var t={name:"debounce",props:["timeout","events"],data:function(){return{eventsKeys:[]}},created:function(){this.eventsKeys=Array.isArray(this.events)?this.events:[this.events]},render:function(){var o=this,e=this.$slots.default[0],i={},s={};return e.componentOptions&&(i=e.componentOptions.listeners),e.data&&e.data.on&&(s=e.data.on),this.eventsKeys.forEach(function(e){var t=i[e],n=s[e];t?i[e]=r(t,o.timeout):n&&(s[e]=r(n,o.timeout))}),e}};return{install:function(e){e.component("Debounce",t)}}});