Remove unneeded method from the backbone build and fix build tests.

Former-commit-id: ee463a4af4d458a556f5be666b71b464bae32e6b
This commit is contained in:
John-David Dalton
2013-05-29 17:06:01 -04:00
parent e27bdb965c
commit 42f4531720
2 changed files with 32 additions and 25 deletions

View File

@@ -208,7 +208,7 @@
// method used by the `backbone` and `underscore` builds
'chain': ['value'],
'findWhere': ['find']
'findWhere': ['where']
};
/** Used to inline `iteratorTemplate` */
@@ -231,7 +231,7 @@
var allMethods = _.keys(dependencyMap);
/** List of Lo-Dash methods */
var lodashMethods = allMethods.slice();
var lodashMethods = _.without(allMethods, 'findWhere');
/** List of Backbone's Lo-Dash dependencies */
var backboneDependencies = [
@@ -729,7 +729,9 @@
* @returns {Array} Returns an array of aliases.
*/
function getAliases(methodName) {
return realToAliasMap[methodName] || [];
return (realToAliasMap[methodName] || []).filter(function(methodName) {
return !dependencyMap[methodName];
});
}
/**
@@ -945,7 +947,7 @@
* @returns {String} Returns the real method name.
*/
function getRealName(methodName) {
return aliasToRealMap[methodName] || methodName;
return (!dependencyMap[methodName] && aliasToRealMap[methodName]) || methodName;
}
/**
@@ -1860,6 +1862,11 @@
return _.contains(methods, methodName);
};
// delete the `_.findWhere` dependency map to enable its alias mapping
if (!isUnderscore || useLodashMethod('findWhere')) {
delete dependencyMap.findWhere;
}
// methods to include in the build
var includeMethods = options.reduce(function(accumulator, value) {
return /^include=.*$/.test(value)
@@ -1934,16 +1941,16 @@
if (!useLodashMethod('pick')){
dependencyMap.pick = _.without(dependencyMap.pick, 'forIn', 'isObject');
}
if (!useLodashMethod('where')) {
dependencyMap.createCallback = _.without(dependencyMap.createCallback, 'isEqual');
dependencyMap.where.push('find', 'isEmpty');
}
if (!useLodashMethod('template')) {
dependencyMap.template = _.without(dependencyMap.template, 'keys', 'values');
}
if (!useLodashMethod('toArray')) {
dependencyMap.toArray.push('isArray', 'map');
}
if (!useLodashMethod('where')) {
dependencyMap.createCallback = _.without(dependencyMap.createCallback, 'isEqual');
dependencyMap.where.push('find', 'isEmpty');
}
_.each(['debounce', 'throttle'], function(methodName) {
if (!useLodashMethod(methodName)) {
@@ -1962,11 +1969,10 @@
dependencyMap[methodName] = _.without(dependencyMap[methodName], 'charAtCallback', 'isArray', 'isString');
}
});
dependencyMap.findWhere = ['where'];
dependencyMap.reduceRight = _.without(dependencyMap.reduceRight, 'isString');
}
if (isModern || isUnderscore) {
dependencyMap.reduceRight = _.without(dependencyMap.reduceRight, 'isString');
_.each(['at', 'forEach', 'toArray'], function(methodName) {
if (!(isUnderscore && useLodashMethod(methodName))) {
dependencyMap[methodName] = _.without(dependencyMap[methodName], 'isString');
@@ -2006,10 +2012,10 @@
// add `chain` and `findWhere`
if (isUnderscore) {
if (_.contains(categories, 'Chaining')) {
if (_.contains(categories, 'Chaining') && !_.contains(methodNames, 'chain')) {
methodNames.push('chain');
}
if (_.contains(categories, 'Collections')) {
if (_.contains(categories, 'Collections') && !_.contains(methodNames, 'findWhere')) {
methodNames.push('findWhere');
}
}
@@ -2125,7 +2131,7 @@
source = removeBindingOptimization(source);
}
if (isLegacy || isMobile || isUnderscore) {
if (!useLodashMethod('assign') && !useLodashMethod('defaults') && !useLodashMethod('forIn') && !useLodashMethod('forOwn')) {
if (isMobile || (!useLodashMethod('assign') && !useLodashMethod('defaults') && !useLodashMethod('forIn') && !useLodashMethod('forOwn'))) {
source = removeKeysOptimization(source);
}
if (!useLodashMethod('defer')) {
@@ -2928,7 +2934,8 @@
else {
// remove methods from the build
allMethods.forEach(function(otherName) {
if (!_.contains(buildMethods, otherName)) {
if (!_.contains(buildMethods, otherName) &&
!(otherName == 'findWhere' && !isUnderscore)) {
source = removeFunction(source, otherName);
}
});
@@ -3300,7 +3307,7 @@
}
debugSource = cleanupSource(source);
source = cleanupSource(source);
source = debugSource;
/*------------------------------------------------------------------------*/

View File

@@ -57,7 +57,6 @@
'drop': 'rest',
'each': 'forEach',
'extend': 'assign',
'findWhere': 'find',
'foldl': 'reduce',
'foldr': 'reduceRight',
'head': 'first',
@@ -77,7 +76,7 @@
'contains': ['include'],
'every': ['all'],
'filter': ['select'],
'find': ['detect', 'findWhere'],
'find': ['detect'],
'first': ['head', 'take'],
'forEach': ['each'],
'functions': ['methods'],
@@ -90,13 +89,13 @@
'zipObject': ['object']
};
/** List of all Lo-Dash methods */
var lodashMethods = _.functions(_).filter(function(methodName) {
/** List of all methods */
var allMethods = _.functions(_).filter(function(methodName) {
return !/^_/.test(methodName);
});
/** List of all methods */
var allMethods = lodashMethods.slice();
/** List of all Lo-Dash methods */
var lodashMethods = _.without(allMethods, 'findWhere');
/** List of "Arrays" category methods */
var arraysMethods = [
@@ -464,7 +463,7 @@
func(array, 'slice');
func(object, 'toFixed');
}
else if (methodName == 'where') {
else if (methodName == 'findWhere' || methodName == 'where') {
func(array, object);
func(object, object);
}
@@ -1445,7 +1444,7 @@
/*--------------------------------------------------------------------------*/
QUnit.module('mixed underscore and lodash methods');
QUnit.module('underscore builds with lodash methods');
(function() {
var methodNames = [
@@ -1482,6 +1481,7 @@
'pick',
'pluck',
'reduce',
'reduceRight',
'result',
'rest',
'some',
@@ -1535,7 +1535,7 @@
vm.runInContext(data.source, context, true);
var lodash = context._;
if (methodName == 'chain' || methodName == 'defer') {
if (methodName == 'chain' || methodName == 'defer' || methodName == 'findWhere') {
notEqual(strip(lodash[methodName]), strip(_[methodName]), basename);
} else if (!/\.min$/.test(basename)) {
equal(strip(lodash[methodName]), strip(_[methodName]), basename);