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
+1
View File
@@ -58,6 +58,7 @@ All definitions files include a header with the author and editors, so at some p
* [dust](http://linkedin.github.com/dustjs) (by [Marcelo Dezem](https://github.com/mdezem))
* [EaselJS](http://www.createjs.com/#!/EaselJS) (by [Pedro Ferreira](https://bitbucket.org/drk4))
* [EasyStar](http://easystarjs.com/) (by [Magnus Gustafsson](https://github.com/Borundin))
* [Elm](http://elm-lang.org) (by [Dénes Harmath](https://github.com/thSoft))
* [ember.js](http://emberjs.com/) (by [Boris Yankov](https://github.com/borisyankov))
* [emissary](https://github.com/atom/emissary) (by [vvakame](https://github.com/vvakame))
* [EpicEditor](http://epiceditor.com/) (by [Boris Yankov](https://github.com/borisyankov))
+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;
}