v0.2.2-rc.1

This commit is contained in:
Leo Horie 2015-12-20 09:14:28 -05:00
parent 484a9d6c70
commit 270b20a2b0
110 changed files with 17357 additions and 3070 deletions

342
mithril.d.ts vendored
View file

@ -20,14 +20,30 @@ declare module _mithril {
* @see m.mount
* @see m.component
*/
(
<T extends MithrilController>(
selector: string,
attributes: MithrilAttributes,
...children: Array<string |
MithrilVirtualElement |
MithrilComponent<MithrilController>>
): MithrilVirtualElement;
MithrilVirtualElement<T> |
MithrilComponent<T>>
): MithrilVirtualElement<T>;
/**
* Initializes a component for use with m.render, m.mount, etc.
*
* @param component A component.
* @param args Arguments to optionally pass to the component.
* @return A component.
*
* @see m.render
* @see m.mount
* @see m
*/
<T extends MithrilController>(
component: MithrilComponent<T>,
...args: any[]
): MithrilComponent<T>;
/**
* Creates a virtual element for use with m.render, m.mount, etc.
*
@ -40,144 +56,41 @@ declare module _mithril {
* @see m.mount
* @see m.component
*/
(
<T extends MithrilController>(
selector: string,
...children: Array<string |
MithrilVirtualElement |
MithrilComponent<MithrilController>>
): MithrilVirtualElement;
MithrilVirtualElement<T> |
MithrilComponent<T>>
): MithrilVirtualElement<T>;
/**
* Initializes a component for use with m.render, m.mount, etc.
* Shorthand for m.component.
*
* @param component A mithril component.
* @return A mithril component.
* @param selector A component.
* @param args Arguments to optionally pass to the component.
* @return A component.
*
* @see m.render
* @see m.mount
* @see m.component
*/
<TController extends MithrilController>(
component: MithrilComponent<TController>
): MithrilComponent<TController>;
/**
* Initializes a component for use with m.render, m.mount, etc.
* Shorthand for m.component.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m.component
*/
<TController extends MithrilController, T1>(
component: ParameterizedMithrilComponent<TController, T1, void, void, void>,
arg1: T1
): MithrilComponent<TController>;
/**
* Initializes a component for use with m.render, m.mount, etc.
* Shorthand for m.component.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m.component
*/
<TController extends MithrilController, T1, T2>(
component: ParameterizedMithrilComponent<TController, T1, T2, void, void>,
arg1: T1,
arg2: T2
): MithrilComponent<TController>;
/**
* Initializes a component for use with m.render, m.mount, etc.
* Shorthand for m.component.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @param arg3 Third argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m.component
*/
<TController extends MithrilController, T1, T2, T3>(
component: ParameterizedMithrilComponent<TController, T1, T2, T3, void>,
arg1: T1,
arg2: T2,
arg3: T3
): MithrilComponent<TController>;
/**
* Initializes a parameterized component for use with m.render, m.mount, etc.
* Shorthand for m.component.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @param arg3 Third argument to bind to the component.
* @param arg4 Fourth argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m.component
*/
<TController extends MithrilController, T1, T2, T3, T4>(
component: ParameterizedMithrilComponent<TController, T1, T2, T3, T4>,
arg1: T1,
arg2: T2,
arg3: T3,
arg4: T4
): MithrilComponent<TController>;
/**
* Initializes a parameterized component for use with m.render, m.mount, etc.
* Shorthand for m.component.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @param arg3 Third argument to bind to the component.
* @param arg4 Fourth argument to bind to the component.
* @param args Additional optional arguments which are not type checked.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m.component
*/
<TController extends MithrilController, T1, T2, T3, T4>(
component: ParameterizedMithrilComponent<TController, T1, T2, T3, T4>,
arg1: T1,
arg2: T2,
arg3: T3,
arg4: T4,
...args:any[]
): MithrilComponent<TController>;
<T extends MithrilController>(
component: MithrilComponent<T>,
...args: any[]
): MithrilComponent<T>;
/**
* Creates a getter-setter function that wraps a Mithril promise. Useful
* for uniform data access, m.withAttr, etc.
*
* @param promise A thenable to initialize the property with. It may
* @param promise A thennable to initialize the property with. It may
* optionally be a Mithril promise.
* @return A getter-setter function wrapping the promise.
*
* @see m.withAttr
*/
prop<T>(promise: Thenable<T>) : MithrilPromiseProperty<T>;
prop<T>(promise: Thennable<T>) : MithrilPromiseProperty<T>;
/**
* Creates a getter-setter function that wraps a simple value. Useful
@ -210,7 +123,8 @@ declare module _mithril {
*/
withAttr(
property: string,
callback: (value: any) => void
callback: (value: any) => void,
callbackThis: any
): (e: Event) => any;
/**
@ -236,116 +150,18 @@ declare module _mithril {
/**
* Initializes a component for use with m.render, m.mount, etc.
*
* @param component A mithril component.
* @return A mithril component.
* @param selector A component.
* @param args Arguments to optionally pass to the component.
* @return A component.
*
* @see m.render
* @see m.mount
* @see m
*/
component<TController extends MithrilController>(
component: MithrilComponent<TController>
): MithrilComponent<TController>;
/**
* Initializes a parameterized component for use with m.render, m.mount, etc.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m
*/
component<TController extends MithrilController, T1>(
component: ParameterizedMithrilComponent<TController, T1, void, void, void>,
arg1: T1
): MithrilComponent<TController>;
/**
* Initializes a parameterized component for use with m.render, m.mount, etc.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m
*/
component<TController extends MithrilController, T1, T2>(
component: ParameterizedMithrilComponent<TController, T1, T2, void, void>,
arg1: T1,
arg2: T2
): MithrilComponent<TController>;
/**
* Initializes a parameterized component for use with m.render, m.mount, etc.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @param arg3 Third argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m
*/
component<TController extends MithrilController, T1, T2, T3>(
component: ParameterizedMithrilComponent<TController, T1, T2, T3, void>,
arg1: T1,
arg2: T2,
arg3: T3
): MithrilComponent<TController>;
/**
* Initializes a parameterized component for use with m.render, m.mount, etc.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @param arg3 Third argument to bind to the component.
* @param arg4 Fourth argument to bind to the component.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m
*/
component<TController extends MithrilController, T1, T2, T3, T4>(
component: ParameterizedMithrilComponent<TController, T1, T2, T3, T4>,
arg1: T1,
arg2: T2,
arg3: T3,
arg4: T4
): MithrilComponent<TController>;
/**
* Initializes a parameterized component for use with m.render, m.mount, etc.
*
* @param component A parameterized component.
* @param arg1 First argument to bind to the component.
* @param arg2 Second argument to bind to the component.
* @param arg3 Third argument to bind to the component.
* @param arg4 Fourth argument to bind to the component.
* @param args Additional optional arguments which are not type checked.
* @return A component bound with the supplied arguments.
*
* @see m.render
* @see m.mount
* @see m
*/
component<TController extends MithrilController, T1, T2, T3, T4>(
component: ParameterizedMithrilComponent<TController, T1, T2, T3, T4>,
arg1: T1,
arg2: T2,
arg3: T3,
arg4: T4,
component<T extends MithrilController>(
component: MithrilComponent<T>,
...args: any[]
): MithrilComponent<TController>;
): MithrilComponent<T>;
/**
* Trust this string of HTML.
@ -364,9 +180,9 @@ declare module _mithril {
* @param forceRecreation If true, overwrite the entire tree without
* diffing against it.
*/
render(
render<T extends MithrilController>(
rootElement: Element,
children: MithrilVirtualElement|MithrilVirtualElement[],
children: MithrilVirtualElement<T>|MithrilVirtualElement<T>[],
forceRecreation?: boolean
): void;
@ -431,10 +247,10 @@ declare module _mithril {
* @param defaultRoute The route to start with.
* @param routes A key-value mapping of pathname to controller.
*/
(
<T extends MithrilController>(
rootElement: Element,
defaultRoute: string,
routes: MithrilRoutes
routes: MithrilRoutes<T>
): void;
/**
@ -447,11 +263,11 @@ declare module _mithril {
* m("a[href='/dashboard/alicesmith']", {config: m.route});
* ```
*/
(
<T extends MithrilController>(
element: Element,
isInitialized: boolean,
context?: MithrilContext,
vdom?: MithrilVirtualElement
vdom?: MithrilVirtualElement<T>
): void;
/**
@ -554,7 +370,7 @@ declare module _mithril {
}
/**
* Takes a list of promises or thenables and returns a Mithril promise
* Takes a list of promises or thennables and returns a Mithril promise
* that resolves once all in the list are resolved, or rejects if any of
* them reject.
*
@ -562,7 +378,7 @@ declare module _mithril {
* @return A promise that resolves to all the promises if all resolve, or
* rejects with the error contained in the first rejection.
*/
sync<T>(promises: Thenable<T>[]): MithrilPromise<T[]>;
sync<T>(promises: Thennable<T>[]): MithrilPromise<T[]>;
/**
* Use this and endComputation if your views aren't redrawing after
@ -615,7 +431,7 @@ declare module _mithril {
*
* @see m
*/
interface MithrilVirtualElement {
interface MithrilVirtualElement<T extends MithrilController> {
/**
* A key to optionally associate with this element.
*/
@ -634,7 +450,7 @@ declare module _mithril {
/**
* The children of this element.
*/
children?: Array<string|MithrilVirtualElement|MithrilComponent<MithrilController>>;
children?: Array<string|MithrilVirtualElement<T>|MithrilComponent<T>>;
}
/**
@ -686,11 +502,11 @@ declare module _mithril {
* @param context The associated context for this element.
* @param vdom The associated virtual element.
*/
(
<T extends MithrilController>(
element: Element,
isInitialized: boolean,
context: MithrilContext,
vdom: MithrilVirtualElement
vdom: MithrilVirtualElement<T>
): void;
}
@ -758,7 +574,7 @@ declare module _mithril {
/**
* Creates a view out of virtual elements.
*/
(ctrl: T): MithrilVirtualElement;
(ctrl: T): MithrilVirtualElement<T>;
}
/**
@ -781,31 +597,7 @@ declare module _mithril {
*
* @see m.component
*/
view(ctrl: T): MithrilVirtualElement;
}
/**
* This represents a parameterized MithrilComponent with up to six parameters,
* intended to be instantiated via m.component().
*
* @see m
* @see m.component
*/
interface ParameterizedMithrilComponent<TController extends MithrilController, T1, T2, T3, T4> {
/**
* The component's controller.
*
* @see m.component
*/
controller: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, ...args: any[]) => TController;
/**
* creates a view out of virtual elements.
*
* @see m.component
*/
view(ctrl: TController, arg1: T1, arg2: T2, arg3: T3, arg4: T4, ...args:any[]): MithrilVirtualElement;
view(ctrl: T): MithrilVirtualElement<T>;
}
/**
@ -876,12 +668,12 @@ declare module _mithril {
/**
* This represents a key-value mapping linking routes to components.
*/
interface MithrilRoutes {
interface MithrilRoutes<T extends MithrilController> {
/**
* The key represents the route. The value represents the corresponding
* component.
*/
[key: string]: MithrilComponent<MithrilController>;
[key: string]: MithrilComponent<T>;
}
/**
@ -911,32 +703,32 @@ declare module _mithril {
}
/**
* This represents a thenable success callback.
* This represents a thennable success callback.
*/
interface MithrilSuccessCallback<T, U> {
(value: T): U | Thenable<U>;
(value: T): U | Thennable<U>;
}
/**
* This represents a thenable error callback.
* This represents a thennable error callback.
*/
interface MithrilErrorCallback<T> {
(value: Error): T | Thenable<T>;
(value: Error): T | Thennable<T>;
}
/**
* This represents a thenable.
* This represents a thennable.
*/
interface Thenable<T> {
then<U>(success: (value: T) => U): Thenable<U>;
then<U,V>(success: (value: T) => U, error: (value: Error) => V): Thenable<U>|Thenable<V>;
catch?: <U>(error: (value: Error) => U) => Thenable<U>;
interface Thennable<T> {
then<U>(success: (value: T) => U): Thennable<U>;
then<U,V>(success: (value: T) => U, error: (value: Error) => V): Thennable<U>|Thennable<V>;
catch?: <U>(error: (value: Error) => U) => Thennable<U>;
}
/**
* This represents a Mithril promise object.
*/
interface MithrilPromise<T> extends Thenable<T>, MithrilProperty<MithrilPromise<T>> {
interface MithrilPromise<T> extends Thennable<T>, MithrilProperty<MithrilPromise<T>> {
/**
* Chain this promise with a simple success callback, propogating
* rejections.