From d5c287f16a080bdb18a92025cc47975b41834369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?De=CC=81nes=20Harmath?= Date: Tue, 29 Apr 2014 00:03:57 +0200 Subject: [PATCH] Add type definition for Elm --- CONTRIBUTORS.md | 1 + elm/elm-tests.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ elm/elm.d.ts | 28 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 elm/elm-tests.ts create mode 100644 elm/elm.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a3f729ca9..74c0363b0 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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)) diff --git a/elm/elm-tests.ts b/elm/elm-tests.ts new file mode 100644 index 000000000..dd0c60197 --- /dev/null +++ b/elm/elm-tests.ts @@ -0,0 +1,42 @@ +/// + +// Based on https://gist.github.com/evancz/8521339 + +interface Elm { + Shanghai: ElmModule; +} + +interface ShanghaiPorts { + coordinates: PortToElm>; + incomingShip: PortToElm; + outgoingShip: PortToElm; + totalCapacity: PortFromElm; +} + +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"); \ No newline at end of file diff --git a/elm/elm.d.ts b/elm/elm.d.ts new file mode 100644 index 000000000..1185394be --- /dev/null +++ b/elm/elm.d.ts @@ -0,0 +1,28 @@ +// Type definitions for Elm 0.12 +// Project: http://elm-lang.org +// Definitions by: Dénes Harmath +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare var Elm: Elm; + +interface Elm { + embed

(elmModule: ElmModule

, element: Node, initialValues?: Object): ElmComponent

; + fullscreen

(elmModule: ElmModule

, initialValues?: Object): ElmComponent

; + worker

(elmModule: ElmModule

, initialValues?: Object): ElmComponent

; +} + +interface ElmModule

{ +} + +interface ElmComponent

{ + ports: P; +} + +interface PortToElm { + send(value: V): void; +} + +interface PortFromElm { + subscribe(handler: (value: V) => void): void; + unsubscribe(handler: (value: V) => void): void; +} \ No newline at end of file