Skip to content

Instantly share code, notes, and snippets.

@joelgrus
Created March 29, 2016 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelgrus/f65b4106cdf32f4bc1109f0e1a0e0497 to your computer and use it in GitHub Desktop.
Save joelgrus/f65b4106cdf32f4bc1109f0e1a0e0497 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Pux Example</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="app"></div>
<script src="https://fb.me/react-0.14.6.min.js"></script>
<script src="https://fb.me/react-dom-0.14.6.min.js"></script>
<script src="index.js"></script>
</body>
</html>
module Main where
import Prelude (Unit)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Debug.Trace (trace)
import Pux (start, renderToDOM, EffModel(), App)
import Prelude ((+), (-), const, show, (++), pure, ($), (>>=))
import Pux.Html (Html, (!), (#), bind, div, span, button, text)
import Pux.Html.Events (onClick)
data Action = Increment | EffIncrement | Receive Int
type State = Int
update :: Action -> State -> EffModel State Action (console :: CONSOLE)
update Increment count =
trace ("Increment: " ++ show count) \_ -> { state: count + 1, effects: [] }
update (Receive c) count =
trace ("Receive: " ++ show c) \_ -> { state: c, effects: [] }
update EffIncrement count =
trace "EffIncrement" \_ -> { state: count, effects: [pure $ Receive (count + 1)]}
view :: State -> Html Action
view count =
div # do
button ! onClick (const Increment) # text "Increment"
span # text (show count)
button ! onClick (const EffIncrement) # text "EffIncrement"
main = start { initialState: 0, update: update, view: view, inputs: [] } >>=
\app -> renderToDOM "#app" app.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment