Merge pull request #5773 from chrootsu/lodash-result

lodash: changed _.result() method
This commit is contained in:
Masahiro Wakame
2015-09-16 22:34:08 +09:00
2 changed files with 39 additions and 31 deletions
+11 -16
View File
@@ -1681,6 +1681,17 @@ interface TestPickFn {
result = _({}).pick<TResult>(testPickFn, any).value();
}
// _.result
{
let testResultPath: number|string|boolean|Array<number|string|boolean>;
let testResultDefaultValue: TResult;
let result: TResult;
result = _.result<{}, TResult>({}, testResultPath);
result = _.result<{}, TResult>({}, testResultPath, testResultDefaultValue);
result = _({}).result<TResult>(testResultPath);
result = _({}).result<TResult>(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();
@@ -1752,22 +1763,6 @@ result = <void>_<string>([]).noop(true, 'a', 1);
result = <void>_({}).noop(true, 'a', 1);
result = <void>_(any).noop(true, 'a', 1);
var object = {
'cheese': 'crumpets',
'one': 1,
'nested': {
'two': 2
},
'stuff': function () {
return 'nonsense';
}
};
result = <string>_.result(object, 'cheese');
result = <string>_.result(object, 'stuff');
result = _.result<number>(object, 'one');
result = _.result<number>(object, ['nested', 'two'] );
var tempObject = {};
result = <typeof _>_.runInContext(tempObject);
+28 -15
View File
@@ -7560,6 +7560,34 @@ declare module _ {
): LoDashObjectWrapper<TResult>;
}
//_.result
interface LoDashStatic {
/**
* This method is like _.get except that if the resolved value is a function its 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<TObject, TResult>(
object: TObject,
path: number|string|boolean|Array<number|string|boolean>,
defaultValue?: TResult
): TResult;
}
interface LoDashWrapperBase<T, TWrapper> {
/**
* @see _.result
*/
result<TResult>(
path: number|string|boolean|Array<number|string|boolean>,
defaultValue?: TResult
): TResult;
}
//_.set
interface LoDashStatic {
/**
@@ -8399,21 +8427,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<T>(object: any, path: string|string[], defaultValue?: T): T;
}
//_.runInContext
interface LoDashStatic {
/**