Search code examples
elmelm-signalelm-port

Elm output port is not working with a signal derived from StartApp


We're learning Elm basics and building a simple application with some audio output with the following setup:

  • We are using Elm's StartApp.
  • We have ports/audio.js with some POC audio logic (and console.log).
  • ATM we are using elm-live to run the application.

With a signal derived from Time.every the port works (code in ports/audio.js is run). In addition, we get "ping" logs with Debug.log.

port audio : Signal Int
port audio =
  Signal.map (always 400) (Time.every Time.second)
  |> Signal.map (Debug.log "ping")

However, when we use a signal derived from StartApp's App.model, we get a signal (since "ping" logs with Debug.log are logged) but port to JS doesn't work (code in ports/audio.js is not run)?

port audio : Signal Int
port audio =
  Signal.map (always 400) signalDerivedFromStartApp
  |> Signal.map (Debug.log "ping")

This might be some basic thing related to Elm signals/ports/StartApp?


Solution

  • Our expert friend found the issue: Our setup was broken since we used Elm.main at two places

    • ports/audio.js had Elm.worker(Elm.Main, {});
    • index.html had script with Elm.fullscreen(Elm.Main)

    -> after removing Elm.worker things from audio.js and plugging audio.js to port implementation at index.html things were fixed.

    (This is probably not a perfect/final solution for the case but fixed the issue for our current setup)