From 2ec9076f2819d52b77056ed143d3f304afd1af3c Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Mon, 7 Sep 2015 01:32:15 +0500 Subject: [PATCH] lodash: changed _.mixin() method --- lodash/lodash-tests.ts | 21 +++++++++++++----- lodash/lodash.d.ts | 50 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 4e3bb97da..85cd42417 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1652,12 +1652,6 @@ var testAttempFn: TestAttemptFn; result = _.attempt(testAttempFn); result = _(testAttempFn).attempt(); -_.mixin({ - 'capitalize': function (string) { - return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); - } -}); - var lodash = _.noConflict(); result = _.random(0, 5); @@ -1939,6 +1933,21 @@ result = (_.methodOf(TestMethodOfObject, 1, 2))(['a', '0']); result = (_(TestMethodOfObject).methodOf(1, 2).value())('a[0]'); result = (_(TestMethodOfObject).methodOf(1, 2).value())(['a', '0']); +// _.mixin +{ + let testMixinSource: _.Dictionary; + let testMixinOptions: {chain?: boolean;} + let result: TResult; + result = _.mixin({}, testMixinSource); + result = _.mixin({}, testMixinSource, testMixinOptions); + result = _.mixin(testMixinSource); + result = _.mixin(testMixinSource, testMixinOptions); + result = _({}).mixin(testMixinSource).value(); + result = _({}).mixin(testMixinSource, testMixinOptions).value(); + result = _(testMixinSource).mixin().value(); + result = _(testMixinSource).mixin(testMixinOptions).value(); +} + // _.uniqueId result = _.uniqueId(); result = _.uniqueId(''); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f54bbbbb4..70e292d9b 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -8151,12 +8151,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( + object: TObject, + source: Dictionary, + options?: MixinOptions + ): TResult; + + /** + * @see _.mixin + */ + mixin( + source: Dictionary, + options?: MixinOptions + ): TResult; + } + + interface LoDashObjectWrapper { + /** + * @see _.mixin + */ + mixin( + source: Dictionary, + options?: MixinOptions + ): LoDashObjectWrapper; + + /** + * @see _.mixin + */ + mixin( + options?: MixinOptions + ): LoDashObjectWrapper; } //_.noConflict