-
Notifications
You must be signed in to change notification settings - Fork 4
/
react-memoize.d.ts
56 lines (44 loc) · 1.61 KB
/
react-memoize.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
declare module 'react-memoize' {
import * as React from 'react';
export type PropOf<T extends { [key: string]: any }> = {
[K in keyof T]: T[K];
};
export type NotRequired<T extends { [key: string]: any }> = {
[K in keyof T]?: T[K];
};
export type RenderFn<T> = (value: T) => React.ReactNode;
export type ConsumerProps<T> = { children: RenderFn<T> | [RenderFn<T>] };
type ItoI<T, K = NotRequired<T> > = (input: T) => K;
interface Nothing {}
type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T];
export type Minus<T, U> = {[P in Diff<keyof T, keyof U>]: T[P]};
export interface MemoizeProps<T, K> {
compute: (props: Minus<K,MemoizePropsMinus>) => T;
children: RenderFn<T>;
pure?: boolean
}
export interface MemoizePropsMinus {
compute: any;
children: any;
pure: any
}
export interface ContextProps<T, R> {
selector: (props: NotRequired<T> ) => R;
children: RenderFn<any>
consumer: React.ComponentClass<ConsumerProps<T>>;
}
export interface FlowProps<T> {
input: T,
flow: ItoI<T>[],
children: RenderFn<T>;
}
/**
* Memoizes the `compute` function, and provide a result as a render prop
*/
export default class ReactMemoize<T, B, K = PropOf<B>> extends React.Component<MemoizeProps<T, K> & B> {
}
export class MemoizeContext<T, R> extends React.Component<ContextProps<T, R>, {}> {
}
export class MemoizedFlow<T> extends React.Component<FlowProps<T>, {}> {
}
}