forked from jorgebucaran/hyperapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hyperapp.d.ts
106 lines (93 loc) · 2.52 KB
/
hyperapp.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
export as namespace hyperapp
/** @namespace [VDOM] */
/** The VDOM representation of an Element.
*
* @memberOf [VDOM]
*/
export interface VNode<Attributes = {}> {
nodeName: string
attributes?: Attributes
children: Array<VNode | string>
key: string
}
/** A Component is a function that returns a custom VNode or View.
*
* @memberOf [VDOM]
*/
export interface Component<Attributes = {}, State = {}, Actions = {}> {
(attributes: Attributes, children: Array<VNode | string>):
| VNode<Attributes>
| View<State, Actions>
}
/**
* Possibles children types
*/
export type Children = VNode | string | number | null
/** The soft way to create a VNode.
* @param name An element name or a Component function
* @param attributes Any valid HTML atributes, events, styles, and meta data
* @param children The children of the VNode
* @returns A VNode tree.
*
* @memberOf [VDOM]
*/
export function h<Attributes>(
nodeName: Component<Attributes, any, any> | string,
attributes?: Attributes,
...children: Array<Children | Children[]>
): VNode<Attributes>
/** @namespace [App] */
/** The result of an action.
*
* @memberOf [App]
*/
export type ActionResult<State> = Partial<State> | Promise<any> | null | void
/** The interface for a single action implementation.
*
* @memberOf [App]
*/
export type ActionType<State, Actions> = (
data?: any
) =>
| ((state: State, actions: Actions) => ActionResult<State>)
| ActionResult<State>
/** The interface for the actions tree implementation.
*
* @memberOf [App]
*/
export type ActionsType<State, Actions> = {
[P in keyof Actions]:
| ActionType<State, Actions>
| ActionsType<any, Actions[P]>
}
/** The view function describes the application UI as a tree of VNodes.
* @returns A VNode tree.
* @memberOf [App]
*/
export interface View<State, Actions> {
(state: State, actions: Actions): VNode<object>
}
/** The app() call creates and renders a new application.
*
* @param state The state object.
* @param actions The actions object implementation.
* @param view The view function.
* @param container The DOM element where the app will be rendered to.
* @returns The actions wired to the application.
* @memberOf [App]
*/
export function app<State, Actions>(
state: State,
actions: ActionsType<State, Actions>,
view: View<State, Actions>,
container: Element | null
): Actions
/** @namespace [JSX] */
declare global {
namespace JSX {
interface Element extends VNode<any> {}
interface IntrinsicElements {
[elemName: string]: any
}
}
}