forked from MithrilJS/mithril.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmithril.d.ts
165 lines (130 loc) · 4.49 KB
/
mithril.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
//Mithril type definitions for Typescript
interface MithrilStatic {
(selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
(selector: string, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>;
prop<T>(value: T): MithrilProperty<T>;
prop(): MithrilProperty<Object>; // might be that this should be Property<any>
withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any;
module<T extends MithrilController>(rootElement: Node, module: MithrilModule<T>): T;
module<T extends MithrilController>(rootElement: Node): T;
trust(html: string): string;
render(rootElement: Element|HTMLDocument): void;
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void;
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void;
redraw: {
(force?: boolean): void;
strategy: MithrilProperty<string>;
}
route: {
<T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void;
<T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void;
(element: Element, isInitialized: boolean): void;
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
(): string;
param(key: string): string;
mode: string;
}
request<T>(options: MithrilXHROptions): MithrilPromise<T>;
deferred: {
onerror(e: Error): void;
<T>(): MithrilDeferred<T>;
}
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>;
startComputation(): void;
endComputation(): void;
// For test suite
deps: {
(mockWindow: Window): Window;
factory: Object;
}
}
interface MithrilVirtualElement {
key?: number;
tag?: string;
attrs?: MithrilAttributes;
children?: any[];
}
// Configuration function for an element
interface MithrilElementConfig {
(element: Element, isInitialized: boolean, context?: any): void;
}
// Attributes on a virtual element
interface MithrilAttributes {
title?: string;
className?: string;
class?: string;
config?: MithrilElementConfig;
}
// Defines the subset of Event that Mithril needs
interface MithrilEvent {
currentTarget: Element;
}
interface MithrilController {
onunload?(evt: Event): any;
}
interface MithrilControllerFunction extends MithrilController {
(): any;
}
interface MithrilView<T extends MithrilController> {
(ctrl: T): string|MithrilVirtualElement;
}
interface MithrilModule<T extends MithrilController> {
controller: MithrilControllerFunction|{ new(): T };
view: MithrilView<T>;
}
interface MithrilProperty<T> {
(): T;
(value: T): T;
toJSON(): T;
}
interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
(): T;
(value: T): T;
toJSON(): T;
}
interface MithrilRoutes<T extends MithrilController> {
[key: string]: MithrilModule<T>;
}
interface MithrilDeferred<T> {
resolve(value?: T): void;
reject(value?: any): void;
promise: MithrilPromise<T>;
}
interface MithrilSuccessCallback<T, U> {
(value: T): U;
(value: T): MithrilPromise<U>;
}
interface MithrilErrorCallback<U> {
(value: Error): U;
(value: string): U;
}
interface MithrilPromise<T> {
(): T;
(value: T): T;
then<U>(success: (value: T) => U): MithrilPromise<U>;
then<U>(success: (value: T) => MithrilPromise<U>): MithrilPromise<U>;
then<U,V>(success: (value: T) => U, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
then<U,V>(success: (value: T) => MithrilPromise<U>, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
}
interface MithrilXHROptions {
method?: string;
url: string;
user?: string;
password?: string;
data?: any;
background?: boolean;
unwrapSuccess?(data: any): any;
unwrapError?(data: any): any;
serialize?(dataToSerialize: any): string;
deserialize?(dataToDeserialize: string): any;
extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string;
type?(data: Object): void;
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
dataType?: string;
}
declare var Mithril: MithrilStatic;
declare var m: MithrilStatic;
declare module 'mithril' {
export = m;
}