This repository was archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcomponent.d.ts
More file actions
100 lines (83 loc) · 2.17 KB
/
component.d.ts
File metadata and controls
100 lines (83 loc) · 2.17 KB
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
100
declare namespace tinyapp {
interface IComponentLifeCycleMethods<D, P> {
/**
* 组件生命周期函数,组件创建时触发
*/
onInit?(): void;
/**
* 组件生命周期函数,组件创建时和更新前触发
*
* @param nextProps 接收到的 props 数据
*/
deriveDataFromProps?(nextProps: Partial<P>): void;
/**
* 组件生命周期函数,组件创建完毕时触发
*/
didMount?(): void;
/**
* 组件生命周期函数,组件更新完毕时触发
*/
didUpdate?(prevProps: Partial<P>, prevData: Partial<D>): void;
/**
* 组件生命周期函数,组件删除时触发
*/
didUnmount?(): void;
}
interface IComponentMethods {
[name: string]: (...args: any[]) => void;
}
interface IComponentInstance<P, D> extends Record<string, any> {
/**
* 组件内部状态
*/
readonly data: D;
/**
* 传入组件的属性
*/
readonly props: P;
/**
* 设置data触发视图渲染
*/
setData: SetDataMethod<D>;
/**
* 组件所属页面实例
*/
readonly $page: IPageInstance<any>;
/**
* 组件 id,可直接在组件 axml 中渲染值
*/
readonly $id: number;
/**
* 组件路径
*/
readonly is: string;
/**
* 同 setData,但是相比于 setData,在处理长列表的时候,其具有更高的性能
*/
$spliceData: SpliceDataMethod;
}
interface InternalComponentOptions<P, D, M> {
/**
* 组件间代码复用机制
*/
mixins?: Array<ComponentOptions<any, any, any>>;
/**
* 组件内部状态
*/
data?: D;
/**
* 为外部传入的数据设置默认值
*/
props?: P;
/**
* 组件的方法,可以是事件响应函数或任意的自定义方法
*/
methods?: M & ThisType<IComponentInstance<P, D> & M>;
}
interface ComponentOptions<
P extends Record<string, any> = Record<string, any>,
D = any,
M extends IComponentMethods = IComponentMethods,
> extends IComponentLifeCycleMethods<D, P>, InternalComponentOptions<P, D, M>, ThisType<IComponentInstance<P, D> & M> {
}
}