1 line
9.0 KiB
JSON
1 line
9.0 KiB
JSON
|
{"ast":null,"code":"require(\"core-js/modules/es.number.constructor.js\");\n\n/* eslint-disable no-undefined,no-param-reassign,no-shadow */\n\n/**\n * Throttle execution of a function. Especially useful for rate limiting\n * execution of handlers on events like resize and scroll.\n *\n * @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.\n * @param {Boolean} [noTrailing] Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the\n * throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time\n * after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,\n * the internal counter is reset)\n * @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,\n * to `callback` when the throttled-function is executed.\n * @param {Boolean} [debounceMode] If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),\n * schedule `callback` to execute after `delay` ms.\n *\n * @return {Function} A new, throttled, function.\n */\nmodule.exports = function (delay, noTrailing, callback, debounceMode) {\n // After wrapper has stopped being called, this timeout ensures that\n // `callback` is executed at the proper times in `throttle` and `end`\n // debounce modes.\n var timeoutID; // Keep track of the last time `callback` was executed.\n\n var lastExec = 0; // `noTrailing` defaults to falsy.\n\n if (typeof noTrailing !== 'boolean') {\n debounceMode = callback;\n callback = noTrailing;\n noTrailing = undefined;\n } // The `wrapper` function encapsulates all of the throttling / debouncing\n // functionality and when executed will limit the rate at which `callback`\n // is executed.\n\n\n function wrapper() {\n var self = this;\n var elapsed = Number(new Date()) - lastExec;\n var args = arguments; // Execute `callback` and update the `lastExec` timestamp.\n\n function exec() {\n lastExec = Number(new Date());\n callback.apply(self, args);\n } // If `debounceMode` is true (at begin) this is used to clear the flag\n // to allow future `callback` executions.\n\n\n function clear() {\n timeoutID = undefined;\n }\n\n if (debounceMode && !timeoutID) {\n // Since `wrapper` is being called for the first time and\n // `debounceMode` is true (at begin), execute `callback`.\n exec();\n } // Clear any existing timeout.\n\n\n if (timeoutID) {\n clearTimeout(timeoutID);\n }\n\n if (debounceMode === undefined && elapsed > delay) {\n // In throttle mode, if `delay` time has been exceeded, execute\n // `callback`.\n exec();\n } else if (noTrailing !== true) {\n // In trailing throttle mode, since `delay` time has not been\n // exceeded, schedule `callback` to execute `delay` ms after most\n // recent execution.\n //\n // If `debounceMode` is true (at begin), schedule `clear` to execute\n // after `delay` ms.\n //\n // If `debounceMode` is false (at end), schedule `callback` to\n // execute after `delay` ms.\n timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);\n }\n } // Return the wrapper function.\n\n\n return wrapper;\n};","map":{"version":3,"sources":["D:/Work/WorkSpace/GitWorkSpace/TenShop/resource/ElectronicMall/src/ElectronicMallVue/node_modules/throttle-debounce/throttle.js"],"names":["module","exports","delay","noTrailing","callback","debounceMode","timeoutID","lastExec","undefined","wrapper","self","elapsed","Number","Date","args","
|