UNPKG

@zippytech/react-notify-resize

Version:

React Component that notifies you whenever it is resized

62 lines (52 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Copyright (c) 2015-present, Zippy Technologies * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ function debounce(func, wait) { var _this = this; var immediate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var timeout = void 0; var args = void 0; var context = void 0; var timestamp = void 0; var result = void 0; var later = function later() { var last = Date.now() - timestamp; if (last < wait && last >= 0) { timeout = setTimeout(later, wait - last); } else { timeout = null; if (!immediate) { result = func.apply(context, args); if (!timeout) { context = null; args = null; } } } }; return function () { for (var _len = arguments.length, internalArgs = Array(_len), _key = 0; _key < _len; _key++) { internalArgs[_key] = arguments[_key]; } var callNow = immediate && !timeout; context = _this; args = internalArgs; timestamp = Date.now(); if (!timeout) { timeout = setTimeout(later, wait); } if (callNow) { result = func.apply(context, args); context = args = null; } return result; }; } exports.default = debounce;