mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Add baseCreateCallback to avoid circular deps add more varDeps to fix large array caching.
Former-commit-id: f8164bbff59a3ad294c5670693942dc56a1c88a5
This commit is contained in:
98
build.js
98
build.js
@@ -110,13 +110,13 @@
|
|||||||
'bind': ['createBound'],
|
'bind': ['createBound'],
|
||||||
'bindAll': ['baseFlatten', 'bind', 'functions'],
|
'bindAll': ['baseFlatten', 'bind', 'functions'],
|
||||||
'bindKey': ['createBound'],
|
'bindKey': ['createBound'],
|
||||||
'clone': ['baseClone', 'createCallback'],
|
'clone': ['baseClone', 'baseCreateCallback'],
|
||||||
'cloneDeep': ['baseClone', 'createCallback'],
|
'cloneDeep': ['baseClone', 'baseCreateCallback'],
|
||||||
'compact': [],
|
'compact': [],
|
||||||
'compose': [],
|
'compose': [],
|
||||||
'contains': ['baseEach', 'getIndexOf', 'isString'],
|
'contains': ['baseEach', 'getIndexOf', 'isString'],
|
||||||
'countBy': ['createAggregator'],
|
'countBy': ['createAggregator'],
|
||||||
'createCallback': ['baseIsEqual', 'bind', 'identity', 'isObject', 'keys', 'setBindData'],
|
'createCallback': ['baseCreateCallback', 'baseIsEqual', 'isObject', 'keys'],
|
||||||
'debounce': ['isObject'],
|
'debounce': ['isObject'],
|
||||||
'defaults': ['createIterator'],
|
'defaults': ['createIterator'],
|
||||||
'defer': ['bind'],
|
'defer': ['bind'],
|
||||||
@@ -133,12 +133,12 @@
|
|||||||
'findLastKey': ['createCallback', 'forOwnRight'],
|
'findLastKey': ['createCallback', 'forOwnRight'],
|
||||||
'first': ['createCallback', 'slice'],
|
'first': ['createCallback', 'slice'],
|
||||||
'flatten': ['baseFlatten', 'map'],
|
'flatten': ['baseFlatten', 'map'],
|
||||||
'forEach': ['baseEach', 'createCallback', 'isArray'],
|
'forEach': ['baseCreateCallback', 'baseEach', 'isArray'],
|
||||||
'forEachRight': ['createCallback', 'forEach', 'isString', 'keys'],
|
'forEachRight': ['baseCreateCallback', 'forEach', 'isString', 'keys'],
|
||||||
'forIn': ['createIterator'],
|
'forIn': ['createIterator'],
|
||||||
'forInRight': ['createCallback', 'forIn'],
|
'forInRight': ['baseCreateCallback', 'forIn'],
|
||||||
'forOwn': ['createIterator'],
|
'forOwn': ['createIterator'],
|
||||||
'forOwnRight': ['createCallback', 'keys'],
|
'forOwnRight': ['baseCreateCallback', 'keys'],
|
||||||
'functions': ['forIn', 'isFunction'],
|
'functions': ['forIn', 'isFunction'],
|
||||||
'groupBy': ['createAggregator'],
|
'groupBy': ['createAggregator'],
|
||||||
'has': [],
|
'has': [],
|
||||||
@@ -155,7 +155,7 @@
|
|||||||
'isDate': [],
|
'isDate': [],
|
||||||
'isElement': [],
|
'isElement': [],
|
||||||
'isEmpty': ['forOwn', 'isArguments', 'isFunction'],
|
'isEmpty': ['forOwn', 'isArguments', 'isFunction'],
|
||||||
'isEqual': ['baseIsEqual', 'createCallback'],
|
'isEqual': ['baseCreateCallback', 'baseIsEqual'],
|
||||||
'isFinite': [],
|
'isFinite': [],
|
||||||
'isFunction': [],
|
'isFunction': [],
|
||||||
'isNaN': ['isNumber'],
|
'isNaN': ['isNumber'],
|
||||||
@@ -172,7 +172,7 @@
|
|||||||
'map': ['baseEach', 'createCallback', 'isArray'],
|
'map': ['baseEach', 'createCallback', 'isArray'],
|
||||||
'max': ['baseEach', 'charAtCallback', 'createCallback', 'isArray', 'isString'],
|
'max': ['baseEach', 'charAtCallback', 'createCallback', 'isArray', 'isString'],
|
||||||
'memoize': [],
|
'memoize': [],
|
||||||
'merge': ['baseMerge', 'createCallback', 'getArray', 'isObject', 'releaseArray'],
|
'merge': ['baseCreateCallback', 'baseMerge', 'getArray', 'isObject', 'releaseArray'],
|
||||||
'min': ['baseEach', 'charAtCallback', 'createCallback', 'isArray', 'isString'],
|
'min': ['baseEach', 'charAtCallback', 'createCallback', 'isArray', 'isString'],
|
||||||
'mixin': ['forEach', 'functions', 'isFunction'],
|
'mixin': ['forEach', 'functions', 'isFunction'],
|
||||||
'noConflict': [],
|
'noConflict': [],
|
||||||
@@ -187,8 +187,8 @@
|
|||||||
'pull': [],
|
'pull': [],
|
||||||
'random': [],
|
'random': [],
|
||||||
'range': [],
|
'range': [],
|
||||||
'reduce': ['baseEach', 'createCallback', 'isArray'],
|
'reduce': ['baseCreateCallback', 'baseEach', 'isArray'],
|
||||||
'reduceRight': ['createCallback', 'forEachRight'],
|
'reduceRight': ['baseCreateCallback', 'forEachRight'],
|
||||||
'reject': ['createCallback', 'filter'],
|
'reject': ['createCallback', 'filter'],
|
||||||
'remove': ['baseEach', 'createCallback', 'isArray'],
|
'remove': ['baseEach', 'createCallback', 'isArray'],
|
||||||
'rest': ['createCallback', 'slice'],
|
'rest': ['createCallback', 'slice'],
|
||||||
@@ -202,9 +202,9 @@
|
|||||||
'tap': ['value'],
|
'tap': ['value'],
|
||||||
'template': ['defaults', 'escape', 'escapeStringChar', 'keys', 'values'],
|
'template': ['defaults', 'escape', 'escapeStringChar', 'keys', 'values'],
|
||||||
'throttle': ['debounce', 'getObject', 'isObject', 'releaseObject'],
|
'throttle': ['debounce', 'getObject', 'isObject', 'releaseObject'],
|
||||||
'times': ['createCallback'],
|
'times': ['baseCreateCallback'],
|
||||||
'toArray': ['isString', 'slice', 'values'],
|
'toArray': ['isString', 'slice', 'values'],
|
||||||
'transform': ['createCallback', 'createObject', 'forOwn', 'isArray'],
|
'transform': ['baseCreateCallback', 'createObject', 'forOwn', 'isArray'],
|
||||||
'unescape': ['keys', 'unescapeHtmlChar'],
|
'unescape': ['keys', 'unescapeHtmlChar'],
|
||||||
'union': ['baseFlatten', 'baseUniq'],
|
'union': ['baseFlatten', 'baseUniq'],
|
||||||
'uniq': ['baseUniq', 'createCallback'],
|
'uniq': ['baseUniq', 'createCallback'],
|
||||||
@@ -219,6 +219,7 @@
|
|||||||
|
|
||||||
// private functions
|
// private functions
|
||||||
'baseClone': ['assign', 'baseEach', 'forOwn', 'getArray', 'isArray', 'isObject', 'isNode', 'releaseArray', 'slice'],
|
'baseClone': ['assign', 'baseEach', 'forOwn', 'getArray', 'isArray', 'isObject', 'isNode', 'releaseArray', 'slice'],
|
||||||
|
'baseCreateCallback': ['bind', 'identity', 'setBindData'],
|
||||||
'baseEach': ['createIterator'],
|
'baseEach': ['createIterator'],
|
||||||
'baseFlatten': ['isArguments', 'isArray'],
|
'baseFlatten': ['isArguments', 'isArray'],
|
||||||
'baseIndexOf': [],
|
'baseIndexOf': [],
|
||||||
@@ -232,7 +233,7 @@
|
|||||||
'createAggregator': ['createCallback', 'forEach'],
|
'createAggregator': ['createCallback', 'forEach'],
|
||||||
'createBound': ['createObject', 'isFunction', 'isObject', 'setBindData'],
|
'createBound': ['createObject', 'isFunction', 'isObject', 'setBindData'],
|
||||||
'createCache': ['cachePush', 'getObject', 'releaseObject'],
|
'createCache': ['cachePush', 'getObject', 'releaseObject'],
|
||||||
'createIterator': ['getObject', 'isArguments', 'isArray', 'isString', 'iteratorTemplate', 'lodash', 'releaseObject'],
|
'createIterator': ['baseCreateCallback', 'getObject', 'isArguments', 'isArray', 'isString', 'iteratorTemplate', 'releaseObject'],
|
||||||
'createObject': [ 'isObject', 'noop'],
|
'createObject': [ 'isObject', 'noop'],
|
||||||
'escapeHtmlChar': [],
|
'escapeHtmlChar': [],
|
||||||
'escapeStringChar': [],
|
'escapeStringChar': [],
|
||||||
@@ -283,24 +284,34 @@
|
|||||||
'assign': ['defaultsIteratorOptions'],
|
'assign': ['defaultsIteratorOptions'],
|
||||||
'baseEach': ['eachIteratorOptions'],
|
'baseEach': ['eachIteratorOptions'],
|
||||||
'baseIsEqual': ['objectTypes'],
|
'baseIsEqual': ['objectTypes'],
|
||||||
|
'baseUniq': ['largeArraySize'],
|
||||||
'bind': ['reNative'],
|
'bind': ['reNative'],
|
||||||
|
'cacheIndexOf': ['keyPrefix'],
|
||||||
|
'cachePush': ['keyPrefix'],
|
||||||
'createIterator': ['indicatorObject', 'objectTypes'],
|
'createIterator': ['indicatorObject', 'objectTypes'],
|
||||||
'createBound': ['reNative'],
|
'createBound': ['reNative'],
|
||||||
'createObject': ['reNative'],
|
'createObject': ['reNative'],
|
||||||
'defaults': ['defaultsIteratorOptions'],
|
'defaults': ['defaultsIteratorOptions'],
|
||||||
'defer': ['objectTypes', 'reNative'],
|
'defer': ['objectTypes', 'reNative'],
|
||||||
|
'difference': ['largeArraySize'],
|
||||||
'escape': ['reUnescapedHtml'],
|
'escape': ['reUnescapedHtml'],
|
||||||
'escapeHtmlChar': ['htmlEscapes'],
|
'escapeHtmlChar': ['htmlEscapes'],
|
||||||
'forIn': ['eachIteratorOptions', 'forOwnIteratorOptions'],
|
'forIn': ['eachIteratorOptions', 'forOwnIteratorOptions'],
|
||||||
'forOwn': ['eachIteratorOptions', 'forOwnIteratorOptions'],
|
'forOwn': ['eachIteratorOptions', 'forOwnIteratorOptions'],
|
||||||
'forOwnIteratorOptions': ['eachIteratorOptions'],
|
'forOwnIteratorOptions': ['eachIteratorOptions'],
|
||||||
|
'getArray': ['arrayPool'],
|
||||||
|
'getObject': ['objectPool'],
|
||||||
'htmlUnescapes': ['htmlEscapes'],
|
'htmlUnescapes': ['htmlEscapes'],
|
||||||
|
'intersection': ['largeArraySize'],
|
||||||
'isArray': ['reNative'],
|
'isArray': ['reNative'],
|
||||||
'isObject': ['objectTypes'],
|
'isObject': ['objectTypes'],
|
||||||
'isPlainObject': ['reNative'],
|
'isPlainObject': ['reNative'],
|
||||||
'isRegExp': ['objectTypes'],
|
'isRegExp': ['objectTypes'],
|
||||||
'keys': ['reNative'],
|
'keys': ['reNative'],
|
||||||
|
'memoize': ['keyPrefix'],
|
||||||
'reEscapedHtml': ['htmlUnescapes'],
|
'reEscapedHtml': ['htmlUnescapes'],
|
||||||
|
'releaseArray': ['arrayPool', 'maxPoolSize'],
|
||||||
|
'releaseObject': ['maxPoolSize', 'objectPool'],
|
||||||
'reUnescapedHtml': ['htmlEscapes'],
|
'reUnescapedHtml': ['htmlEscapes'],
|
||||||
'setBindData': ['reNative'],
|
'setBindData': ['reNative'],
|
||||||
'support': ['reNative'],
|
'support': ['reNative'],
|
||||||
@@ -566,6 +577,7 @@
|
|||||||
/** List of private functions */
|
/** List of private functions */
|
||||||
var privateFuncs = [
|
var privateFuncs = [
|
||||||
'baseClone',
|
'baseClone',
|
||||||
|
'baseCreateCallback',
|
||||||
'baseEach',
|
'baseEach',
|
||||||
'baseFlatten',
|
'baseFlatten',
|
||||||
'baseIndexOf',
|
'baseIndexOf',
|
||||||
@@ -752,10 +764,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates modules for each of the specified `identifiers`.
|
* Creates modules based on the build state passed.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} state An array identifiers to modularize.
|
* @param {Object} state The build state object.
|
||||||
*/
|
*/
|
||||||
function buildModule(state) {
|
function buildModule(state) {
|
||||||
var buildFuncs = state.buildFuncs,
|
var buildFuncs = state.buildFuncs,
|
||||||
@@ -1614,8 +1626,8 @@
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove `__bindData__` logic and `setBindData` function calls from `_.createCallback`
|
// remove `__bindData__` logic and `setBindData` function calls from `baseCreateCallback`
|
||||||
source = source.replace(matchFunction(source, 'createCallback'), function(match) {
|
source = source.replace(matchFunction(source, 'baseCreateCallback'), function(match) {
|
||||||
return match
|
return match
|
||||||
.replace(/(?:\s*\/\/.*)*\n( *)var bindData *=[\s\S]+?\n\1}/, '')
|
.replace(/(?:\s*\/\/.*)*\n( *)var bindData *=[\s\S]+?\n\1}/, '')
|
||||||
.replace(/(?:\s*\/\/.*)*\n( *)if *\(bindData[\s\S]+?\n\1}/, '');
|
.replace(/(?:\s*\/\/.*)*\n( *)if *\(bindData[\s\S]+?\n\1}/, '');
|
||||||
@@ -1728,7 +1740,18 @@
|
|||||||
source = removeFunction(source, 'getIndexOf');
|
source = removeFunction(source, 'getIndexOf');
|
||||||
|
|
||||||
// replace all `getIndexOf` calls with `baseIndexOf`
|
// replace all `getIndexOf` calls with `baseIndexOf`
|
||||||
source = source.replace(/\bgetIndexOf\(\)/g, 'baseIndexOf');
|
_.each(['baseUniq', 'contains', 'difference', 'intersection', 'omit'], function(funcName) {
|
||||||
|
source = source.replace(matchFunction(source, funcName), function(match) {
|
||||||
|
return match.replace(/\bgetIndexOf\(\)/g, 'baseIndexOf');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// simplify `isLarge` assignments
|
||||||
|
_.each(['baseUniq', 'difference'], function(funcName) {
|
||||||
|
source = source.replace(matchFunction(source, funcName), function(match) {
|
||||||
|
return match.replace(/\b(largeArraySize).+?baseIndexOf\b/g, '$1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
@@ -2146,8 +2169,8 @@
|
|||||||
return match.replace(/^ *if *\(support\.unindexedChars[^}]+}\n+/m, '');
|
return match.replace(/^ *if *\(support\.unindexedChars[^}]+}\n+/m, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove `support.unindexedChars` from `_.reduceRight`
|
// remove `support.unindexedChars` from `_.forEachRight`
|
||||||
source = source.replace(matchFunction(source, 'reduceRight'), function(match) {
|
source = source.replace(matchFunction(source, 'forEachRight'), function(match) {
|
||||||
return match.replace(/}\s*else if *\(support\.unindexedChars[^}]+/, '');
|
return match.replace(/}\s*else if *\(support\.unindexedChars[^}]+/, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2723,7 +2746,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (isLegacy || isMobile || isUnderscore) {
|
if (isLegacy || isMobile || isUnderscore) {
|
||||||
_.each(['createBound', 'createCallback'], function(funcName) {
|
_.each(['baseCreateCallback', 'createBound'], function(funcName) {
|
||||||
_.pull(funcDepMap[funcName], 'setBindData');
|
_.pull(funcDepMap[funcName], 'setBindData');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2782,19 +2805,12 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each(['clone', 'isEqual', 'omit', 'pick'], function(funcName) {
|
_.each(['isEqual', 'omit', 'pick'], function(funcName) {
|
||||||
if (funcName == 'isEqual') {
|
if (funcName == 'isEqual'
|
||||||
if (isLodash('baseIsEqual') || isLodash('isEqual')) {
|
? (!isLodash('baseIsEqual') && !isLodash('isEqual'))
|
||||||
return;
|
: !isLodash(funcName)
|
||||||
}
|
) {
|
||||||
}
|
_.pull(funcDepMap[funcName], 'baseCreateCallback', 'createCallback');
|
||||||
if (funcName == 'clone') {
|
|
||||||
if (isLodash('baseClone') || isLodash('clone') || isLodash('cloneDeep')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!isLodash(funcName)) {
|
|
||||||
_.pull(funcDepMap[funcName], 'createCallback');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2818,8 +2834,8 @@
|
|||||||
var deps = _.pull(funcDepMap[funcName], 'createIterator');
|
var deps = _.pull(funcDepMap[funcName], 'createIterator');
|
||||||
_.pull(varDepMap[funcName] || (varDepMap[funcName] = []), 'defaultsIteratorOptions', 'eachIteratorOptions', 'forOwnIteratorOptions').push('objectTypes');
|
_.pull(varDepMap[funcName] || (varDepMap[funcName] = []), 'defaultsIteratorOptions', 'eachIteratorOptions', 'forOwnIteratorOptions').push('objectTypes');
|
||||||
|
|
||||||
if (funcName != 'shimKeys') {
|
if (funcName != 'defaults' && funcName != 'shimKeys') {
|
||||||
deps.push('createCallback');
|
deps.push('baseCreateCallback');
|
||||||
}
|
}
|
||||||
if (funcName != 'forIn' && funcName != 'shimKeys') {
|
if (funcName != 'forIn' && funcName != 'shimKeys') {
|
||||||
deps.push('keys');
|
deps.push('keys');
|
||||||
@@ -2882,7 +2898,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isModularize) {
|
if (isModularize) {
|
||||||
funcDepMap.createIterator.push('createCallback');
|
|
||||||
_.forOwn(funcDepMap, function(deps, funcName) {
|
_.forOwn(funcDepMap, function(deps, funcName) {
|
||||||
if (_.contains(deps, 'getIndexOf')) {
|
if (_.contains(deps, 'getIndexOf')) {
|
||||||
_.pull(deps, 'getIndexOf').push('baseIndexOf');
|
_.pull(deps, 'getIndexOf').push('baseIndexOf');
|
||||||
@@ -3061,7 +3076,7 @@
|
|||||||
' var index = -1,',
|
' var index = -1,',
|
||||||
' length = collection ? collection.length : 0;',
|
' length = collection ? collection.length : 0;',
|
||||||
'',
|
'',
|
||||||
" callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg, 3);",
|
" callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3);",
|
||||||
" if (typeof length == 'number') {",
|
" if (typeof length == 'number') {",
|
||||||
' while (++index < length) {',
|
' while (++index < length) {',
|
||||||
' if (callback(collection[index], index, collection) === false) {',
|
' if (callback(collection[index], index, collection) === false) {',
|
||||||
@@ -4217,11 +4232,6 @@
|
|||||||
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
||||||
});
|
});
|
||||||
|
|
||||||
// replace `lodash` with `createCallback` in `createIterator`
|
|
||||||
source = source.replace(matchFunction(source, 'createIterator'), function(match) {
|
|
||||||
return match.replace(/\blodash\b/g, 'createCallback');
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove unneeded variable dependencies
|
// remove unneeded variable dependencies
|
||||||
_.each(varDependencies, function(varName) {
|
_.each(varDependencies, function(varName) {
|
||||||
if (!_.contains(includeVars, varName)) {
|
if (!_.contains(includeVars, varName)) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
'args',
|
'args',
|
||||||
'argsIndex',
|
'argsIndex',
|
||||||
'argsLength',
|
'argsLength',
|
||||||
|
'baseCreateCallback',
|
||||||
'callback',
|
'callback',
|
||||||
'className',
|
'className',
|
||||||
'collection',
|
'collection',
|
||||||
|
|||||||
194
lodash.js
194
lodash.js
@@ -143,7 +143,7 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base implementation of `_.indexOf` without support for binary searches
|
* The base implementation of `_.indexOf` without support for binary searches
|
||||||
* or `fromIndex` constraints.
|
* or `fromIndex` constraints.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -945,7 +945,7 @@
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base implementation of `_.clone` without argument juggling or support
|
* The base implementation of `_.clone` without argument juggling or support
|
||||||
* for `thisArg` binding.
|
* for `thisArg` binding.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -1035,7 +1035,52 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base implementation of `_.flatten` without support for `callback`
|
* The base implementation of `_.createCallback` without support for creating
|
||||||
|
* "_.pluck" or "_.where" style callbacks.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Mixed} [func=identity] The value to convert to a callback.
|
||||||
|
* @param {Mixed} [thisArg] The `this` binding of the created callback.
|
||||||
|
* @param {Number} [argCount] The number of arguments the callback accepts.
|
||||||
|
* @returns {Function} Returns a callback function.
|
||||||
|
*/
|
||||||
|
function baseCreateCallback(func, thisArg, argCount) {
|
||||||
|
if (typeof func != 'function') {
|
||||||
|
return identity;
|
||||||
|
}
|
||||||
|
// exit early if there is no `thisArg`
|
||||||
|
if (typeof thisArg == 'undefined') {
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
var bindData = !func.name || func.__bindData__;
|
||||||
|
if (typeof bindData == 'undefined') {
|
||||||
|
// checks if `func` references the `this` keyword and stores the result
|
||||||
|
bindData = !reThis || reThis.test(fnToString.call(func));
|
||||||
|
setBindData(func, bindData);
|
||||||
|
}
|
||||||
|
// exit early if there are no `this` references or `func` is bound
|
||||||
|
if (bindData !== true && !(bindData && bindData[4])) {
|
||||||
|
return func;
|
||||||
|
}
|
||||||
|
switch (argCount) {
|
||||||
|
case 1: return function(value) {
|
||||||
|
return func.call(thisArg, value);
|
||||||
|
};
|
||||||
|
case 2: return function(a, b) {
|
||||||
|
return func.call(thisArg, a, b);
|
||||||
|
};
|
||||||
|
case 3: return function(value, index, collection) {
|
||||||
|
return func.call(thisArg, value, index, collection);
|
||||||
|
};
|
||||||
|
case 4: return function(accumulator, value, index, collection) {
|
||||||
|
return func.call(thisArg, accumulator, value, index, collection);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return bind(func, thisArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `_.flatten` without support for `callback`
|
||||||
* shorthands or `thisArg` binding.
|
* shorthands or `thisArg` binding.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -1063,7 +1108,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base implementation of `_.isEqual`, without support for `thisArg` binding,
|
* The base implementation of `_.isEqual`, without support for `thisArg` binding,
|
||||||
* that allows partial "_.where" style comparisons.
|
* that allows partial "_.where" style comparisons.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -1232,7 +1277,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base implementation of `_.merge` without argument juggling or support
|
* The base implementation of `_.merge` without argument juggling or support
|
||||||
* for `thisArg` binding.
|
* for `thisArg` binding.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -1297,7 +1342,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base implementation of `_.uniq` without support for `callback` shorthands
|
* The base implementation of `_.uniq` without support for `callback` shorthands
|
||||||
* or `thisArg` binding.
|
* or `thisArg` binding.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
@@ -1485,9 +1530,9 @@
|
|||||||
|
|
||||||
// create the function factory
|
// create the function factory
|
||||||
var factory = Function(
|
var factory = Function(
|
||||||
'errorClass, errorProto, hasOwnProperty, indicatorObject, isArguments, ' +
|
'baseCreateCallback, errorClass, errorProto, hasOwnProperty, ' +
|
||||||
'isArray, isString, keys, lodash, objectProto, objectTypes, nonEnumProps, ' +
|
'indicatorObject, isArguments, isArray, isString, keys, objectProto, ' +
|
||||||
'stringClass, stringProto, toString',
|
'objectTypes, nonEnumProps, stringClass, stringProto, toString',
|
||||||
'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
|
'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1495,9 +1540,9 @@
|
|||||||
|
|
||||||
// return the compiled function
|
// return the compiled function
|
||||||
return factory(
|
return factory(
|
||||||
errorClass, errorProto, hasOwnProperty, indicatorObject, isArguments,
|
baseCreateCallback, errorClass, errorProto, hasOwnProperty,
|
||||||
isArray, isString, data.keys, lodash, objectProto, objectTypes, nonEnumProps,
|
indicatorObject, isArguments, isArray, isString, data.keys, objectProto,
|
||||||
stringClass, stringProto, toString
|
objectTypes, nonEnumProps, stringClass, stringProto, toString
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1704,7 +1749,7 @@
|
|||||||
/** Reusable iterator options shared by `each`, `forIn`, and `forOwn` */
|
/** Reusable iterator options shared by `each`, `forIn`, and `forOwn` */
|
||||||
var eachIteratorOptions = {
|
var eachIteratorOptions = {
|
||||||
'args': 'collection, callback, thisArg',
|
'args': 'collection, callback, thisArg',
|
||||||
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : lodash.createCallback(callback, thisArg, 3)",
|
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : baseCreateCallback(callback, thisArg, 3)",
|
||||||
'array': "typeof length == 'number'",
|
'array': "typeof length == 'number'",
|
||||||
'keys': keys,
|
'keys': keys,
|
||||||
'loop': 'if (callback(iterable[index], index, collection) === false) return result'
|
'loop': 'if (callback(iterable[index], index, collection) === false) return result'
|
||||||
@@ -1807,7 +1852,7 @@
|
|||||||
defaultsIteratorOptions.top.replace(';',
|
defaultsIteratorOptions.top.replace(';',
|
||||||
';\n' +
|
';\n' +
|
||||||
"if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {\n" +
|
"if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {\n" +
|
||||||
' var callback = lodash.createCallback(args[--argsLength - 1], args[argsLength--], 2);\n' +
|
' var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2);\n' +
|
||||||
"} else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') {\n" +
|
"} else if (argsLength > 2 && typeof args[argsLength - 1] == 'function') {\n" +
|
||||||
' callback = args[--argsLength];\n' +
|
' callback = args[--argsLength];\n' +
|
||||||
'}'
|
'}'
|
||||||
@@ -1863,7 +1908,7 @@
|
|||||||
callback = deep;
|
callback = deep;
|
||||||
deep = false;
|
deep = false;
|
||||||
}
|
}
|
||||||
return baseClone(value, deep, typeof callback == 'function' && lodash.createCallback(callback, thisArg, 1));
|
return baseClone(value, deep, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1908,7 +1953,7 @@
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function cloneDeep(value, callback, thisArg) {
|
function cloneDeep(value, callback, thisArg) {
|
||||||
return baseClone(value, true, typeof callback == 'function' && lodash.createCallback(callback, thisArg, 1));
|
return baseClone(value, true, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2065,7 +2110,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
var length = pairs.length;
|
var length = pairs.length;
|
||||||
callback = lodash.createCallback(callback, thisArg, 3);
|
callback = baseCreateCallback(callback, thisArg, 3);
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
if (callback(pairs[index], pairs[++index], object) === false) {
|
if (callback(pairs[index], pairs[++index], object) === false) {
|
||||||
break;
|
break;
|
||||||
@@ -2119,7 +2164,7 @@
|
|||||||
var props = keys(object),
|
var props = keys(object),
|
||||||
length = props.length;
|
length = props.length;
|
||||||
|
|
||||||
callback = lodash.createCallback(callback, thisArg, 3);
|
callback = baseCreateCallback(callback, thisArg, 3);
|
||||||
while (length--) {
|
while (length--) {
|
||||||
var key = props[length];
|
var key = props[length];
|
||||||
if (callback(object[key], key, object) === false) {
|
if (callback(object[key], key, object) === false) {
|
||||||
@@ -2329,7 +2374,7 @@
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function isEqual(a, b, callback, thisArg) {
|
function isEqual(a, b, callback, thisArg) {
|
||||||
return baseIsEqual(a, b, typeof callback == 'function' && lodash.createCallback(callback, thisArg, 2));
|
return baseIsEqual(a, b, typeof callback == 'function' && baseCreateCallback(callback, thisArg, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2636,7 +2681,7 @@
|
|||||||
length = args.length;
|
length = args.length;
|
||||||
}
|
}
|
||||||
if (length > 3 && typeof args[length - 2] == 'function') {
|
if (length > 3 && typeof args[length - 2] == 'function') {
|
||||||
var callback = lodash.createCallback(args[--length - 1], args[length--], 2);
|
var callback = baseCreateCallback(args[--length - 1], args[length--], 2);
|
||||||
} else if (length > 2 && typeof args[length - 1] == 'function') {
|
} else if (length > 2 && typeof args[length - 1] == 'function') {
|
||||||
callback = args[--length];
|
callback = args[--length];
|
||||||
}
|
}
|
||||||
@@ -2810,7 +2855,7 @@
|
|||||||
*/
|
*/
|
||||||
function transform(object, callback, accumulator, thisArg) {
|
function transform(object, callback, accumulator, thisArg) {
|
||||||
var isArr = isArray(object);
|
var isArr = isArray(object);
|
||||||
callback = lodash.createCallback(callback, thisArg, 4);
|
callback = baseCreateCallback(callback, thisArg, 4);
|
||||||
|
|
||||||
if (accumulator == null) {
|
if (accumulator == null) {
|
||||||
if (isArr) {
|
if (isArr) {
|
||||||
@@ -3269,7 +3314,7 @@
|
|||||||
} else if (support.unindexedChars && isString(collection)) {
|
} else if (support.unindexedChars && isString(collection)) {
|
||||||
iterable = collection.split('');
|
iterable = collection.split('');
|
||||||
}
|
}
|
||||||
callback = lodash.createCallback(callback, thisArg, 3);
|
callback = baseCreateCallback(callback, thisArg, 3);
|
||||||
forEach(collection, function(value, index, collection) {
|
forEach(collection, function(value, index, collection) {
|
||||||
index = props ? props[--length] : --length;
|
index = props ? props[--length] : --length;
|
||||||
callback(iterable[index], index, collection);
|
callback(iterable[index], index, collection);
|
||||||
@@ -3643,7 +3688,7 @@
|
|||||||
*/
|
*/
|
||||||
function reduce(collection, callback, accumulator, thisArg) {
|
function reduce(collection, callback, accumulator, thisArg) {
|
||||||
var noaccum = arguments.length < 3;
|
var noaccum = arguments.length < 3;
|
||||||
callback = lodash.createCallback(callback, thisArg, 4);
|
callback = baseCreateCallback(callback, thisArg, 4);
|
||||||
|
|
||||||
if (isArray(collection)) {
|
if (isArray(collection)) {
|
||||||
var index = -1,
|
var index = -1,
|
||||||
@@ -3686,7 +3731,7 @@
|
|||||||
*/
|
*/
|
||||||
function reduceRight(collection, callback, accumulator, thisArg) {
|
function reduceRight(collection, callback, accumulator, thisArg) {
|
||||||
var noaccum = arguments.length < 3;
|
var noaccum = arguments.length < 3;
|
||||||
callback = lodash.createCallback(callback, thisArg, 4);
|
callback = baseCreateCallback(callback, thisArg, 4);
|
||||||
forEachRight(collection, function(value, index, collection) {
|
forEachRight(collection, function(value, index, collection) {
|
||||||
accumulator = noaccum
|
accumulator = noaccum
|
||||||
? (noaccum = false, value)
|
? (noaccum = false, value)
|
||||||
@@ -3785,7 +3830,8 @@
|
|||||||
var value = collection[index];
|
var value = collection[index];
|
||||||
if (callback(value, index, collection)) {
|
if (callback(value, index, collection)) {
|
||||||
result.push(value);
|
result.push(value);
|
||||||
splice.call(collection, index, 1);
|
splice.call(collection, index--, 1);
|
||||||
|
length--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -4602,7 +4648,8 @@
|
|||||||
value = args[argsIndex];
|
value = args[argsIndex];
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
if (array[index] === value) {
|
if (array[index] === value) {
|
||||||
splice.call(array, index, 1);
|
splice.call(array, index--, 1);
|
||||||
|
length--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5131,8 +5178,6 @@
|
|||||||
* If `func` is an object, the created callback will return `true` for elements
|
* If `func` is an object, the created callback will return `true` for elements
|
||||||
* that contain the equivalent object properties, otherwise it will return `false`.
|
* that contain the equivalent object properties, otherwise it will return `false`.
|
||||||
*
|
*
|
||||||
* Note: All Lo-Dash methods, that accept a `callback` argument, use `_.createCallback`.
|
|
||||||
*
|
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Functions
|
* @category Functions
|
||||||
@@ -5172,71 +5217,40 @@
|
|||||||
* // => { 'moe': { 'name': 'moe', 'age': 40 }, 'larry': { 'name': 'larry', 'age': 50 } }
|
* // => { 'moe': { 'name': 'moe', 'age': 40 }, 'larry': { 'name': 'larry', 'age': 50 } }
|
||||||
*/
|
*/
|
||||||
function createCallback(func, thisArg, argCount) {
|
function createCallback(func, thisArg, argCount) {
|
||||||
if (func == null) {
|
|
||||||
return identity;
|
|
||||||
}
|
|
||||||
var type = typeof func;
|
var type = typeof func;
|
||||||
if (type != 'function') {
|
if (func == null || type == 'function') {
|
||||||
// handle "_.pluck" style callback shorthands
|
return baseCreateCallback(func, thisArg, argCount);
|
||||||
if (type != 'object') {
|
}
|
||||||
return function(object) {
|
// handle "_.pluck" style callback shorthands
|
||||||
return object[func];
|
if (type != 'object') {
|
||||||
};
|
|
||||||
}
|
|
||||||
var props = keys(func),
|
|
||||||
key = props[0],
|
|
||||||
a = func[key];
|
|
||||||
|
|
||||||
// handle "_.where" style callback shorthands
|
|
||||||
if (props.length == 1 && a === a && !isObject(a)) {
|
|
||||||
// fast path the common case of passing an object with a single
|
|
||||||
// property containing a primitive value
|
|
||||||
return function(object) {
|
|
||||||
var b = object[key];
|
|
||||||
return a === b && (a !== 0 || (1 / a == 1 / b));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return function(object) {
|
return function(object) {
|
||||||
var length = props.length,
|
return object[func];
|
||||||
result = false;
|
};
|
||||||
|
}
|
||||||
|
var props = keys(func),
|
||||||
|
key = props[0],
|
||||||
|
a = func[key];
|
||||||
|
|
||||||
while (length--) {
|
// handle "_.where" style callback shorthands
|
||||||
if (!(result = baseIsEqual(object[props[length]], func[props[length]], null, true))) {
|
if (props.length == 1 && a === a && !isObject(a)) {
|
||||||
break;
|
// fast path the common case of passing an object with a single
|
||||||
}
|
// property containing a primitive value
|
||||||
|
return function(object) {
|
||||||
|
var b = object[key];
|
||||||
|
return a === b && (a !== 0 || (1 / a == 1 / b));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return function(object) {
|
||||||
|
var length = props.length,
|
||||||
|
result = false;
|
||||||
|
|
||||||
|
while (length--) {
|
||||||
|
if (!(result = baseIsEqual(object[props[length]], func[props[length]], null, true))) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
};
|
return result;
|
||||||
}
|
};
|
||||||
// exit early if there is no `thisArg`
|
|
||||||
if (typeof thisArg == 'undefined') {
|
|
||||||
return func;
|
|
||||||
}
|
|
||||||
var bindData = !func.name || func.__bindData__;
|
|
||||||
if (typeof bindData == 'undefined') {
|
|
||||||
// checks if `func` references the `this` keyword and stores the result
|
|
||||||
bindData = !reThis || reThis.test(fnToString.call(func));
|
|
||||||
setBindData(func, bindData);
|
|
||||||
}
|
|
||||||
// exit early if there are no `this` references or `func` is bound
|
|
||||||
if (bindData !== true && !(bindData && bindData[4])) {
|
|
||||||
return func;
|
|
||||||
}
|
|
||||||
switch (argCount) {
|
|
||||||
case 1: return function(value) {
|
|
||||||
return func.call(thisArg, value);
|
|
||||||
};
|
|
||||||
case 2: return function(a, b) {
|
|
||||||
return func.call(thisArg, a, b);
|
|
||||||
};
|
|
||||||
case 3: return function(value, index, collection) {
|
|
||||||
return func.call(thisArg, value, index, collection);
|
|
||||||
};
|
|
||||||
case 4: return function(accumulator, value, index, collection) {
|
|
||||||
return func.call(thisArg, accumulator, value, index, collection);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return bind(func, thisArg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -6013,7 +6027,7 @@
|
|||||||
var index = -1,
|
var index = -1,
|
||||||
result = Array(n);
|
result = Array(n);
|
||||||
|
|
||||||
callback = lodash.createCallback(callback, thisArg, 1);
|
callback = baseCreateCallback(callback, thisArg, 1);
|
||||||
while (++index < n) {
|
while (++index < n) {
|
||||||
result[index] = callback(index);
|
result[index] = callback(index);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user