mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Drop boolean options param support in _.mixin.
This commit is contained in:
@@ -10804,52 +10804,43 @@
|
|||||||
* // => ['e']
|
* // => ['e']
|
||||||
*/
|
*/
|
||||||
function mixin(object, source, options) {
|
function mixin(object, source, options) {
|
||||||
if (options == null) {
|
var props = keys(source),
|
||||||
var isObj = isObject(source),
|
methodNames = baseFunctions(source, props);
|
||||||
props = isObj ? keys(source) : undefined,
|
|
||||||
methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
|
|
||||||
|
|
||||||
if (!(methodNames ? methodNames.length : isObj)) {
|
if (options == null &&
|
||||||
methodNames = false;
|
!(isObject(source) && (methodNames.length || !props.length))) {
|
||||||
options = source;
|
options = source;
|
||||||
source = object;
|
source = object;
|
||||||
object = this;
|
object = this;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!methodNames) {
|
|
||||||
methodNames = baseFunctions(source, keys(source));
|
methodNames = baseFunctions(source, keys(source));
|
||||||
}
|
}
|
||||||
var chain = true,
|
var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
|
||||||
index = -1,
|
index = -1,
|
||||||
isFunc = isFunction(object),
|
isFunc = isFunction(object),
|
||||||
length = methodNames.length;
|
length = methodNames.length;
|
||||||
|
|
||||||
if (options === false) {
|
|
||||||
chain = false;
|
|
||||||
} else if (isObject(options) && 'chain' in options) {
|
|
||||||
chain = options.chain;
|
|
||||||
}
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var methodName = methodNames[index],
|
var methodName = methodNames[index],
|
||||||
func = source[methodName];
|
func = source[methodName];
|
||||||
|
|
||||||
object[methodName] = func;
|
(function(func) {
|
||||||
if (isFunc) {
|
object[methodName] = func;
|
||||||
object.prototype[methodName] = (function(func) {
|
if (!isFunc) {
|
||||||
return function() {
|
return;
|
||||||
var chainAll = this.__chain__;
|
}
|
||||||
if (chain || chainAll) {
|
object.prototype[methodName] = function() {
|
||||||
var result = object(this.__wrapped__),
|
var chainAll = this.__chain__;
|
||||||
actions = result.__actions__ = arrayCopy(this.__actions__);
|
if (chain || chainAll) {
|
||||||
|
var result = object(this.__wrapped__),
|
||||||
|
actions = result.__actions__ = copyArray(this.__actions__);
|
||||||
|
|
||||||
actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
||||||
result.__chain__ = chainAll;
|
result.__chain__ = chainAll;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return func.apply(object, arrayPush([this.value()], arguments));
|
return func.apply(object, arrayPush([this.value()], arguments));
|
||||||
};
|
};
|
||||||
}(func));
|
}(func));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
@@ -11547,7 +11538,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return source;
|
return source;
|
||||||
}()), false);
|
}()), { 'chain': false });
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
@@ -10943,16 +10943,17 @@
|
|||||||
function Foo() {}
|
function Foo() {}
|
||||||
Foo.prototype.a = _.noop;
|
Foo.prototype.a = _.noop;
|
||||||
|
|
||||||
deepEqual(_.mixin({}, new Foo), {});
|
var object = {};
|
||||||
|
strictEqual(_.mixin(object, new Foo), object);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should accept an `options` argument', 16, function() {
|
test('should accept an `options` argument', 8, function() {
|
||||||
function message(func, chain) {
|
function message(func, chain) {
|
||||||
return (func === _ ? 'lodash' : 'provided') + ' function should ' + (chain ? '' : 'not ') + 'chain';
|
return (func === _ ? 'lodash' : 'provided') + ' function should ' + (chain ? '' : 'not ') + 'chain';
|
||||||
}
|
}
|
||||||
|
|
||||||
_.each([_, Wrapper], function(func) {
|
_.each([_, Wrapper], function(func) {
|
||||||
_.each([false, true, { 'chain': false }, { 'chain': true }], function(options) {
|
_.each([{ 'chain': false }, { 'chain': true }], function(options) {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
if (func === _) {
|
if (func === _) {
|
||||||
_.mixin(source, options);
|
_.mixin(source, options);
|
||||||
@@ -10962,7 +10963,7 @@
|
|||||||
var wrapped = func(array),
|
var wrapped = func(array),
|
||||||
actual = wrapped.a();
|
actual = wrapped.a();
|
||||||
|
|
||||||
if (options === true || (options && options.chain)) {
|
if (options.chain) {
|
||||||
strictEqual(actual.value(), 'a', message(func, true));
|
strictEqual(actual.value(), 'a', message(func, true));
|
||||||
ok(actual instanceof func, message(func, true));
|
ok(actual instanceof func, message(func, true));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user