Created
January 7, 2016 01:54
-
-
Save jergason/2e3ebfd8ed4d1b10f63d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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