Skip to content

Instantly share code, notes, and snippets.

@renegr
Created April 16, 2014 14:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renegr/10885781 to your computer and use it in GitHub Desktop.
Save renegr/10885781 to your computer and use it in GitHub Desktop.
The pleasantness of ELM
{-
As seen on: http://danielsz.github.io/2014/02/28/The-pleasantness-of-Om/
Additional feature: <SPACE> and Time advance
Missing feature: Randomizer for List
-}
import Keyboard
-- Model
type Testimonial = { shopName:String,
shopOwner:String,
avatar:String,
quote:String }
type AppState = { testimonials:[Testimonial] }
defaultState : AppState
defaultState = { testimonials=[{ shopName="One",
avatar="http://www.martin-missfeldt.de/kunst-blog/images/avatar-facebook-twitter-google-youtube.png",
shopOwner="One",
quote="That is really smthg"},
{ shopName="Two",
avatar="http://www.ninaneco.com/content/pictures/avatar_greenfiire_klein.jpg",
shopOwner="Two",
quote="That is really smthg with more text"},
{ shopName="Three",
avatar="http://forum.fernsehkritik.tv/customavatars/avatar6970_5.gif",
shopOwner="Three",
quote="That is really smthg"}] }
-- Update the state
nextTestims : [Testimonial] -> [Testimonial]
nextTestims testimonials =
let t = (tail testimonials)
in if isEmpty t then defaultState.testimonials else t
update : String -> AppState -> AppState
update action appState =
case action of
"next" -> { appState | testimonials <- nextTestims appState.testimonials}
_ -> appState
-- Render the State
display : AppState -> Element
display appState =
let testimonial = head appState.testimonials
in
collage 300 100 [ image 40 40 testimonial.avatar |> toForm |> move (130, 20),
asText testimonial.quote |> toForm |> move (30,30) ,
asText testimonial.shopName |> toForm |> move (90, 17)]
-- Main
input = merge (foldp (\f s -> "next") "idle" (every (second *4)))
(foldp (\spaceIsDown s -> if spaceIsDown then "next" else "idle") "idle" Keyboard.space)
actualState = foldp update defaultState input
main = lift display actualState
@danielsz
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment