export default function debounce(func, wait, immediate = false) {
  var timeout;
  return function (...arg) {
    var context = this; // var args = arguments;

    var later = function () {
      timeout = null;
      if (!immediate) func.apply(context, arg);
    };

    var callNow = immediate && !timeout;
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
    if (callNow) func.apply(context, arg);
  };
}