From bd2fc2e67233f722e6be1508d7da736e0e88cfe3 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Wed, 17 Feb 2016 20:31:18 +0500 Subject: [PATCH] lodash: changed _.memoize --- lodash/lodash-3.10-tests.ts | 46 +++++++++++++++++++++++++++---------- lodash/lodash-3.10.d.ts | 8 +++++++ lodash/lodash-tests.ts | 46 +++++++++++++++++++++++++++---------- lodash/lodash.d.ts | 8 +++++++ 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/lodash/lodash-3.10-tests.ts b/lodash/lodash-3.10-tests.ts index 8d19f394a1..1c094912b8 100644 --- a/lodash/lodash-3.10-tests.ts +++ b/lodash/lodash-3.10-tests.ts @@ -6097,20 +6097,42 @@ namespace TestFlowRight { // _.memoize namespace TestMemoize { - var testMemoizedFunction: _.MemoizedFunction; - var cache = <_.MapCache>testMemoizedFunction.cache; - interface TestMemoizedResultFn extends _.MemoizedFunction { + { + let memoizedFunction: _.MemoizedFunction; + let cache: _.MapCache = memoizedFunction.cache; + } + + interface MemoizedResultFn extends _.MemoizedFunction { (a1: string, a2: number): boolean; } - var testMemoizeFn = (a1: string, a2: number) => a1.length > a2; - var testMemoizeResolverFn = (a1: string, a2: number) => a1 + a2; - var result: TestMemoizedResultFn; - result = _.memoize(testMemoizeFn); - result = _.memoize(testMemoizeFn, testMemoizeResolverFn); - result = _(testMemoizeFn).memoize().value(); - result = _(testMemoizeFn).memoize(testMemoizeResolverFn).value(); - result('foo', 1); - result.cache.get('foo1'); + + let memoizeFn: (a1: string, a2: number) => boolean; + let memoizeResolverFn: (a1: string, a2: number) => string; + + { + let result: MemoizedResultFn; + + result = _.memoize(memoizeFn); + result = _.memoize(memoizeFn, memoizeResolverFn); + + result('foo', 1); + result.cache.get('foo1'); + } + + { + let result: _.LoDashImplicitObjectWrapper; + + result = _(memoizeFn).memoize(); + result = _(memoizeFn).memoize(memoizeResolverFn); + } + + { + let result: _.LoDashExplicitObjectWrapper; + + result = _(memoizeFn).chain().memoize(); + result = _(memoizeFn).chain().memoize(memoizeResolverFn); + } + _.memoize.Cache = { delete: key => false, get: key => undefined, diff --git a/lodash/lodash-3.10.d.ts b/lodash/lodash-3.10.d.ts index c2fb9f726b..5ba05dc47d 100644 --- a/lodash/lodash-3.10.d.ts +++ b/lodash/lodash-3.10.d.ts @@ -9735,6 +9735,7 @@ declare module _ { * storing the result based on the arguments provided to the memoized function. By default, the first argument * provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with * the this binding of the memoized function. + * * @param func The function to have its output memoized. * @param resolver The function to resolve the cache key. * @return Returns the new memoizing function. @@ -9752,6 +9753,13 @@ declare module _ { memoize(resolver?: Function): LoDashImplicitObjectWrapper; } + interface LoDashExplicitObjectWrapper { + /** + * @see _.memoize + */ + memoize(resolver?: Function): LoDashExplicitObjectWrapper; + } + //_.modArgs interface LoDashStatic { /** diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c8c824bd79..4772f1d33e 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5977,20 +5977,42 @@ namespace TestFlowRight { // _.memoize namespace TestMemoize { - var testMemoizedFunction: _.MemoizedFunction; - var cache = <_.MapCache>testMemoizedFunction.cache; - interface TestMemoizedResultFn extends _.MemoizedFunction { + { + let memoizedFunction: _.MemoizedFunction; + let cache: _.MapCache = memoizedFunction.cache; + } + + interface MemoizedResultFn extends _.MemoizedFunction { (a1: string, a2: number): boolean; } - var testMemoizeFn = (a1: string, a2: number) => a1.length > a2; - var testMemoizeResolverFn = (a1: string, a2: number) => a1 + a2; - var result: TestMemoizedResultFn; - result = _.memoize(testMemoizeFn); - result = _.memoize(testMemoizeFn, testMemoizeResolverFn); - result = _(testMemoizeFn).memoize().value(); - result = _(testMemoizeFn).memoize(testMemoizeResolverFn).value(); - result('foo', 1); - result.cache.get('foo1'); + + let memoizeFn: (a1: string, a2: number) => boolean; + let memoizeResolverFn: (a1: string, a2: number) => string; + + { + let result: MemoizedResultFn; + + result = _.memoize(memoizeFn); + result = _.memoize(memoizeFn, memoizeResolverFn); + + result('foo', 1); + result.cache.get('foo1'); + } + + { + let result: _.LoDashImplicitObjectWrapper; + + result = _(memoizeFn).memoize(); + result = _(memoizeFn).memoize(memoizeResolverFn); + } + + { + let result: _.LoDashExplicitObjectWrapper; + + result = _(memoizeFn).chain().memoize(); + result = _(memoizeFn).chain().memoize(memoizeResolverFn); + } + _.memoize.Cache = { delete: key => false, get: key => undefined, diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 790107369d..8383f3234e 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -10467,6 +10467,7 @@ declare module _ { * storing the result based on the arguments provided to the memoized function. By default, the first argument * provided to the memoized function is coerced to a string and used as the cache key. The func is invoked with * the this binding of the memoized function. + * * @param func The function to have its output memoized. * @param resolver The function to resolve the cache key. * @return Returns the new memoizing function. @@ -10484,6 +10485,13 @@ declare module _ { memoize(resolver?: Function): LoDashImplicitObjectWrapper; } + interface LoDashExplicitObjectWrapper { + /** + * @see _.memoize + */ + memoize(resolver?: Function): LoDashExplicitObjectWrapper; + } + //_.overArgs (was _.modArgs) interface LoDashStatic { /**