mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #2123 from thSoft/master
Add type definition for Elm
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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");
|
||||
Vendored
+28
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user