lodash: changed _.memoize

This commit is contained in:
Ilya Mochalov
2016-02-17 20:31:18 +05:00
parent 80057d687a
commit bd2fc2e672
4 changed files with 84 additions and 24 deletions

View File

@@ -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<MemoizedResultFn>;
result = _(memoizeFn).memoize();
result = _(memoizeFn).memoize(memoizeResolverFn);
}
{
let result: _.LoDashExplicitObjectWrapper<MemoizedResultFn>;
result = _(memoizeFn).chain().memoize();
result = _(memoizeFn).chain().memoize(memoizeResolverFn);
}
_.memoize.Cache = {
delete: key => false,
get: key => undefined,

View File

@@ -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<T & MemoizedFunction>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.memoize
*/
memoize(resolver?: Function): LoDashExplicitObjectWrapper<T & MemoizedFunction>;
}
//_.modArgs
interface LoDashStatic {
/**

View File

@@ -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<MemoizedResultFn>;
result = _(memoizeFn).memoize();
result = _(memoizeFn).memoize(memoizeResolverFn);
}
{
let result: _.LoDashExplicitObjectWrapper<MemoizedResultFn>;
result = _(memoizeFn).chain().memoize();
result = _(memoizeFn).chain().memoize(memoizeResolverFn);
}
_.memoize.Cache = {
delete: key => false,
get: key => undefined,

8
lodash/lodash.d.ts vendored
View File

@@ -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<T & MemoizedFunction>;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.memoize
*/
memoize(resolver?: Function): LoDashExplicitObjectWrapper<T & MemoizedFunction>;
}
//_.overArgs (was _.modArgs)
interface LoDashStatic {
/**