forked from jorgebucaran/hyperapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyperapp.d.ts
113 lines (99 loc) · 2.6 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
107
108
109
110
111
112
113
export as namespace Hyperapp
/** @namespace [VDOM] */
/** The VDOM representation of an Element.
*
* @memberOf [VDOM]
*/
export interface VNode<Props> {
name: string
props: Props
children: VNodeChild<object | null>[]
}
/** In the VDOM a Child can be either a VNode or a string.
*
* @memberOf [VDOM]
*/
export type VNodeChild<Props = object> = VNode<Props> | string
/** A Component is a function that returns a custom VNode.
*
* @memberOf [VDOM]
*/
export interface Component<Props> {
(props: Props, children: VNodeChild<object | null>[]): VNode<object>
}
/** The type of the children argument passed to h().
*
* @memberOf [VDOM]
*/
export type VNodeChildren =
| Array<VNodeChild<object | null> | number>
| VNodeChild<object | null>
| number
/** The soft way to create a VNode.
* @param name An element name or a Component function
* @param props 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<Props>(
name: Component<Props> | string,
props?: Props,
children?: VNodeChildren
): VNode<object>
/** @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 actions implementations.
*
* @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<Data> extends VNode<object> {}
interface IntrinsicElements {
[elemName: string]: any
}
}
}