Merge pull request #5714 from chrootsu/lodash-mixin

lodash: changed _.mixin() method
This commit is contained in:
Masahiro Wakame
2015-09-09 01:38:53 +09:00
2 changed files with 61 additions and 10 deletions
+15 -6
View File
@@ -1716,12 +1716,6 @@ var testAttempFn: TestAttemptFn;
result = <TResult|Error>_.attempt<TResult>(testAttempFn);
result = <TResult|Error>_(testAttempFn).attempt<TResult>();
_.mixin({
'capitalize': function (string) {
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
}
});
var lodash = <typeof _>_.noConflict();
result = <number>_.random(0, 5);
@@ -2003,6 +1997,21 @@ result = <number>(_.methodOf<number>(TestMethodOfObject, 1, 2))(['a', '0']);
result = <number>(_(TestMethodOfObject).methodOf<number>(1, 2).value())('a[0]');
result = <number>(_(TestMethodOfObject).methodOf<number>(1, 2).value())(['a', '0']);
// _.mixin
{
let testMixinSource: _.Dictionary<Function>;
let testMixinOptions: {chain?: boolean;}
let result: TResult;
result = _.mixin<TResult, Object>({}, testMixinSource);
result = _.mixin<TResult, Object>({}, testMixinSource, testMixinOptions);
result = _.mixin<TResult>(testMixinSource);
result = _.mixin<TResult>(testMixinSource, testMixinOptions);
result = _({}).mixin<TResult>(testMixinSource).value();
result = _({}).mixin<TResult>(testMixinSource, testMixinOptions).value();
result = _(testMixinSource).mixin<TResult>().value();
result = _(testMixinSource).mixin<TResult>(testMixinOptions).value();
}
// _.uniqueId
result = <string>_.uniqueId();
result = <string>_.uniqueId('');
+46 -4
View File
@@ -8209,12 +8209,54 @@ declare module _ {
}
//_.mixin
interface MixinOptions {
chain?: boolean;
}
interface LoDashStatic {
/**
* Adds function properties of a source object to the lodash function and chainable wrapper.
* @param object The object of function properties to add to lodash.
**/
mixin(object?: Dictionary<(value: any) => any>): void;
* Adds all own enumerable function properties of a source object to the destination object. If object is a
* function then methods are added to its prototype as well.
*
* Note: Use _.runInContext to create a pristine lodash function to avoid conflicts caused by modifying
* the original.
*
* @param object The destination object.
* @param source The object of functions to add.
* @param options The options object.
* @param options.chain Specify whether the functions added are chainable.
* @return Returns object.
*/
mixin<TResult, TObject>(
object: TObject,
source: Dictionary<Function>,
options?: MixinOptions
): TResult;
/**
* @see _.mixin
*/
mixin<TResult>(
source: Dictionary<Function>,
options?: MixinOptions
): TResult;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.mixin
*/
mixin<TResult>(
source: Dictionary<Function>,
options?: MixinOptions
): LoDashObjectWrapper<TResult>;
/**
* @see _.mixin
*/
mixin<TResult>(
options?: MixinOptions
): LoDashObjectWrapper<TResult>;
}
//_.noConflict