From 05d57b90a9527cb22f52ab09e81d14be7739650c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 25 Nov 2015 12:07:13 -0800 Subject: [PATCH] Rename `_.invokePath` to `_.invoke`. --- lodash.js | 20 +++--- test/test.js | 168 +++++++++++++++++++++++++-------------------------- 2 files changed, 94 insertions(+), 94 deletions(-) diff --git a/lodash.js b/lodash.js index f71ccdba2..f24078eb6 100644 --- a/lodash.js +++ b/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); }); }); diff --git a/test/test.js b/test/test.js index d07c9aa28..0802c0954 100644 --- a/test/test.js +++ b/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() {