mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-12 12:10:44 +08:00
Add type definition for Elm
This commit is contained in:
@@ -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