forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mithril.d.ts
94 lines (82 loc) · 2.84 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
// Type definitions for Mithril
// Project: http://lhorie.github.io/mithril/
// Definitions by: Leo Horie <https://github.com/lhorie>, Chris Bowdon <https://github.com/cbowdon>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
//Mithril type definitions for Typescript
interface MithrilStatic {
(selector: string, attributes: Object, children?: any): MithrilVirtualElement;
(selector: string, children?: any): MithrilVirtualElement;
prop<T>(value?: T): (value?: T) => T;
prop<T>(promise: MithrilPromise<T>): MithrilPromiseProperty<T>;
withAttr(property: string, callback: (value: any) => void): (e: Event) => any;
module(rootElement: Node, module: MithrilModule): void;
trust(html: string): String;
render(rootElement: Element, children?: any): void;
render(rootElement: HTMLDocument, children?: any): void;
redraw: MithrilRedraw;
route: MithrilRoute;
request(options: MithrilXHROptions): MithrilPromise<any>;
deferred<T>(): MithrilDeferred<T>;
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T>;
startComputation(): void;
endComputation(): void;
}
interface MithrilRoute {
(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
(element: Element, isInitialized: boolean): void;
(): string;
mode: string;
param: MithrilParam;
buildQueryString(data: Object): string;
parseQueryString(queryString: string): Object;
}
interface MithrilParam {
(param: string): string;
}
interface MithrilRedraw {
(): void;
strategy: (value?: string) => string;
}
interface MithrilVirtualElement {
tag: string;
attrs: Object;
children: any;
}
interface MithrilModule {
controller: Function;
view: (controller?: any) => MithrilVirtualElement;
}
interface MithrilDeferred<T> {
resolve(value?: T): void;
reject(value?: any): void;
promise: MithrilPromise<T>;
}
interface MithrilPromise<T> {
(value?: T): T;
then<R>(successCallback?: (value: T) => R, errorCallback?: (value: any) => any): MithrilPromise<R>;
then<R>(successCallback?: (value: T) => MithrilPromise<R>, errorCallback?: (value: any) => any): MithrilPromise<R>;
}
interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
(): T;
(value: T): T;
toJSON(): T;
}
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;
}
declare var Mithril: MithrilStatic;
declare var m: MithrilStatic;