@@ -5,7 +5,7 @@ import Prelude
55import Data.Array ((!!), drop , mapWithIndex , take )
66import Data.Foldable (for_ )
77import Data.Maybe (Maybe (Nothing), fromMaybe , maybe )
8- import React.Basic (Component , JSX , StateUpdate (..), createComponent , fragment , make )
8+ import React.Basic (Component , JSX , StateUpdate (..), createComponent , fragment , make , send )
99import React.Basic.DOM as R
1010import React.Basic.DOM.Events (targetChecked )
1111import React.Basic.Events as Events
@@ -22,15 +22,11 @@ data Action
2222 = Move { from :: Int , to :: Int }
2323 | SetDone String Boolean
2424
25- component :: Component
25+ component :: Component Unit
2626component = createComponent " TodoExample"
2727
2828todoExample :: JSX
29- todoExample = unit # make component
30- { initialState = initialState
31- , update = update
32- , render = render
33- }
29+ todoExample = unit # make component { initialState, update, render }
3430 where
3531 initialState =
3632 { todos:
@@ -52,12 +48,12 @@ todoExample = unit # make component
5248 else t
5349 }
5450
55- render { state, send } =
51+ render self =
5652 dndContext $
5753 fragment
5854 [ R .h1_ [ R .text " Todos" ]
5955 , R .p_ [ R .text " Drag to reorder the list:" ]
60- , R .section_ (mapWithIndex renderTodo state.todos)
56+ , R .section_ (mapWithIndex renderTodo self. state.todos)
6157 ]
6258
6359 where
@@ -75,7 +71,7 @@ todoExample = unit # make component
7571 dnd.dropTarget
7672 { drop: \{ item: dragItem } -> do
7773 for_ (_.index <$> dragItem) \dragItemIndex ->
78- send $ Move { from: dragItemIndex, to: index }
74+ send self $ Move { from: dragItemIndex, to: index }
7975 pure Nothing
8076 , hover: const (pure unit)
8177 , canDrop: const (pure true )
@@ -100,7 +96,7 @@ todoExample = unit # make component
10096 { " type" : " checkbox"
10197 , checked: todo.done
10298 , onChange: Events .handler targetChecked \checked -> do
103- send $ SetDone todo.id $ fromMaybe false checked
99+ send self $ SetDone todo.id $ fromMaybe false checked
104100 }
105101 , R .text todo.text
106102 ]
0 commit comments