Skip to content

Instantly share code, notes, and snippets.

@jergason
Created January 7, 2016 01:54
Show Gist options
  • Save jergason/2e3ebfd8ed4d1b10f63d to your computer and use it in GitHub Desktop.
Save jergason/2e3ebfd8ed4d1b10f63d to your computer and use it in GitHub Desktop.
import Elm from './src/Main.elm'
const container = document.querySelector('.container')
const elmApp = Elm.embed(Elm.Main, container)
function playSound(soundName) {
// this is never called
console.log('soundName is', soundName)
}
elmApp.ports.playSound.subscribe(playSound)
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
Actions.PlaySound soundName ->
( model, sendToJs soundName )
Actions.NoOp ->
( model, Effects.none )
Actions.SetAngel showing ->
let
updatedModel = {model | showingAngels = showing }
effect = (
if showing == True then
clearAngel
else
Effects.none
)
in
( updatedModel, effect )
sendToJs : String -> Effects Action
sendToJs soundName =
(Signal.send sounds.address soundName)
|> Task.toResult
|> Task.map
(
\res ->
case res of
Ok val ->
Actions.SetAngel True
Err val ->
Actions.NoOp
)
|> Effects.task
sounds : Mailbox String
sounds = mailbox ""
port playSound : Signal String
port playSound = sounds.signal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment