'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var debounce = _interopDefault(require('./debounce'));

/**
 * 节流函数，目标函数在一个时间段之内只能被调用一次
 * @param {Function} func 目标函数
 * @param {number} wait 节流时间
 * @param {boolean} immediate 是否立即调用，默认：true
 * @param {boolean} lastcall 结束后是否需要调用，默认：true
 * @returns {Function}
 *
 * const logNum = throttle(() => console.log('called'), 1000);
 *
 * // 间隔200毫秒调一次，共调用20次，但只会打印4次'called'
 * let callTimes = 0;
 * const timer = setInterval(() => {
 *   console.log('callTimes', ++callTimes);
 *   logNum();
 * }, 200);
 * setTimeout(() => clearInterval(timer), 4000);
 */
function throttle(func, wait, immediate, lastcall) {
  return debounce(func, wait, immediate, lastcall, true);
}

module.exports = throttle;
