The closest you can get is probably something like this: Create the port similar to your examples but with the first parameters as (() -> msg)
:
port updateTime : (() -> msg) -> Sub msg
Assuming you have an UpdateTime
Msg
that accepts no parameters,
type Msg
= ...
| UpdateTime
You can then tie into the updateTime
subscription like this:
subscriptions : Model -> Sub Msg
subscriptions model =
updateTime (always UpdateTime)
Now, on the javascript side, you'll have to pass null
as the only parameter.
app.ports.updateTime.send(null);
Update for Elm 0.19
In Elm 0.19 you had to be explicit about which Elm modules exposed ports, so you may have to update your module definition to include port module
.
port module Main exposing (main)