Get updates via , Github, or RSS | About

Episode 4: Ports Jun 9, 2016

Ports are Elms method of getting data into and out of your program via Javascript. As long as the data you want to move around can be simply converted to json, it will work over a port.

Read the full guide on ports for more examples.

Samples

Main module
port module Core exposing (..)

import --…

port dealOne : (Bool -> msg) -> Sub msg

port sendToJs : Int -> Cmd msg

main = Html.program
  { init = init
  , update = update
  , view = view
  , subscriptions = (\model -> dealOne DealOneCardMsg)
  }
index.html
<script>
core = Elm.Core.embed(/*…*/)
core.ports.dealOne.send(true);

core.ports.sendToJs.subscribe(function (val) {
  console.log(val);
});
</script>