@@ -5,7 +5,7 @@ import Prelude
5
5
import Data.Array ((!!), drop , mapWithIndex , take )
6
6
import Data.Foldable (for_ )
7
7
import 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 )
9
9
import React.Basic.DOM as R
10
10
import React.Basic.DOM.Events (targetChecked )
11
11
import React.Basic.Events as Events
@@ -22,15 +22,11 @@ data Action
22
22
= Move { from :: Int , to :: Int }
23
23
| SetDone String Boolean
24
24
25
- component :: Component
25
+ component :: Component Unit
26
26
component = createComponent " TodoExample"
27
27
28
28
todoExample :: JSX
29
- todoExample = unit # make component
30
- { initialState = initialState
31
- , update = update
32
- , render = render
33
- }
29
+ todoExample = unit # make component { initialState, update, render }
34
30
where
35
31
initialState =
36
32
{ todos:
@@ -52,12 +48,12 @@ todoExample = unit # make component
52
48
else t
53
49
}
54
50
55
- render { state, send } =
51
+ render self =
56
52
dndContext $
57
53
fragment
58
54
[ R .h1_ [ R .text " Todos" ]
59
55
, R .p_ [ R .text " Drag to reorder the list:" ]
60
- , R .section_ (mapWithIndex renderTodo state.todos)
56
+ , R .section_ (mapWithIndex renderTodo self. state.todos)
61
57
]
62
58
63
59
where
@@ -75,7 +71,7 @@ todoExample = unit # make component
75
71
dnd.dropTarget
76
72
{ drop: \{ item: dragItem } -> do
77
73
for_ (_.index <$> dragItem) \dragItemIndex ->
78
- send $ Move { from: dragItemIndex, to: index }
74
+ send self $ Move { from: dragItemIndex, to: index }
79
75
pure Nothing
80
76
, hover: const (pure unit)
81
77
, canDrop: const (pure true )
@@ -100,7 +96,7 @@ todoExample = unit # make component
100
96
{ " type" : " checkbox"
101
97
, checked: todo.done
102
98
, onChange: Events .handler targetChecked \checked -> do
103
- send $ SetDone todo.id $ fromMaybe false checked
99
+ send self $ SetDone todo.id $ fromMaybe false checked
104
100
}
105
101
, R .text todo.text
106
102
]
0 commit comments