mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #2818 from cbowdon/mithril
Included Mithril definitions.
This commit is contained in:
@@ -254,6 +254,7 @@ All definitions files include a header with the author and editors, so at some p
|
||||
* [Microsoft Live Connect](http://msdn.microsoft.com/en-us/library/live/hh243643.aspx) (by [John Vilk](https://github.com/jvilk))
|
||||
* [Minimatch](https://github.com/isaacs/minimatch) (by [vvakame](https://github.com/vvakame))
|
||||
* [minimist](https://github.com/substack/minimist) (by [Bart van der Schoor](https://github.com/Bartvds))
|
||||
* [Mithril](http://lhorie.github.io/mithril) (by [Leo Horie](https://github.com/lhorie) and [Chris Bowdon](https://github.com/cbowdon))
|
||||
* [Mixpanel](https://github.com/mixpanel/mixpanel-js) (by [Knut Eirik Leira Hjelle](https://github.com/hjellek))
|
||||
* [mixto](https://github.com/atom/mixto) (by [vvakame](https://github.com/vvakame))
|
||||
* [Modernizr](http://modernizr.com/) (by [Boris Yankov](https://github.com/borisyankov) and [Theodore Brown](https://github.com/theodorejb/))
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/// <reference path="mithril.d.ts" />
|
||||
// This is the todolist example from http://lhorie.github.io/mithril/getting-started.html
|
||||
|
||||
var todo = {
|
||||
|
||||
//the Todo class has two properties
|
||||
Todo: function(data: any) {
|
||||
this.description = m.prop(data.description);
|
||||
this.done = m.prop(false);
|
||||
},
|
||||
|
||||
//the TodoList class is a list of Todo's
|
||||
TodoList: Array,
|
||||
|
||||
//the controller uses three model-level entities, of which one is a custom defined class:
|
||||
//`Todo` is the central class in this application
|
||||
//`list` is merely a generic array, with standard array methods
|
||||
//`description` is a temporary storage box that holds a string
|
||||
//
|
||||
//the `add` method simply adds a new todo to the list
|
||||
controller: function() {
|
||||
this.list = new todo.TodoList();
|
||||
this.description = m.prop("");
|
||||
|
||||
this.add = function() {
|
||||
if (this.description()) {
|
||||
this.list.push(new todo.Todo({description: this.description()}));
|
||||
this.description("");
|
||||
}
|
||||
}.bind(this);
|
||||
},
|
||||
|
||||
//here's the view
|
||||
view: function(ctrl: any) {
|
||||
return m("html", [
|
||||
m("body", [
|
||||
m("input", {onchange: m.withAttr("value", ctrl.description), value: ctrl.description()}),
|
||||
m("button", {onclick: ctrl.add}, "Add"),
|
||||
m("table", [
|
||||
ctrl.list.map(function(task: any) {
|
||||
return m("tr", [
|
||||
m("td", [
|
||||
m("input[type=checkbox]", {onclick: m.withAttr("checked", task.done), checked: task.done()})
|
||||
]),
|
||||
m("td", {style: {textDecoration: task.done() ? "line-through" : "none"}}, task.description()),
|
||||
])
|
||||
})
|
||||
])
|
||||
])
|
||||
]);
|
||||
},
|
||||
};
|
||||
|
||||
//initialize the application
|
||||
m.module(document, todo);
|
||||
Vendored
+69
@@ -0,0 +1,69 @@
|
||||
// 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(value?: any): (value?: any) => any;
|
||||
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(): void;
|
||||
route(rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
|
||||
route(rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void;
|
||||
route(path: string, params?: any, shouldReplaceHistory?: boolean): void;
|
||||
route(): string;
|
||||
route(element: Element, isInitialized: boolean): void;
|
||||
request(options: MithrilXHROptions): MithrilPromise;
|
||||
deferred(): MithrilDeferred;
|
||||
sync(promises: MithrilPromise[]): MithrilPromise;
|
||||
startComputation(): void;
|
||||
endComputation(): void;
|
||||
}
|
||||
|
||||
interface MithrilVirtualElement {
|
||||
tag: string;
|
||||
attrs: Object;
|
||||
children: any;
|
||||
}
|
||||
|
||||
interface MithrilModule {
|
||||
controller: Function;
|
||||
view: Function;
|
||||
}
|
||||
|
||||
interface MithrilDeferred {
|
||||
resolve(value?: any): void;
|
||||
reject(value?: any): void;
|
||||
promise: MithrilPromise;
|
||||
}
|
||||
|
||||
interface MithrilPromise {
|
||||
(value?: any): any;
|
||||
then(successCallback?: (value: any) => any, errorCallback?: (value: any) => any): MithrilPromise;
|
||||
}
|
||||
|
||||
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;
|
||||
Reference in New Issue
Block a user