Created
January 12, 2017 15:33
-
-
Save bkonkle/a56fea49bde964f25df22815a2831e6b to your computer and use it in GitHub Desktop.
PureScript NewTodo Component
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 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