mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Rename _.invokePath to _.invoke.
This commit is contained in:
20
lodash.js
20
lodash.js
@@ -1517,7 +1517,7 @@
|
||||
* `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`,
|
||||
* `findLast`, `findLastIndex`, `findLastKey`, `floor`, `get`, `gt`, `gte`,
|
||||
* `has`, `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`,
|
||||
* `invokePath`, `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`,
|
||||
* `invoke`, `isArguments`, `isArray`, `isArrayLike`, `isArrayLikeObject`,
|
||||
* `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
|
||||
* `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMatch`,
|
||||
* `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber`,
|
||||
@@ -2704,7 +2704,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* The base implementation of `_.invokePath` without support for individual
|
||||
* The base implementation of `_.invoke` without support for individual
|
||||
* method arguments.
|
||||
*
|
||||
*
|
||||
@@ -2714,7 +2714,7 @@
|
||||
* @param {Array} args The arguments to invoke the method with.
|
||||
* @returns {*} Returns the result of the invoked method.
|
||||
*/
|
||||
function baseInvokePath(object, path, args) {
|
||||
function baseInvoke(object, path, args) {
|
||||
if (!isKey(path, object)) {
|
||||
path = baseToPath(path);
|
||||
object = parent(object, path);
|
||||
@@ -7509,7 +7509,7 @@
|
||||
|
||||
baseEach(collection, function(value) {
|
||||
var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
|
||||
result[++index] = func ? func.apply(value, args) : baseInvokePath(value, path, args);
|
||||
result[++index] = func ? func.apply(value, args) : baseInvoke(value, path, args);
|
||||
});
|
||||
return result;
|
||||
});
|
||||
@@ -10921,10 +10921,10 @@
|
||||
*
|
||||
* var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
|
||||
*
|
||||
* _.invokePath(object, 'a[0].b.c.slice', 1, 3);
|
||||
* _.invoke(object, 'a[0].b.c.slice', 1, 3);
|
||||
* // => [2, 3]
|
||||
*/
|
||||
var invokePath = rest(baseInvokePath);
|
||||
var invoke = rest(baseInvoke);
|
||||
|
||||
/**
|
||||
* Creates an array of the own enumerable property names of `object`.
|
||||
@@ -12940,7 +12940,7 @@
|
||||
*/
|
||||
var method = rest(function(path, args) {
|
||||
return function(object) {
|
||||
return baseInvokePath(object, path, args);
|
||||
return baseInvoke(object, path, args);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -12968,7 +12968,7 @@
|
||||
*/
|
||||
var methodOf = rest(function(object, args) {
|
||||
return function(path) {
|
||||
return baseInvokePath(object, path, args);
|
||||
return baseInvoke(object, path, args);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -13875,7 +13875,7 @@
|
||||
lodash.includes = includes;
|
||||
lodash.indexOf = indexOf;
|
||||
lodash.inRange = inRange;
|
||||
lodash.invokePath = invokePath;
|
||||
lodash.invoke = invoke;
|
||||
lodash.isArguments = isArguments;
|
||||
lodash.isArray = isArray;
|
||||
lodash.isArrayLike = isArrayLike;
|
||||
@@ -14066,7 +14066,7 @@
|
||||
return new LazyWrapper(this);
|
||||
}
|
||||
return this.map(function(value) {
|
||||
return baseInvokePath(value, path, args);
|
||||
return baseInvoke(value, path, args);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
168
test/test.js
168
test/test.js
@@ -7089,6 +7089,90 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.invoke');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should invoke a method on `object`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var object = { 'a': lodashStable.constant('A') },
|
||||
actual = _.invoke(object, 'a');
|
||||
|
||||
assert.strictEqual(actual, 'A');
|
||||
});
|
||||
|
||||
QUnit.test('should support invoking with arguments', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var object = { 'a': function(a, b) { return [a, b]; } },
|
||||
actual = _.invoke(object, 'a', 1, 2);
|
||||
|
||||
assert.deepEqual(actual, [1, 2]);
|
||||
});
|
||||
|
||||
QUnit.test('should not error on nullish elements', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var values = [null, undefined],
|
||||
expected = lodashStable.map(values, lodashStable.constant(undefined));
|
||||
|
||||
var actual = lodashStable.map(values, function(value) {
|
||||
try {
|
||||
return _.invoke(value, 'a.b.c', 1, 2);
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should support deep paths', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
|
||||
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var actual = _.invoke(object, path, 1, 2);
|
||||
assert.deepEqual(actual, [1, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
|
||||
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
assert.deepEqual(_.invoke(object, path), 1);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (!isNpm) {
|
||||
var object = { 'a': lodashStable.constant(1) };
|
||||
assert.strictEqual(_(object).invoke('a'), 1);
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (!isNpm) {
|
||||
var object = { 'a': lodashStable.constant(1) };
|
||||
assert.ok(_(object).chain().invoke('a') instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.invokeMap');
|
||||
|
||||
(function() {
|
||||
@@ -7199,90 +7283,6 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.invokePath');
|
||||
|
||||
(function() {
|
||||
QUnit.test('should invoke a method on `object`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var object = { 'a': lodashStable.constant('A') },
|
||||
actual = _.invokePath(object, 'a');
|
||||
|
||||
assert.strictEqual(actual, 'A');
|
||||
});
|
||||
|
||||
QUnit.test('should support invoking with arguments', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var object = { 'a': function(a, b) { return [a, b]; } },
|
||||
actual = _.invokePath(object, 'a', 1, 2);
|
||||
|
||||
assert.deepEqual(actual, [1, 2]);
|
||||
});
|
||||
|
||||
QUnit.test('should not error on nullish elements', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var values = [null, undefined],
|
||||
expected = lodashStable.map(values, lodashStable.constant(undefined));
|
||||
|
||||
var actual = lodashStable.map(values, function(value) {
|
||||
try {
|
||||
return _.invokePath(value, 'a.b.c', 1, 2);
|
||||
} catch (e) {}
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('should support deep paths', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': function(a, b) { return [a, b]; } } };
|
||||
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
var actual = _.invokePath(object, path, 1, 2);
|
||||
assert.deepEqual(actual, [1, 2]);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should invoke deep property methods with the correct `this` binding', function(assert) {
|
||||
assert.expect(2);
|
||||
|
||||
var object = { 'a': { 'b': function() { return this.c; }, 'c': 1 } };
|
||||
|
||||
lodashStable.each(['a.b', ['a', 'b']], function(path) {
|
||||
assert.deepEqual(_.invokePath(object, path), 1);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.test('should return an unwrapped value when implicitly chaining', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (!isNpm) {
|
||||
var object = { 'a': lodashStable.constant(1) };
|
||||
assert.strictEqual(_(object).invokePath('a'), 1);
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('should return a wrapped value when explicitly chaining', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
if (!isNpm) {
|
||||
var object = { 'a': lodashStable.constant(1) };
|
||||
assert.ok(_(object).chain().invokePath('a') instanceof _);
|
||||
}
|
||||
else {
|
||||
skipTest(assert);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
QUnit.module('lodash.isArguments');
|
||||
|
||||
(function() {
|
||||
|
||||
Reference in New Issue
Block a user