Created
March 29, 2016 23:43
-
-
Save joelgrus/f65b4106cdf32f4bc1109f0e1a0e0497 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
<!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> |
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
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