1
1
-- | This module defines foreign types and functions which wrap React's functionality.
2
2
3
- module React
3
+ module React
4
4
( UI ()
5
5
, UIRef ()
6
-
6
+
7
7
, EventHandler ()
8
-
8
+
9
9
, Disallowed ()
10
10
, Read ()
11
11
, Write ()
12
12
, Only ()
13
13
, ReadWrite ()
14
14
, ReadOnly ()
15
-
15
+
16
16
, ReactState ()
17
17
, ReactProps ()
18
18
, ReactRefs ()
19
-
19
+
20
20
, Refs ()
21
-
21
+
22
22
, Render ()
23
-
23
+
24
24
, UISpec ()
25
-
25
+
26
26
, Event ()
27
27
, MouseEvent ()
28
28
, KeyboardEvent ()
29
-
29
+
30
30
, EventHandlerContext ()
31
-
31
+
32
32
, spec
33
-
33
+
34
34
, getProps
35
35
, getRefs
36
-
36
+
37
37
, readState
38
38
, writeState
39
39
, transformState
40
-
40
+
41
41
, mkUI
42
-
42
+
43
43
, handle
44
-
44
+
45
45
, renderToString
46
46
, renderToBody
47
47
, renderToElementById
@@ -103,13 +103,13 @@ foreign import data Refs :: *
103
103
foreign import data Event :: *
104
104
105
105
-- | The type of mouse events.
106
- type MouseEvent =
106
+ type MouseEvent =
107
107
{ pageX :: Number
108
- , pageY :: Number
108
+ , pageY :: Number
109
109
}
110
110
111
111
-- | The type of keyboard events.
112
- type KeyboardEvent =
112
+ type KeyboardEvent =
113
113
{ altKey :: Boolean
114
114
, ctrlKey :: Boolean
115
115
, charCode :: Int
@@ -124,7 +124,7 @@ type KeyboardEvent =
124
124
}
125
125
126
126
-- | A function which handles events.
127
- type EventHandlerContext eff props state result =
127
+ type EventHandlerContext eff props state result =
128
128
Eff ( props :: ReactProps props
129
129
, refs :: ReactRefs ReadOnly
130
130
, state :: ReactState ReadWrite state
@@ -143,6 +143,7 @@ type Render props state eff =
143
143
-- | A specification of a component.
144
144
type UISpec props state eff =
145
145
{ render :: Render props state eff
146
+ , displayName :: String
146
147
, getInitialState
147
148
:: UIRef ->
148
149
Eff ( props :: ReactProps props
@@ -205,6 +206,7 @@ type UISpec props state eff =
205
206
spec :: forall props state eff . state -> Render props state eff -> UISpec props state eff
206
207
spec st render =
207
208
{ render: render
209
+ , displayName: " "
208
210
, getInitialState: \_ -> pure st
209
211
, componentWillMount: \_ -> return unit
210
212
, componentDidMount: \_ -> return unit
@@ -216,30 +218,30 @@ spec st render =
216
218
}
217
219
218
220
-- | Read the component props.
219
- foreign import getProps :: forall props eff .
220
- UIRef ->
221
+ foreign import getProps :: forall props eff .
222
+ UIRef ->
221
223
Eff (props :: ReactProps props | eff ) props
222
224
223
225
-- | Read the component refs.
224
226
foreign import getRefs :: forall write eff .
225
- UIRef ->
227
+ UIRef ->
226
228
Eff (refs :: ReactRefs (Read write ) | eff ) Refs
227
229
228
230
-- | Write the component state.
229
- foreign import writeState :: forall state eff .
230
- UIRef ->
231
- state ->
231
+ foreign import writeState :: forall state eff .
232
+ UIRef ->
233
+ state ->
232
234
Eff (state :: ReactState ReadWrite state | eff ) state
233
235
234
236
-- | Read the component state.
235
- foreign import readState :: forall state write eff .
237
+ foreign import readState :: forall state write eff .
236
238
UIRef ->
237
239
Eff (state :: ReactState (Read write ) state | eff ) state
238
240
239
241
-- | Transform the component state by applying a function.
240
- transformState :: forall state statePerms eff .
242
+ transformState :: forall state statePerms eff .
241
243
UIRef ->
242
- (state -> state ) ->
244
+ (state -> state ) ->
243
245
Eff (state :: ReactState ReadWrite state | eff ) state
244
246
transformState ctx f = do
245
247
state <- readState ctx
@@ -248,7 +250,7 @@ transformState ctx f = do
248
250
-- | Create a component from a component spec.
249
251
foreign import mkUI :: forall props state eff .
250
252
UISpec props state eff ->
251
- props ->
253
+ props ->
252
254
UI
253
255
254
256
-- | Create an event handler.
0 commit comments