Add type definition for Elm

This commit is contained in:
Dénes Harmath
2014-04-29 00:05:38 +02:00
parent d8b512ed51
commit d5c287f16a
3 changed files with 71 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
/// <reference path="elm.d.ts" />
// Based on https://gist.github.com/evancz/8521339
interface Elm {
Shanghai: ElmModule<ShanghaiPorts>;
}
interface ShanghaiPorts {
coordinates: PortToElm<Array<number>>;
incomingShip: PortToElm<Ship>;
outgoingShip: PortToElm<string>;
totalCapacity: PortFromElm<number>;
}
interface Ship {
name: string;
capacity: number;
}
// initialize the Shanghai component which keeps track of
// shipping data in and out of the Port of Shanghai.
var shanghai = Elm.worker(Elm.Shanghai, {
coordinates: [0, 0],
incomingShip: { name: "", capacity: 0 },
outgoingShip: ""
});
function logger(x: any) { console.log(x) }
shanghai.ports.totalCapacity.subscribe(logger);
// send some ships to the port of Shanghai
shanghai.ports.incomingShip.send({
name: "Mary Mærsk",
capacity: 18270
});
shanghai.ports.incomingShip.send({
name: "Emma Mærsk",
capacity: 15500
});
// have those ships leave the port of Shanghai
shanghai.ports.outgoingShip.send("Mary Mærsk");
shanghai.ports.outgoingShip.send("Emma Mærsk");
+28
View File
@@ -0,0 +1,28 @@
// Type definitions for Elm 0.12
// Project: http://elm-lang.org
// Definitions by: Dénes Harmath <https://github.com/thSoft>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare var Elm: Elm;
interface Elm {
embed<P>(elmModule: ElmModule<P>, element: Node, initialValues?: Object): ElmComponent<P>;
fullscreen<P>(elmModule: ElmModule<P>, initialValues?: Object): ElmComponent<P>;
worker<P>(elmModule: ElmModule<P>, initialValues?: Object): ElmComponent<P>;
}
interface ElmModule<P> {
}
interface ElmComponent<P> {
ports: P;
}
interface PortToElm<V> {
send(value: V): void;
}
interface PortFromElm<V> {
subscribe(handler: (value: V) => void): void;
unsubscribe(handler: (value: V) => void): void;
}