-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmemoize-state.d.ts
99 lines (92 loc) · 2.96 KB
/
memoize-state.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
declare module 'memoize-state' {
interface MemoizeStateOptions {
/**
* the size of the cache
* @default 1
*/
cacheSize?: number,
/**
* allow shallow arguments check
* @default true
*/
shallowCheck: boolean,
/**
* allow equal argiments check
* @default true
*/
equalCheck: boolean,
/**
* respond only to the "used" amount of arguments (not working with spread)
* @default false
*/
strictArity: boolean,
/**
* maintain the equal object equality
* @default true
*/
nestedEquality: boolean,
/**
* perform additional safe checks
* @default false
*/
safe: boolean
}
export type NotRequired<T extends { [key: string]: any }> = {
[K in keyof T]?: T[K];
};
export type Mapper<T, K = NotRequired<T> > = (input: T) => K;
type ResultFunction<T> = (input: T) => T;
/**
* Memoizes the function basing on paramiters actually used by a function
* @param {T} functor - function to be wrapped
* @param {MemoizeStateOptions} [memoizationOptions], options
* @return {T}
* @example
* const memoizedFn = memoize(fn)
*/
export default function memoize<T>(functor: T, memoizationOptions?: MemoizeStateOptions): T;
/**
* Flow(pipe) memoization composition.
* @param {Mapper[]} flow - array of functions to be applied from left to right
* @return {Function}
*/
export function memoizedFlow<T>(flow: Mapper<T>): ResultFunction<T>;
/**
* Flow(pipe) memoization composition.
* @param {Mapper[]} flow - array of functions to be applied from left to right
* @return {Function}
*/
export function memoizedPipe<T>(flow: Mapper<T>): ResultFunction<T>;
/**
* FlowRight(compose) memoization composition.
* @param {Mapper[]} flow - array of functions to be applied from right to left
* @return {Function}
*/
export function memoizedFlowRight<T>(flow: Mapper<T>): ResultFunction<T>;
/**
* FlowRight(compose) memoization composition.
* @param {Mapper[]} flow - array of functions to be applied from right to left
* @return {Function}
*/
export function memoizedCompose<T>(flow: Mapper<T>): ResultFunction<T>;
/**
* double checks that function inside the `executor` is a pure function
* @param {() => any} executor
* @return {boolean}
* @example
* isThisPure(() => someFn())
*/
export function isThisPure(executor: () => any): boolean
/**
* perform consistent checks, that fn is a pure function.
* @param {T} fn
* @return {T}
*/
export function shallBePure<T>(fn: T): T
/**
* perform consistent checks, that fn is a pure function in DEV env only
* @param {T} fn
* @return {T}
*/
export function shouldBePure<T>(fn: T): T
}