mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Attempt to throttle seData.
This commit is contained in:
29
lodash.js
29
lodash.js
@@ -3015,13 +3015,13 @@
|
|||||||
* @param {*} data The metadata.
|
* @param {*} data The metadata.
|
||||||
* @returns {Function} Returns `func`.
|
* @returns {Function} Returns `func`.
|
||||||
*/
|
*/
|
||||||
function setData(func, data) {
|
function baseSetData(func, data) {
|
||||||
metaMap.set(func, data);
|
metaMap.set(func, data);
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
// fallback for environments without `WeakMap`
|
// fallback for environments without `WeakMap`
|
||||||
if (!WeakMap) {
|
if (!WeakMap) {
|
||||||
setData = !defineProperty ? identity : function(func, value) {
|
baseSetData = !defineProperty ? identity : function(func, value) {
|
||||||
descriptor.value = value;
|
descriptor.value = value;
|
||||||
defineProperty(func, EXPANDO, descriptor);
|
defineProperty(func, EXPANDO, descriptor);
|
||||||
descriptor.value = null;
|
descriptor.value = null;
|
||||||
@@ -3029,6 +3029,31 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trip(func, times, wait) {
|
||||||
|
var count = 0,
|
||||||
|
lastCalled = 0;
|
||||||
|
|
||||||
|
return function(key, value) {
|
||||||
|
var stamp = now ? now() : 0,
|
||||||
|
remaining = wait - (stamp - lastCalled);
|
||||||
|
|
||||||
|
lastCalled = stamp;
|
||||||
|
if (remaining > 0) {
|
||||||
|
if (++count > times) {
|
||||||
|
var dataFunc = typeof value == 'object' && isFunction(dataFunc = value[0]) && dataFunc;
|
||||||
|
if (typeof getData(key) == 'undefined' && !(dataFunc && getData(dataFunc) != 'undefined')) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
return func(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var setData = trip(baseSetData, 50, 16);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fallback implementation of `_.isPlainObject` which checks if `value`
|
* A fallback implementation of `_.isPlainObject` which checks if `value`
|
||||||
* is an object created by the `Object` constructor or has a `[[Prototype]]`
|
* is an object created by the `Object` constructor or has a `[[Prototype]]`
|
||||||
|
|||||||
Reference in New Issue
Block a user