mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Ensure _#plant resets iterator data of the cloned sequence.
This commit is contained in:
18
lodash.js
18
lodash.js
@@ -1486,11 +1486,10 @@
|
|||||||
* @private
|
* @private
|
||||||
* @param {*} value The value to wrap.
|
* @param {*} value The value to wrap.
|
||||||
* @param {boolean} [chainAll] Enable chaining for all wrapper methods.
|
* @param {boolean} [chainAll] Enable chaining for all wrapper methods.
|
||||||
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
|
|
||||||
*/
|
*/
|
||||||
function LodashWrapper(value, chainAll, actions) {
|
function LodashWrapper(value, chainAll) {
|
||||||
this.__wrapped__ = value;
|
this.__wrapped__ = value;
|
||||||
this.__actions__ = actions || [];
|
this.__actions__ = [];
|
||||||
this.__chain__ = !!chainAll;
|
this.__chain__ = !!chainAll;
|
||||||
this.__index__ = 0;
|
this.__index__ = 0;
|
||||||
this.__values__ = undefined;
|
this.__values__ = undefined;
|
||||||
@@ -4347,9 +4346,14 @@
|
|||||||
* @returns {Object} Returns the cloned wrapper.
|
* @returns {Object} Returns the cloned wrapper.
|
||||||
*/
|
*/
|
||||||
function wrapperClone(wrapper) {
|
function wrapperClone(wrapper) {
|
||||||
return wrapper instanceof LazyWrapper
|
if (wrapper instanceof LazyWrapper) {
|
||||||
? wrapper.clone()
|
return wrapper.clone();
|
||||||
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, copyArray(wrapper.__actions__));
|
}
|
||||||
|
var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
|
||||||
|
result.__actions__ = wrapper.__actions__;
|
||||||
|
result.__index__ = wrapper.__index__;
|
||||||
|
result.__values__ = wrapper.__values__;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
@@ -5950,6 +5954,8 @@
|
|||||||
|
|
||||||
while (parent instanceof baseLodash) {
|
while (parent instanceof baseLodash) {
|
||||||
var clone = wrapperClone(parent);
|
var clone = wrapperClone(parent);
|
||||||
|
clone.__index__ = 0;
|
||||||
|
clone.__values__ = undefined;
|
||||||
if (result) {
|
if (result) {
|
||||||
previous.__wrapped__ = clone;
|
previous.__wrapped__ = clone;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
16
test/test.js
16
test/test.js
@@ -16637,6 +16637,22 @@
|
|||||||
skipTest(2);
|
skipTest(2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should reset iterator data on cloned sequences', 2, function() {
|
||||||
|
if (!isNpm) {
|
||||||
|
var array1 = [2, 4],
|
||||||
|
array2 = [6, 8],
|
||||||
|
wrapped1 = _(array1).map(square);
|
||||||
|
|
||||||
|
deepEqual(_.toArray(wrapped1), [4, 16]);
|
||||||
|
|
||||||
|
var wrapped2 = wrapped1.plant(array2);
|
||||||
|
deepEqual(_.toArray(wrapped2), [36, 64]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user