Merge pull request #8757 from chrootsu/lodash-memoize

lodash: changed _.memoize
This commit is contained in:
Masahiro Wakame 2016-03-31 00:47:26 +09:00
commit e12c8e3bcd
4 changed files with 84 additions and 24 deletions

View File

@ -6162,20 +6162,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

@ -9820,6 +9820,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.
@ -9837,6 +9838,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

@ -6066,20 +6066,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

@ -10545,6 +10545,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.
@ -10562,6 +10563,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 {
/**