From bc9e0dfc5ef43c0a8516d137d957e84037daf59e Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 11 Sep 2015 06:14:43 +0500 Subject: [PATCH] lodash: changed _.result() method --- lodash/lodash-tests.ts | 27 +++++++++++--------------- lodash/lodash.d.ts | 43 +++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 5b9add244..55a4efa38 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1664,6 +1664,17 @@ interface TestPickFn { result = _({}).pick(testPickFn, any).value(); } +// _.result +{ + let testResultPath: number|string|boolean|Array; + let testResultDefaultValue: TResult; + let result: TResult; + result = _.result<{}, TResult>({}, testResultPath); + result = _.result<{}, TResult>({}, testResultPath, testResultDefaultValue); + result = _({}).result(testResultPath); + result = _({}).result(testResultPath, testResultDefaultValue); +} + // _.set result = <{ a: { b: { c: number; }}[]}>_.set({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', 4); result = <{ a: { b: { c: number; }}[]}>_({ 'a': [{ 'b': { 'c': 3 } }] }).set('a[0].b.c', 4).value(); @@ -1735,22 +1746,6 @@ result = _([]).noop(true, 'a', 1); result = _({}).noop(true, 'a', 1); result = _(any).noop(true, 'a', 1); -var object = { - 'cheese': 'crumpets', - 'one': 1, - 'nested': { - 'two': 2 - }, - 'stuff': function () { - return 'nonsense'; - } -}; - -result = _.result(object, 'cheese'); -result = _.result(object, 'stuff'); -result = _.result(object, 'one'); -result = _.result(object, ['nested', 'two'] ); - var tempObject = {}; result = _.runInContext(tempObject); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index b6c95710b..9bccd7cb0 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -7540,6 +7540,34 @@ declare module _ { ): LoDashObjectWrapper; } + //_.result + interface LoDashStatic { + /** + * This method is like _.get except that if the resolved value is a function it’s invoked with the this binding + * of its parent object and its result is returned. + * + * @param object The object to query. + * @param path The path of the property to resolve. + * @param defaultValue The value returned if the resolved value is undefined. + * @return Returns the resolved value. + */ + result( + object: TObject, + path: number|string|boolean|Array, + defaultValue?: TResult + ): TResult; + } + + interface LoDashWrapperBase { + /** + * @see _.result + */ + result( + path: number|string|boolean|Array, + defaultValue?: TResult + ): TResult; + } + //_.set interface LoDashStatic { /** @@ -8379,21 +8407,6 @@ declare module _ { random(min: number, max: number, floating?: boolean): number; } - //_.result - interface LoDashStatic { - /** - * Resolves the value of property on object. If property is a function it will be invoked with - * the this binding of object and its result returned, else the property value is returned. If - * object is false then undefined is returned. - * @param object The object to query. - * @param path The path of the property to resolve. - * @param defaultValue The value returned if the resolved value is undefined. - * @return The resolved value. - **/ - - result(object: any, path: string|string[], defaultValue?: T): T; - } - //_.runInContext interface LoDashStatic { /**