This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.d.ts
180 lines (166 loc) · 4.15 KB
/
lib.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { ObjectOf } from "@riadh-adrani/utility-js/types";
export interface Flags {
/**
* ## `renderIf`
*
* A boolean indicating if the element should be rendered
* in the view.
*/
renderIf?: boolean;
/**
* ## `forceRerender`
*
* A boolean indicating if the element should override
* the old one without performing deep diffing.
*/
forceRerender?: boolean;
}
export interface Hooks<T = any> {
/**
* ## `onCreated`
*
* Hook executed when the element
* is rendered for the first time.
* When an element
* gets updated with another one having the same type,
* the `onCreated` hook of the new one won't be executed,
* the operation is not considered as a creation of a new element.
*/
onCreated?: (el: T) => void;
/**
* ## `onUpdated`
*
* Hook executed when the element attributes are removed, added or updated,
* or when events are added or removed.
*/
onUpdated?: (el: T) => void;
/**
* ## `onRef`
*
* Executed every time the app is updated.
* Return a string that will serve as the reference key.
*/
onRef?: (el: T) => void;
/**
* ## `beforeDestroyed`
*
* Executed before the element get removed from the DOM.
*/
beforeDestroyed?: (el: T) => void;
/**
* ## `onDestroyed`
*
* Executed after the element get removed from the DOM.
*/
onDestroyed?: () => void;
/**
* ## `onPrepared`
*
* Executed after the element is computed and checked.
*/
onPrepared?: (el: RecursiveElement) => void;
/**
* ## `onPrepared`
*
* Executed before element checking.
*/
beforePrepared?: (el: BaseElement) => void;
}
export interface CommonProps<T = any> {
elementType: string;
$$_RecursiveSymbol: Symbol;
rendererOptions?: { [item: string]: any };
hooks?: Hooks<T>;
flags?: Flags;
key?: string;
}
export interface BaseElement {
elementType: string;
$$_RecursiveSymbol: Symbol;
rendererOptions?: { [item: string]: any };
[key: string]: any;
}
export interface RecursiveElement<T = any> extends BaseElement {
style: { [item: string]: any };
attributes: { [item: string]: any };
events: ObjectOf<(e: any) => void>;
map: { [key: string]: number };
flags: Flags;
hooks: Hooks<T>;
parent: RecursiveElement<T>;
children: Array<RecursiveElement<T>>;
}
export type App = () => BaseElement;
export interface Route {
/**
* path fragment.
*
* except for the root path, you should not add a backslash `/` at the beginning of the path.
*/
path: string;
/**
* absolute route path that the app will try to redirect to.
*
* if it does not exist, a `/404` route will load instead.
*/
redirectTo?: string;
/**
* App title when the current route is mounted.
*/
title?: string;
/**
* nested routes.
*/
routes?: Array<Route>;
/**
* component callback representing the route.
*/
component: () => BaseElement | string;
/**
* callback executing when the route is mounted.
*/
onLoad?: () => void;
/**
* callback executing when the route is unmounted.
*/
onExit?: () => void;
}
export interface RouteTemplate {
isDynamic: boolean;
template: Route;
}
export interface ResolvedRoute {
path: String;
route: Route;
redirected: any;
}
export interface FlatRoutes {
[key: string]: Route;
}
export interface StateEntry {
value: any;
preValue: any;
history: Array<any>;
onRemoved: Function;
unsubscribe: Function;
addOrder: number;
}
export interface StateStores {
[key: string]: {
items: { [key: string]: StateEntry };
used: Array<String>;
set: (newValue: any) => void;
get: () => any;
clear: () => void;
flush: () => void;
};
}
export interface StoreParams {
name: String;
set: (newValue: any) => void;
get: () => any;
clear: () => void;
flush: () => void;
obj: any;
}
export type StateArray<T = any> = [T, (value: T) => void, () => T, () => void, T];