@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
28 lines (27 loc) • 1.38 kB
TypeScript
import type { AnyToAnyFnSignature } from './functions';
/** Memoized function type */
export type MemoizedFn<T extends AnyToAnyFnSignature> = T & {
/** Cache instance */
cache: Map<null | string, ReturnType<T>>;
/** Clear memoization cache */
clear: () => void;
/** Check existence of cache for passed params */
has: (...params: Parameters<T>) => boolean;
};
/**
* Memoization decorator function. Caches the original function result according to hash generated from arguments.
* In case the hash function returns `undefined` value will not be memoized.
* @see MemoHashFn Hash function signature.
*/
export declare function memoizeFn<F extends AnyToAnyFnSignature>(fn: F, hashFn?: MemoHashFn<F>): MemoizedFn<F>;
/**
* Describe abstract memoization hash function. Memoization should have the same or compatible signature as the decorated function.
* Hash function can return string or null as a hash result. Note: null is correct hash for arguments!
* If the result is `undefined` - it means that the hash can not be generated.
*/
export type MemoHashFn<F extends AnyToAnyFnSignature = AnyToAnyFnSignature> = (...args: Parameters<F>) => undefined | null | string;
/**
* Default arguments hash function.
* Supports only 0-1 arguments with a primitive type.
*/
export declare function defaultArgsHashFn(...args: any[]): string | null | undefined;