1 | export as namespace hyperapp
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export interface VNode<Attributes = {}> {
|
10 | nodeName: string
|
11 | attributes?: Attributes
|
12 | children: Array<VNode | string>
|
13 | key: string | number | null
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export interface Component<Attributes = {}, State = {}, Actions = {}> {
|
21 | (attributes: Attributes, children: Array<VNode | string>):
|
22 | | VNode<Attributes>
|
23 | | View<State, Actions>
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | export type Children = VNode | string | number | null
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export function h<Attributes>(
|
40 | nodeName: Component<Attributes, any, any> | string,
|
41 | attributes?: Attributes,
|
42 | ...children: Array<Children | Children[]>
|
43 | ): VNode<Attributes>
|
44 |
|
45 | /** @namespace [App] */
|
46 |
|
47 | /** The result of an action.
|
48 | *
|
49 | * @memberOf [App]
|
50 | */
|
51 | export type ActionResult<State> = Partial<State> | Promise<any> | null | void
|
52 |
|
53 | /** The interface for a single action implementation.
|
54 | *
|
55 | * @memberOf [App]
|
56 | */
|
57 | export type ActionType<Data, State, Actions> = (
|
58 | data?: Data
|
59 | ) =>
|
60 | | ((state: State, actions: Actions) => ActionResult<State>)
|
61 | | ActionResult<State>
|
62 |
|
63 | /** The interface for the actions tree implementation.
|
64 | *
|
65 | * @memberOf [App]
|
66 | */
|
67 | export type ActionsType<State, Actions> = {
|
68 | [P in keyof Actions]:
|
69 | | ActionType<any, State, Actions>
|
70 | | ActionsType<any, Actions[P]>
|
71 | }
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | export interface View<State, Actions> {
|
78 | (state: State, actions: Actions): VNode<object> | null
|
79 | }
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | export function app<State, Actions>(
|
91 | state: State,
|
92 | actions: ActionsType<State, Actions>,
|
93 | view: View<State, Actions>,
|
94 | container: Element | null
|
95 | ): Actions
|
96 |
|
97 | /** @namespace [JSX] */
|
98 |
|
99 | declare global {
|
100 | namespace JSX {
|
101 | interface Element extends VNode<any> {}
|
102 | interface IntrinsicElements {
|
103 | [elemName: string]: any
|
104 | }
|
105 | }
|
106 | }
|