Skip to content

Instantly share code, notes, and snippets.

@bkonkle
Created January 12, 2017 15:33
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 bkonkle/a56fea49bde964f25df22815a2831e6b to your computer and use it in GitHub Desktop.
Save bkonkle/a56fea49bde964f25df22815a2831e6b to your computer and use it in GitHub Desktop.
PureScript NewTodo Component
module Todo.Components.NewTodo (newTodo) where
import Prelude
import Control.Monad.Eff (Eff)
import React (ReactClass)
import React.Recompose (withHandlers)
import Todo.State.Todos (add) as Todos
import Redux.Mini (connect)
-- Props
type HandleAdd props eff =
{ add :: String -> Eff eff Unit | props } ->
{ key :: String, target :: { value :: String } } ->
Eff eff Unit
addTodo :: forall props eff. HandleAdd props eff
addTodo props event = case event.key of
"Enter" -> props.add event.target.value
_ -> pure unit
-- Component
newTodo :: ReactClass {}
newTodo = connectState <<< eventHandlers
where mapStateToProps = \state -> { nextId: show $ state.todos.lastId + 1 }
dispatchActions = { add: Todos.add }
connectState = connect mapStateToProps dispatchActions
eventHandlers = withHandlers { addTodo }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment