1 | declare namespace tinyapp {
|
2 | interface IComponentLifeCycleMethods<D, P> {
|
3 | |
4 |
|
5 |
|
6 | onInit?(): void;
|
7 |
|
8 | |
9 |
|
10 |
|
11 |
|
12 |
|
13 | deriveDataFromProps?(nextProps: Partial<P>): void;
|
14 |
|
15 | |
16 |
|
17 |
|
18 | didMount?(): void;
|
19 |
|
20 | |
21 |
|
22 |
|
23 | didUpdate?(prevProps: Partial<P>, prevData: Partial<D>): void;
|
24 |
|
25 | |
26 |
|
27 |
|
28 | didUnmount?(): void;
|
29 | }
|
30 |
|
31 | interface IComponentMethods {
|
32 | [name: string]: (...args: any[]) => void;
|
33 | }
|
34 |
|
35 | interface IComponentInstance<P, D> extends Record<string, any> {
|
36 | |
37 |
|
38 |
|
39 | readonly data: D;
|
40 |
|
41 | |
42 |
|
43 |
|
44 | readonly props: P;
|
45 |
|
46 | |
47 |
|
48 |
|
49 | setData: SetDataMethod<D>;
|
50 |
|
51 | |
52 |
|
53 |
|
54 | readonly $page: IPageInstance<any>;
|
55 |
|
56 | |
57 |
|
58 |
|
59 | readonly $id: number;
|
60 |
|
61 | |
62 |
|
63 |
|
64 | readonly is: string;
|
65 |
|
66 | |
67 |
|
68 |
|
69 | $spliceData: (operations: { [k: string]: [number, number, ...any[]] }) => void;
|
70 | }
|
71 |
|
72 | type ComponentOptions<
|
73 | P extends Record<string, any> = Record<string, any>,
|
74 | D = any,
|
75 | M extends IComponentMethods = IComponentMethods,
|
76 | > = IComponentLifeCycleMethods<D, P>
|
77 | & {
|
78 | |
79 |
|
80 |
|
81 | mixins?: Array<ComponentOptions<any, any, any>>;
|
82 |
|
83 | |
84 |
|
85 |
|
86 | data?: D;
|
87 |
|
88 | |
89 |
|
90 |
|
91 | props?: P;
|
92 |
|
93 | |
94 |
|
95 |
|
96 | methods?: M & ThisType<IComponentInstance<P, D> & M>;
|
97 | }
|
98 | & ThisType<IComponentInstance<P, D> & M>;
|
99 | }
|