Skip to content

Instantly share code, notes, and snippets.

@ThomasCrevoisier
Last active June 25, 2017 16:32
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 ThomasCrevoisier/45adba2a25089a5787c194c808238dc8 to your computer and use it in GitHub Desktop.
Save ThomasCrevoisier/45adba2a25089a5787c194c808238dc8 to your computer and use it in GitHub Desktop.
module Main where
import Prelude hiding (div)
import Control.Monad.Eff (Eff)
import Pux (CoreEffects, EffModel, start)
import Pux.DOM.Events (onClick)
import Pux.DOM.HTML (HTML)
import Pux.Renderer.React (renderToDOM, renderToReact)
import Text.Smolder.HTML (button, div, span)
import Text.Smolder.Markup (text, (#!))
import React (ReactClass)
data Event
= Increment
| Decrement
type State = Int
foldp :: forall fx. Event -> State -> EffModel State Event fx
foldp Increment n = { state: n + 1, effects: [] }
foldp Decrement n = { state: n - 1, effects: [] }
view :: State -> HTML Event
view count =
div do
button #! onClick (const Increment) $ text "Increment"
span $ text (show count)
button #! onClick (const Decrement) $ text "Decrement"
toReact :: forall props fx. Eff (CoreEffects fx) (ReactClass props)
toReact state = do
app <- start
{ initialState: state
, view
, foldp
, inputs: []
}
pure $ renderToReact app.markup app.input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment