Created
January 9, 2015 01:12
-
-
Save joefiorini/7639ff48f25e5067c97d to your computer and use it in GitHub Desktop.
Signal.toggle for Elm
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 Signal | |
import Html | |
import Html (div, text, button) | |
import Html.Events (onClick) | |
toggle s1 s2 s = | |
Signal.foldp | |
(\prev curr -> | |
if prev == s1 then s2 else s1) s1 s | |
toggler = Signal.channel "blah" | |
main = Signal.map scene | |
<| toggle "blah" "diddy" | |
<| Signal.subscribe toggler | |
scene s = | |
Html.toElement 500 500 | |
<| div | |
[] | |
[ text s | |
, button | |
[onClick <| Signal.send toggler s] | |
[text "Toggle That"] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment