UNPKG

vuikit

Version:

A Vuejs component library based on UIkit

33 lines (28 loc) 745 B
/** * Vuikit 0.7.0 * (c) 2018 Miljan Aleksic * @license MIT */ /** * Returns a function, that, as long as it continues to be invoked, will not * be triggered. The function will be called after it stops being called for * N milliseconds. If `immediate` is passed, trigger the function on the * leading edge, instead of the trailing. */ export default function (fn, wait, immediate) { var timeout return function () { var context = this var args = arguments var later = function () { timeout = null if (!immediate) fn.apply(context, args) } var callNow = immediate && !timeout clearTimeout(timeout) timeout = setTimeout(later, wait) if (callNow) { fn.apply(context, args) } } }