This repository has been archived by the owner on May 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.d.ts
444 lines (369 loc) · 8.71 KB
/
types.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import { Store } from './lib/store';
declare global {
type InjectorNode = Node;
type InjectorItem = any;
type ComponentEventHandler = (component: Component, event: Event, target: HTMLElement) => void;
type StaticEventHandler = (evt: Event) => void;
interface DisposeCallback {
(scope: object): void
}
interface BlockDisposeCallback {
(block: BaseBlock): void;
}
interface Component extends HTMLElement {
/**
* Pointer to component view container. By default, it’s the same as component
* element, but for native Web Components it points to shadow root
*/
componentView: Element;
/**
* Internal component model
*/
componentModel: ComponentModel;
/**
* Component properties (external contract)
*/
props: object;
/**
* Component state (internal props)
*/
state: object;
/**
* Named references to elements rendered inside current component
*/
refs: RefMap;
/**
* A store, bound to current component
*/
store?: Store;
/**
* References to component slot containers. Default slot is available as `slot['']`
*/
slots: RefMap;
/**
* Reference to the root component of the current app
*/
root?: Component;
/**
* Updates props with data from `value`
* @param value Updated props
* @returns Final props
*/
setProps(value: object): void;
/**
* Updates state with data from `value`
* @param value Updated values
* @returns Final state
*/
setState(value: object): void;
}
/**
* Internal Endorphin component descriptor
*/
interface ComponentModel {
/**
* Component’s definition
*/
definition: ComponentDefinition;
/**
* Injector for incoming component data
* @private
*/
input: Injector;
/**
* Change set for component refs
* @private
*/
refs: ChangeSet;
/**
* Runtime variables
*/
vars: object;
/**
* A function for updating rendered component content. Might be available
* after component was mounted and only if component has update cycle
*/
update?: UpdateView;
/**
* List of attached event handlers
*/
events: AttachedStaticEvents;
/** Slot output for component */
slots: {
[name: string]: BaseBlock
}
/**
* Slots update status
*/
slotStatus?: {
[name: string]: number
};
/**
* Indicates that component was mounted
* @private
*/
mounted: boolean;
/**
* Component render is queued
* @private
*/
queued: boolean;
/**
* Indicates that component is currently rendering
* @private
*/
rendering: boolean;
/**
* Indicates that component is currently in finalization state (calling
* `did*` hooks)
* @private
*/
finalizing: boolean;
/**
* Default props values
*/
defaultProps: object;
/**
* A function for disposing component contents
*/
dispose?: DisposeCallback
}
/**
* A definition of component, written as ES module
*/
interface ComponentDefinition {
/**
* Initial props factory
*/
props?(component: Component): object;
/**
* Initial state factory
*/
state?(component: Component): object;
/**
* Returns instance of store used for components
*/
store?(): Store;
/**
* Returns pointer to element where contents of component should be rendered
*/
componentView?(component: Component, parentComponent?: Component | Element): Element;
/**
* Listeners for events bubbling from component contents
*/
events?: {
[type: string]: ComponentEventHandler;
};
/**
* Public methods to attach to component element
* @deprecated Use `extend` instead
*/
methods?: {
[name: string]: (this: Component) => void;
};
/**
* Methods and properties to extend component with
*/
extend?: object;
/**
* List of plugins for current component
*/
plugins?: ComponentDefinition[];
/**
* A scope token to be added for every element, created inside current component
* bound
*/
cssScope?: string;
/**
* A function for rendering component contents. Will be added automatically
* in compilation step with compiled HTML template, if not provided.
* If rendered result must be updated, should return function that will be
* invoked for update
*/
default(component: Component, scope: object): UpdateView;
/**
* Component created
*/
init?(component: Component): void;
/**
* Component is about to be mounted (will be initially rendered)
*/
willMount?(component: Component): void;
/**
* Component just mounted (initially rendered)
* @param component
*/
didMount?(component: Component): void;
/**
* Component props changed
*/
didChange?(component: Component, changes: Changes): void;
/**
* Component is about to be updated (next renders after mount)
* @param component
* @param changedProps List of changed properties which caused component update
* @param changedState List of changed state which caused component update
*/
willUpdate?(component: Component, changes: Changes): void;
/**
* Component just updated (next renders after mount)
* @param component
* @param changedProps List of changed properties which caused component update
* @param changedState List of changed state which caused component update
*/
didUpdate?(component: Component, changes: Changes): void;
/**
* Component is about to be rendered. If `false` value is returned, component
* rendering will be cancelled
* @param component
* @param changedProps List of changed properties which caused component update
* @param changedState List of changed state which caused component update
*/
willRender?(component: Component, changes: Changes): boolean;
/**
* Component just rendered
* @param component
* @param changedProps List of changed properties which caused component update
* @param changedState List of changed state which caused component update
*/
didRender?(component: Component, changes: Changes): void;
/**
* Component is about to be removed
*/
willUnmount?(component: Component): void;
/**
* Component was removed
*/
didUnmount?(component: Component): void;
}
interface Injector {
/**
* Injector DOM target
*/
parentNode: Element;
/**
* Current injector contents
*/
items: LinkedList;
/**
* Current insertion pointer
*/
ptr: LinkedListItem<any>;
/**
* Current block context
*/
ctx: BaseBlock;
/**
* Slots container
*/
slots?: {
[name: string]: DocumentFragment | Element
};
/**
* Pending attributes updates
*/
attributes: ChangeSet;
attributesNS?: {
[uri: string]: ChangeSet
}
/**
* Current event handlers
*/
events: ChangeSet;
}
interface AttachedStaticEvents {
handler: StaticEventHandler;
listeners: {
[event: string]: ComponentEventHandler[];
}
}
interface RefMap {
[key: string]: Element;
}
interface ChangeSet {
prev: object;
cur: object;
}
interface Changes {
[key: string]: {
current: any,
prev: any
}
};
interface UpdateView {
(host: Component, scope: object): void;
}
interface SlotContext {
host: Component;
name: string;
isDefault: boolean;
defaultContent: Function;
}
interface StoreUpdateHandler {
(state: object, changes: object): void
}
interface StoreUpdateEntry {
keys?: string[];
component?: Component;
handler?: StoreUpdateHandler;
}
interface LinkedList {
head: LinkedListItem;
}
interface LinkedListItem<T> {
value: T;
next: LinkedListItem<any> | null;
prev: LinkedListItem<any> | null;
}
interface BaseBlock<T> {
$$block: true;
host: Component;
injector: Injector;
scope: any;
/** A function to dispose block contents */
dispose: BlockDisposeCallback | null;
start: LinkedListItem<T>;
end: LinkedListItem<T>;
}
interface FunctionBlock extends BaseBlock<FunctionBlock> {
get: Function;
fn: Function | undefined;
update: Function | undefined;
}
interface IteratorBlock extends BaseBlock<IteratorBlock> {
get: Function;
body: Function;
index: number;
updated: number;
}
interface KeyIteratorBlock extends IteratorBlock {
keyExpr: Function;
used: {
[key: string]: IteratorItemBlock[]
} | null;
rendered: {
[key: string]: IteratorItemBlock[]
} | null;
order: IteratorItemBlock[];
needReorder: boolean;
parentScope: object;
}
interface IteratorItemBlock extends BaseBlock<IteratorItemBlock> {
update: Function | undefined;
owner: IteratorBlock | KeyIteratorBlock;
}
interface InnerHtmlBlock extends BaseBlock<InnerHtmlBlock> {
get: Function;
code: any;
slotName: string;
}
interface PartialBlock extends BaseBlock<PartialBlock> {
update: Function | null;
partial: PartialDefinition | null;
}
interface PartialDefinition {
host: Component;
body: Function;
defaults: object;
}
}