mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Cleanup lazy _.pluck and _.where.
This commit is contained in:
@@ -10190,13 +10190,13 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// add `LazyWrapper` methods for `_.pluck` and `_.where`
|
// Add `LazyWrapper` methods for `_.pluck` and `_.where`.
|
||||||
arrayEach(['pluck', 'where'], function (methodName, index) {
|
arrayEach(['pluck', 'where'], function (methodName, index) {
|
||||||
var operationName = index ? 'filter' : 'map',
|
var operationName = index ? 'filter' : 'map',
|
||||||
getCallback = index ? matches : property;
|
getCallback = index ? matches : property;
|
||||||
|
|
||||||
LazyWrapper.prototype[methodName] = function (arg) {
|
LazyWrapper.prototype[methodName] = function(value) {
|
||||||
return this[operationName](getCallback(arg));
|
return this[operationName](getCallback(value));
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
41
test/test.js
41
test/test.js
@@ -9291,19 +9291,6 @@
|
|||||||
deepEqual(_.pluck(objects, 'a'), [1, undefined, undefined, 4]);
|
deepEqual(_.pluck(objects, 'a'), [1, undefined, undefined, 4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work in a lazy chain sequence', 1, function () {
|
|
||||||
if (!isNpm) {
|
|
||||||
var array = [{prop: 1}, null, {prop: 3}, {prop: 4}];
|
|
||||||
|
|
||||||
var wrapped = _(array).filter(Boolean).pluck("prop");
|
|
||||||
|
|
||||||
deepEqual(wrapped.value(), [1, 3, 4]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
skipTest();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should coerce `key` to a string', 1, function() {
|
test('should coerce `key` to a string', 1, function() {
|
||||||
function fn() {}
|
function fn() {}
|
||||||
fn.toString = _.constant('fn');
|
fn.toString = _.constant('fn');
|
||||||
@@ -9317,6 +9304,21 @@
|
|||||||
|
|
||||||
deepEqual(actual, [[1], [2], [3], [4]]);
|
deepEqual(actual, [[1], [2], [3], [4]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should work in a lazy chain sequence', 2, function() {
|
||||||
|
if (!isNpm) {
|
||||||
|
var array = [{ 'a': 1 }, null, { 'a': 3 }, { 'a': 4 }],
|
||||||
|
actual = _(array).pluck('a').value();
|
||||||
|
|
||||||
|
deepEqual(actual, [1, undefined, 3, 4]);
|
||||||
|
|
||||||
|
actual = _(array).filter(Boolean).pluck('a').value();
|
||||||
|
deepEqual(actual, [1, 3, 4]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -12516,17 +12518,16 @@
|
|||||||
deepEqual(actual, expected);
|
deepEqual(actual, expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work in a lazy chain sequence', 1, function () {
|
test('should work in a lazy chain sequence', 1, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var array = [
|
var array = [
|
||||||
{'a': 1},
|
{ 'a': 1 },
|
||||||
{'a': 3},
|
{ 'a': 3 },
|
||||||
{'a': 1, 'b': 2}
|
{ 'a': 1, 'b': 2 }
|
||||||
];
|
];
|
||||||
|
|
||||||
var wrapped = _(array).where({'a': 1});
|
var actual = _(array).where({ 'a': 1 }).value();
|
||||||
|
deepEqual(actual, [array[0], array[2]]);
|
||||||
deepEqual(wrapped.value(), [array[0], array[2]]);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest();
|
skipTest();
|
||||||
|
|||||||
Reference in New Issue
Block a user