lodash.debounce
Advanced tools
Comparing version 3.1.1 to 4.0.0
180
index.js
/** | ||
* lodash 3.1.1 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modern modularize exports="npm" -o ./` | ||
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/> | ||
* lodash 4.0.0 (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
* Available under MIT license <https://lodash.com/license> | ||
*/ | ||
var getNative = require('lodash._getnative'); | ||
@@ -14,13 +13,45 @@ /** Used as the `TypeError` message for "Functions" methods. */ | ||
/* Native method references for those with the same name as other `lodash` methods. */ | ||
var nativeMax = Math.max, | ||
nativeNow = getNative(Date, 'now'); | ||
/** Used as references for various `Number` constants. */ | ||
var NAN = 0 / 0; | ||
/** `Object#toString` result references. */ | ||
var funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]'; | ||
/** Used to match leading and trailing whitespace. */ | ||
var reTrim = /^\s+|\s+$/g; | ||
/** Used to detect bad signed hexadecimal string values. */ | ||
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; | ||
/** Used to detect binary string values. */ | ||
var reIsBinary = /^0b[01]+$/i; | ||
/** Used to detect octal string values. */ | ||
var reIsOctal = /^0o[0-7]+$/i; | ||
/** Built-in method references without a dependency on `global`. */ | ||
var freeParseInt = parseInt; | ||
/** Used for built-in method references. */ | ||
var objectProto = global.Object.prototype; | ||
/** | ||
* Gets the number of milliseconds that have elapsed since the Unix epoch | ||
* (1 January 1970 00:00:00 UTC). | ||
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString = objectProto.toString; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeMax = Math.max; | ||
/** | ||
* Gets the timestamp of the number of milliseconds that have elapsed since | ||
* the Unix epoch (1 January 1970 00:00:00 UTC). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @type Function | ||
* @category Date | ||
* @returns {number} Returns the timestamp. | ||
* @example | ||
@@ -33,5 +64,3 @@ * | ||
*/ | ||
var now = nativeNow || function() { | ||
return new Date().getTime(); | ||
}; | ||
var now = Date.now; | ||
@@ -42,6 +71,7 @@ /** | ||
* invoked. The debounced function comes with a `cancel` method to cancel | ||
* delayed invocations. Provide an options object to indicate that `func` | ||
* should be invoked on the leading and/or trailing edge of the `wait` timeout. | ||
* Subsequent calls to the debounced function return the result of the last | ||
* `func` invocation. | ||
* delayed `func` invocations and a `flush` method to immediately invoke them. | ||
* Provide an options object to indicate whether `func` should be invoked on | ||
* the leading and/or trailing edge of the `wait` timeout. The `func` is invoked | ||
* with the last arguments provided to the debounced function. Subsequent calls | ||
* to the debounced function return the result of the last `func` invocation. | ||
* | ||
@@ -64,3 +94,3 @@ * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked | ||
* @param {number} [options.maxWait] The maximum time `func` is allowed to be | ||
* delayed before it is invoked. | ||
* delayed before it's invoked. | ||
* @param {boolean} [options.trailing=true] Specify invoking on the trailing | ||
@@ -74,4 +104,4 @@ * edge of the timeout. | ||
* | ||
* // invoke `sendMail` when the click event is fired, debouncing subsequent calls | ||
* jQuery('#postbox').on('click', _.debounce(sendMail, 300, { | ||
* // invoke `sendMail` when clicked, debouncing subsequent calls | ||
* jQuery(element).on('click', _.debounce(sendMail, 300, { | ||
* 'leading': true, | ||
@@ -82,23 +112,8 @@ * 'trailing': false | ||
* // ensure `batchLog` is invoked once after 1 second of debounced calls | ||
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); | ||
* var source = new EventSource('/stream'); | ||
* jQuery(source).on('message', _.debounce(batchLog, 250, { | ||
* 'maxWait': 1000 | ||
* })); | ||
* jQuery(source).on('message', debounced); | ||
* | ||
* // cancel a debounced call | ||
* var todoChanges = _.debounce(batchLog, 1000); | ||
* Object.observe(models.todo, todoChanges); | ||
* | ||
* Object.observe(models, function(changes) { | ||
* if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) { | ||
* todoChanges.cancel(); | ||
* } | ||
* }, ['delete']); | ||
* | ||
* // ...at some point `models.todo` is changed | ||
* models.todo.completed = true; | ||
* | ||
* // ...before 1 second has passed `models.todo` is deleted | ||
* // which cancels the debounced `todoChanges` call | ||
* delete models.todo; | ||
* // cancel a trailing debounced invocation | ||
* jQuery(window).on('popstate', debounced.cancel); | ||
*/ | ||
@@ -114,2 +129,3 @@ function debounce(func, wait, options) { | ||
lastCalled = 0, | ||
leading = false, | ||
maxWait = false, | ||
@@ -121,9 +137,6 @@ trailing = true; | ||
} | ||
wait = wait < 0 ? 0 : (+wait || 0); | ||
if (options === true) { | ||
var leading = true; | ||
trailing = false; | ||
} else if (isObject(options)) { | ||
wait = toNumber(wait) || 0; | ||
if (isObject(options)) { | ||
leading = !!options.leading; | ||
maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait); | ||
maxWait = 'maxWait' in options && nativeMax(toNumber(options.maxWait) || 0, wait); | ||
trailing = 'trailing' in options ? !!options.trailing : trailing; | ||
@@ -140,3 +153,3 @@ } | ||
lastCalled = 0; | ||
maxTimeoutId = timeoutId = trailingCall = undefined; | ||
args = maxTimeoutId = thisArg = timeoutId = trailingCall = undefined; | ||
} | ||
@@ -167,2 +180,10 @@ | ||
function flush() { | ||
if ((timeoutId && trailingCall) || (maxTimeoutId && trailing)) { | ||
result = func.apply(thisArg, args); | ||
} | ||
cancel(); | ||
return result; | ||
} | ||
function maxDelayed() { | ||
@@ -214,2 +235,3 @@ complete(trailing, timeoutId); | ||
debounced.cancel = cancel; | ||
debounced.flush = flush; | ||
return debounced; | ||
@@ -219,2 +241,26 @@ } | ||
/** | ||
* Checks if `value` is classified as a `Function` object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. | ||
* @example | ||
* | ||
* _.isFunction(_); | ||
* // => true | ||
* | ||
* _.isFunction(/abc/); | ||
* // => false | ||
*/ | ||
function isFunction(value) { | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8 which returns 'object' for typed array constructors, and | ||
// PhantomJS 1.9 which returns 'function' for `NodeList` instances. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
} | ||
/** | ||
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. | ||
@@ -236,3 +282,6 @@ * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* _.isObject(1); | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
@@ -247,2 +296,39 @@ */ | ||
/** | ||
* Converts `value` to a number. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @category Lang | ||
* @param {*} value The value to process. | ||
* @returns {number} Returns the number. | ||
* @example | ||
* | ||
* _.toNumber(3); | ||
* // => 3 | ||
* | ||
* _.toNumber(Number.MIN_VALUE); | ||
* // => 5e-324 | ||
* | ||
* _.toNumber(Infinity); | ||
* // => Infinity | ||
* | ||
* _.toNumber('3'); | ||
* // => 3 | ||
*/ | ||
function toNumber(value) { | ||
if (isObject(value)) { | ||
var other = isFunction(value.valueOf) ? value.valueOf() : value; | ||
value = isObject(other) ? (other + '') : other; | ||
} | ||
if (typeof value != 'string') { | ||
return value === 0 ? value : +value; | ||
} | ||
value = value.replace(reTrim, ''); | ||
var isBinary = reIsBinary.test(value); | ||
return (isBinary || reIsOctal.test(value)) | ||
? freeParseInt(value.slice(2), isBinary ? 2 : 8) | ||
: (reIsBadHex.test(value) ? NAN : +value); | ||
} | ||
module.exports = debounce; |
{ | ||
"name": "lodash.debounce", | ||
"version": "3.1.1", | ||
"description": "The modern build of lodash’s `_.debounce` as a module.", | ||
"version": "4.0.0", | ||
"description": "The lodash method `_.debounce` exported as a module.", | ||
"homepage": "https://lodash.com/", | ||
"icon": "https://lodash.com/icon.svg", | ||
"license": "MIT", | ||
"keywords": "lodash, lodash-modularized, stdlib, util", | ||
"keywords": "lodash, lodash-modularized, stdlib, util, debounce", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"contributors": [ | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (http://www.iceddev.com/)", | ||
"Kit Cambridge <github@kitcambridge.be> (http://kitcambridge.be/)", | ||
"Blaine Bublitz <blaine@iceddev.com> (https://github.com/phated)", | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
], | ||
"repository": "lodash/lodash", | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }, | ||
"dependencies": { | ||
"lodash._getnative": "^3.0.0" | ||
} | ||
"scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.debounce v3.1.1 | ||
# lodash.debounce v4.0.0 | ||
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.debounce` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module. | ||
The [lodash](https://lodash.com/) method `_.debounce` exported as a [Node.js](https://nodejs.org/) module. | ||
@@ -8,3 +8,2 @@ ## Installation | ||
Using npm: | ||
```bash | ||
@@ -15,4 +14,3 @@ $ {sudo -H} npm i -g npm | ||
In Node.js/io.js: | ||
In Node.js: | ||
```js | ||
@@ -22,2 +20,2 @@ var debounce = require('lodash.debounce'); | ||
See the [documentation](https://lodash.com/docs#debounce) or [package source](https://github.com/lodash/lodash/blob/3.1.1-npm-packages/lodash.debounce) for more details. | ||
See the [documentation](https://lodash.com/docs#debounce) or [package source](https://github.com/lodash/lodash/blob/4.0.0-npm-packages/lodash.debounce) for more details. |
Sorry, the diff of this file is not supported yet
11809
0
294
19
- Removedlodash._getnative@^3.0.0
- Removedlodash._getnative@3.9.1(transitive)