UNPKG

react-throttle

Version:

Throttles/debounces handlers of a child element

32 lines (25 loc) 805 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = throttle; var _lodash = require('lodash'); var _debounce = require('./debounce'); var _debounce2 = _interopRequireDefault(_debounce); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function throttle(func, wait, options) { var leading = true, trailing = true; if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } if ((0, _lodash.isObject)(options)) { leading = 'leading' in options ? !!options.leading : leading; trailing = 'trailing' in options ? !!options.trailing : trailing; } return (0, _debounce2.default)(func, wait, { 'leading': leading, 'maxWait': wait, 'trailing': trailing }); }