Rename _.invoke to _.invokeMap.

This commit is contained in:
John-David Dalton
2015-11-24 14:10:11 -08:00
parent 9e334b5ece
commit 44abe46da4
6 changed files with 73 additions and 54 deletions

View File

@@ -28,12 +28,30 @@
QUnit.config.hidepassed = true;
var mixinPrereqs = (function() {
var aliasToReal = {
'indexBy': 'keyBy',
'invoke': 'invokeMap'
};
var keyMap = {
'rest': 'tail'
};
var lodash = _.noConflict();
return function(_) {
lodash.defaultsDeep(_, { 'templateSettings': lodash.templateSettings });
lodash.mixin(_ , { 'indexBy': lodash.keyBy, 'rest': lodash.tail });
lodash.mixin(_, lodash.pick(lodash, lodash.difference(lodash.functions(lodash), lodash.functions(_))));
lodash.forOwn(keyMap, function(realName, otherName) {
_[otherName] = lodash[realName];
_.prototype[otherName] = lodash.prototype[realName];
});
lodash.forOwn(aliasToReal, function(realName, alias) {
_[alias] = _[realName];
_.prototype[alias] = _.prototype[realName];
});
};
}());

View File

@@ -290,7 +290,7 @@ function logThrobber() {
* @returns {Array} Returns the new converted array.
*/
function optionToArray(name, string) {
return _.compact(_.invoke((optionToValue(name, string) || '').split(/, */), 'trim'));
return _.compact(_.invokeMap((optionToValue(name, string) || '').split(/, */), 'trim'));
}
/**
@@ -714,7 +714,7 @@ function Tunnel(properties) {
total = all.length,
tunnel = this;
_.invoke(all, 'on', 'complete', function() {
_.invokeMap(all, 'on', 'complete', function() {
_.pull(active, this);
if (success) {
success = !this.failed;
@@ -726,7 +726,7 @@ function Tunnel(properties) {
tunnel.dequeue();
});
_.invoke(all, 'on', 'restart', function() {
_.invokeMap(all, 'on', 'restart', function() {
if (!_.includes(restarted, this)) {
restarted.push(this);
}
@@ -774,7 +774,7 @@ Tunnel.prototype.restart = function(callback) {
all = jobs.all;
var reset = _.after(all.length, _.bind(this.stop, this, onGenericRestart)),
stop = _.after(active.length, _.partial(_.invoke, all, 'reset', reset));
stop = _.after(active.length, _.partial(_.invokeMap, all, 'reset', reset));
if (_.isEmpty(active)) {
_.defer(stop);
@@ -782,7 +782,7 @@ Tunnel.prototype.restart = function(callback) {
if (_.isEmpty(all)) {
_.defer(reset);
}
_.invoke(active, 'stop', function() {
_.invokeMap(active, 'stop', function() {
_.pull(active, this);
stop();
});
@@ -870,7 +870,7 @@ Tunnel.prototype.stop = function(callback) {
if (_.isEmpty(active)) {
_.defer(stop);
}
_.invoke(active, 'stop', function() {
_.invokeMap(active, 'stop', function() {
_.pull(active, this);
stop();
});

View File

@@ -7063,14 +7063,14 @@
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.invoke');
QUnit.module('lodash.invokeMap');
(function() {
QUnit.test('should invoke a methods on each element of `collection`', function(assert) {
assert.expect(1);
var array = ['a', 'b', 'c'],
actual = _.invoke(array, 'toUpperCase');
actual = _.invokeMap(array, 'toUpperCase');
assert.deepEqual(actual, ['A', 'B', 'C']);
});
@@ -7079,7 +7079,7 @@
assert.expect(1);
var array = [function() { return slice.call(arguments); }],
actual = _.invoke(array, 'call', null, 'a', 'b', 'c');
actual = _.invokeMap(array, 'call', null, 'a', 'b', 'c');
assert.deepEqual(actual, [['a', 'b', 'c']]);
});
@@ -7089,7 +7089,7 @@
var array = ['a', 'b', 'c'];
var actual = _.invoke(array, function(left, right) {
var actual = _.invokeMap(array, function(left, right) {
return left + this.toUpperCase() + right;
}, '(', ')');
@@ -7100,7 +7100,7 @@
assert.expect(1);
var object = { 'a': 1, 'b': 2, 'c': 3 },
actual = _.invoke(object, 'toFixed', 1);
actual = _.invokeMap(object, 'toFixed', 1);
assert.deepEqual(actual, ['1.0', '2.0', '3.0']);
});
@@ -7108,7 +7108,7 @@
QUnit.test('should treat number values for `collection` as empty', function(assert) {
assert.expect(1);
assert.deepEqual(_.invoke(1), []);
assert.deepEqual(_.invokeMap(1), []);
});
QUnit.test('should not error on nullish elements', function(assert) {
@@ -7117,10 +7117,10 @@
var array = ['a', null, undefined, 'd'];
try {
var actual = _.invoke(array, 'toUpperCase');
var actual = _.invokeMap(array, 'toUpperCase');
} catch (e) {}
assert.deepEqual(_.invoke(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
assert.deepEqual(_.invokeMap(array, 'toUpperCase'), ['A', undefined, undefined, 'D']);
});
QUnit.test('should not error on elements with missing properties', function(assert) {
@@ -7133,7 +7133,7 @@
var expected = lodashStable.times(objects.length - 1, lodashStable.constant(undefined)).concat(1);
try {
var actual = _.invoke(objects, 'a');
var actual = _.invokeMap(objects, 'a');
} catch (e) {}
assert.deepEqual(actual, expected);
@@ -7145,12 +7145,11 @@
var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
lodashStable.each(['a.b', ['a', 'b']], function(path) {
assert.deepEqual(_.invoke([object], path), [1]);
assert.deepEqual(_.invokeMap([object], path), [1]);
});
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.invokePath');
@@ -9849,7 +9848,8 @@
assert.expect(1);
if (realm.object) {
var props = _.invoke(typedArrays, 'toLowerCase');
var invoke = lodashStable.invokeMap || lodashStable.invoke,
props = invoke(typedArrays, 'toLowerCase');
var expected = lodashStable.map(props, function(key) {
return key in realm;
@@ -22670,7 +22670,7 @@
'functions',
'initial',
'intersection',
'invoke',
'invokeMap',
'keys',
'map',
'pull',
@@ -22746,7 +22746,7 @@
func = _[methodName];
switch (methodName) {
case 'invoke':
case 'invokeMap':
actual = func(array, 'toFixed');
break;
case 'sample':

View File

@@ -344,6 +344,7 @@
'include': 'includes',
'indexBy': 'keyBy',
'inject': 'reduce',
'invoke': 'invokeMap',
'mapObject': 'mapValues',
'matcher': 'matches',
'methods': 'functions',