From 0d690600294d71ec5857da54227b1e7b5e0ba1d6 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Thu, 3 Mar 2016 21:27:59 +0500 Subject: [PATCH] lodash: added _.update --- lodash/lodash-tests.ts | 45 +++++++++++++++++++++++ lodash/lodash.d.ts | 81 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 3a857f040..02fd3b282 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -9619,6 +9619,51 @@ namespace TestUnset { } } +// _.update +namespace TestUpdate { + type SampleObject = {a: {}}; + type SampleResult = {a: {b: number[]}}; + + let object: SampleObject; + let updater: (value: any) => number; + + { + let result: SampleResult; + + result = _.update(object, 'a.b[1]', updater); + result = _.update(object, ['a', 'b', 1], updater); + + result = _.update<(value: any) => number, SampleResult>(object, 'a.b[1]', updater); + result = _.update<(value: any) => number, SampleResult>(object, ['a', 'b', 1], updater); + + result = _.update(object, 'a.b[1]', updater); + result = _.update(object, ['a', 'b', 1], updater); + + result = _.update number, SampleResult>(object, 'a.b[1]', updater); + result = _.update number, SampleResult>(object, ['a', 'b', 1], updater); + } + + { + let result: _.LoDashImplicitObjectWrapper; + + result = _(object).update('a.b[1]', updater); + result = _(object).update(['a', 'b', 1], updater); + + result = _(object).update<(value: any) => number, SampleResult>('a.b[1]', updater); + result = _(object).update<(value: any) => number, SampleResult>(['a', 'b', 1], updater); + } + + { + let result: _.LoDashExplicitObjectWrapper; + + result = _(object).chain().update('a.b[1]', updater); + result = _(object).chain().update(['a', 'b', 1], updater); + + result = _(object).chain().update<(value: any) => number, SampleResult>('a.b[1]', updater); + result = _(object).chain().update<(value: any) => number, SampleResult>(['a', 'b', 1], updater); + } +} + // _.values module TestValues { let object: _.Dictionary; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 903497617..f567c4fec 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -16216,6 +16216,87 @@ declare module _ { unset(path: StringRepresentable|StringRepresentable[]): LoDashExplicitWrapper; } + //_.update + interface LoDashStatic { + /** + * This method is like _.set except that accepts updater to produce the value to set. Use _.updateWith to + * customize path creation. The updater is invoked with one argument: (value). + * + * @param object The object to modify. + * @param path The path of the property to set. + * @param updater The function to produce the updated value. + * @return Returns object. + */ + update( + object: Object, + path: StringRepresentable|StringRepresentable[], + updater: Function + ): TResult; + + /** + * @see _.update + */ + update( + object: Object, + path: StringRepresentable|StringRepresentable[], + updater: U + ): TResult; + + /** + * @see _.update + */ + update( + object: O, + path: StringRepresentable|StringRepresentable[], + updater: Function + ): TResult; + + /** + * @see _.update + */ + update( + object: O, + path: StringRepresentable|StringRepresentable[], + updater: U + ): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: any + ): LoDashImplicitObjectWrapper; + + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: U + ): LoDashImplicitObjectWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: any + ): LoDashExplicitObjectWrapper; + + /** + * @see _.update + */ + update( + path: StringRepresentable|StringRepresentable[], + updater: U + ): LoDashExplicitObjectWrapper; + } + //_.values interface LoDashStatic { /**