@mightyplow/jslib
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| /** | ||
| * Creates a function which debounces with the given timeout and resets the timer | ||
| * on every function call. | ||
| * | ||
| * The returned debounced function has a function property abort() which aborts the timer. | ||
| * | ||
| * @memberOf function | ||
| * @function | ||
| * @param {function} fn | ||
| * @param {number} timeout | ||
| * @return {function(...[*])} | ||
| */ | ||
| exports.default = function (fn) { | ||
| var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
| var timer = null; | ||
| var abortTimer = function abortTimer() { | ||
| return clearTimeout(timer); | ||
| }; | ||
| var debouncedFunction = function debouncedFunction() { | ||
| for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
| args[_key] = arguments[_key]; | ||
| } | ||
| abortTimer(); | ||
| timer = setTimeout(function () { | ||
| return fn.apply(undefined, args); | ||
| }, timeout); | ||
| }; | ||
| debouncedFunction.abort = abortTimer; | ||
| return debouncedFunction; | ||
| }; |
@@ -43,2 +43,11 @@ 'use strict'; | ||
| var _debounce = require('./debounce'); | ||
| Object.defineProperty(exports, 'debounce', { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _interopRequireDefault(_debounce).default; | ||
| } | ||
| }); | ||
| var _enqueue = require('./enqueue'); | ||
@@ -45,0 +54,0 @@ |
+2
-3
@@ -8,5 +8,4 @@ "use strict"; | ||
| * @memberOf function | ||
| * @function | ||
| */ | ||
| var noop = Function.prototype; | ||
| exports.default = noop; | ||
| exports.default = Function.prototype; |
+6
-0
@@ -84,2 +84,8 @@ 'use strict'; | ||
| }); | ||
| Object.defineProperty(exports, 'debounce', { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _function.debounce; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, 'enqueueWithResults', { | ||
@@ -86,0 +92,0 @@ enumerable: true, |
+1
-1
| { | ||
| "name": "@mightyplow/jslib", | ||
| "version": "0.16.0", | ||
| "version": "0.17.0", | ||
| "description": "js helpers library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
+21
-5
@@ -119,9 +119,10 @@ ## Objects | ||
| * [.enqueueWithResults](#function.enqueueWithResults) ⇒ | ||
| * [.noop](#function.noop) | ||
| * [.argsToArray(fn)](#function.argsToArray) ⇒ [<code>function</code>](#function) | ||
| * [.checkTypes()](#function.checkTypes) | ||
| * [.curry(fn)](#function.curry) ⇒ <code>curried</code> | ||
| * [.module.exports(fn, timeout)](#function.module.exports) ⇒ [<code>function</code>](#function) | ||
| * [.enqueue(promiseGenerators)](#function.enqueue) ⇒ | ||
| * [.indentity(arg)](#function.indentity) | ||
| * [.memoize(fn, [timeout])](#function.memoize) ⇒ [<code>function</code>](#function) | ||
| * [.module.exports()](#function.module.exports) | ||
| * [.promisify(fn, context)](#function.promisify) | ||
@@ -146,6 +147,2 @@ | ||
| <a name="function.noop"></a> | ||
| ### function.noop | ||
| **Kind**: static constant of [<code>function</code>](#function) | ||
| <a name="function.argsToArray"></a> | ||
@@ -173,2 +170,17 @@ | ||
| <a name="function.module.exports"></a> | ||
| ### function.module.exports(fn, timeout) ⇒ [<code>function</code>](#function) | ||
| Creates a function which debounces with the given timeout and resets the timer | ||
| on every function call. | ||
| The returned debounced function has a function property abort() which aborts the timer. | ||
| **Kind**: static method of [<code>function</code>](#function) | ||
| | Param | Type | | ||
| | --- | --- | | ||
| | fn | [<code>function</code>](#function) | | ||
| | timeout | <code>number</code> | | ||
| <a name="function.enqueue"></a> | ||
@@ -207,2 +219,6 @@ | ||
| <a name="function.module.exports"></a> | ||
| ### function.module.exports() | ||
| **Kind**: static method of [<code>function</code>](#function) | ||
| <a name="function.promisify"></a> | ||
@@ -209,0 +225,0 @@ |
48404
4.37%43
2.38%1164
4.11%416
4%