@@ -4,14 +4,18 @@ module React where
4
4
import Control.Monad.Eff
5
5
6
6
foreign import data DOM :: !
7
- foreign import data ReadPropsEff :: * -> !
8
- foreign import data ReadRefsEff :: * -> !
9
- foreign import data ReadStateEff :: * -> !
10
- foreign import data WriteStateEff :: * -> !
11
7
foreign import data UI :: *
12
- foreign import data UIRef :: * -> * -> *
8
+ foreign import data UIRef :: # ! -> *
13
9
foreign import data EventHandler :: * -> *
14
10
11
+ foreign import data Disallowed :: !
12
+ foreign import data ReadAllowed :: !
13
+ foreign import data WriteAllowed :: !
14
+
15
+ foreign import data ReactState :: # ! -> * -> !
16
+ foreign import data ReactProps :: * -> !
17
+ foreign import data ReactRefs :: * -> !
18
+
15
19
foreign import noop0
16
20
" function noop0() { return null; }"
17
21
:: forall eff result. Eff ( eff ) result
@@ -24,57 +28,83 @@ module React where
24
28
" var noop2 = noop0"
25
29
:: forall a b eff result. a -> b -> Eff ( eff ) result
26
30
27
- type ReadProps props refs result = Eff (
28
- p :: ReadPropsEff props ,
29
- f :: ReadRefsEff refs ,
30
- dom :: DOM ,
31
- trace :: Trace
32
- ) result
33
-
34
- type ReadState props refs state result = Eff (
35
- p :: ReadPropsEff props ,
36
- f :: ReadRefsEff refs ,
37
- r :: ReadStateEff state ,
38
- dom :: DOM ,
39
- trace :: Trace
40
- ) result
41
-
42
- type ReadWriteState props refs state result = Eff (
43
- p :: ReadPropsEff props ,
44
- f :: ReadRefsEff refs ,
45
- r :: ReadStateEff state ,
46
- w :: WriteStateEff state ,
47
- dom :: DOM
48
- ) result
49
-
50
- type Render props refs state = Eff (
51
- p :: ReadPropsEff props ,
52
- f :: ReadRefsEff refs ,
53
- r :: ReadStateEff state ,
54
- trace :: Trace
31
+ type Render props refs state eff =
32
+ Eff (
33
+ props :: ReactProps props ,
34
+ refs :: Disallowed ,
35
+ state :: ReactState (read :: ReadAllowed) state
36
+ | eff
55
37
) UI
56
38
57
- type ShouldComponentUpdate props refs state =
58
- props -> state -> Eff (
59
- p :: ReadPropsEff props ,
60
- f :: ReadRefsEff refs ,
61
- r :: ReadStateEff state ,
62
- w :: WriteStateEff state ,
63
- trace :: Trace
64
- ) Boolean
65
-
66
- type UISpec props refs state =
67
- { getInitialState :: ReadProps props refs state
68
- , componentWillMount :: ReadState props refs state {}
69
- , componentDidMount :: ReadWriteState props refs state {}
70
- , componentWillReceiveProps :: props -> ReadWriteState props refs state {}
71
- , shouldComponentUpdate :: ShouldComponentUpdate refs props state
72
- , componentWillUpdate :: props -> state -> ReadWriteState props refs state {}
73
- , componentDidUpdate :: props -> state -> ReadState props refs state {}
74
- , componentWillUnmount :: ReadState props refs state {}
39
+ type UISpec props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8 =
40
+ { getInitialState
41
+ :: Eff (
42
+ props :: ReactProps props ,
43
+ state :: Disallowed ,
44
+ refs :: Disallowed
45
+ | eff1
46
+ ) state
47
+ , componentWillMount
48
+ :: Eff (
49
+ props :: ReactProps props ,
50
+ state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state ,
51
+ refs :: Disallowed
52
+ | eff2
53
+ ) Unit
54
+ , componentDidMount
55
+ :: Eff (
56
+ props :: ReactProps props ,
57
+ state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state ,
58
+ refs :: ReactRefs refs
59
+ | eff3
60
+ ) Unit
61
+ , componentWillReceiveProps
62
+ :: props
63
+ -> Eff (
64
+ props :: ReactProps props ,
65
+ state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state ,
66
+ refs :: ReactRefs refs
67
+ | eff4
68
+ ) Unit
69
+ , shouldComponentUpdate
70
+ :: props
71
+ -> state
72
+ -> Eff (
73
+ props :: ReactProps props ,
74
+ state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state ,
75
+ refs :: ReactRefs refs
76
+ | eff5
77
+ ) Boolean
78
+ , componentWillUpdate
79
+ :: props
80
+ -> state
81
+ -> Eff (
82
+ props :: ReactProps props ,
83
+ state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state ,
84
+ refs :: ReactRefs refs
85
+ | eff6
86
+ ) Unit
87
+ , componentDidUpdate
88
+ :: props
89
+ -> state
90
+ -> Eff (
91
+ props :: ReactProps props ,
92
+ state :: ReactState (read :: ReadAllowed) state ,
93
+ refs :: ReactRefs refs
94
+ | eff7
95
+ ) Unit
96
+ , componentWillUnmount
97
+ :: Eff (
98
+ props :: ReactProps props ,
99
+ state :: ReactState (read :: ReadAllowed) state ,
100
+ refs :: ReactRefs refs
101
+ | eff8
102
+ ) Unit
75
103
}
76
104
77
- spec :: forall props refs state. UISpec props refs state
105
+ spec
106
+ :: forall props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8.
107
+ UISpec props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8
78
108
spec =
79
109
{ getInitialState : noop0
80
110
, componentWillMount : noop0
@@ -86,37 +116,46 @@ module React where
86
116
, componentWillUnmount : noop0
87
117
}
88
118
where
89
- updateAlways :: forall props refs state. ShouldComponentUpdate props refs state
119
+ updateAlways
120
+ :: forall props refs state. props
121
+ -> state
122
+ -> forall eff. Eff (
123
+ props :: ReactProps props ,
124
+ state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state ,
125
+ refs :: ReactRefs refs
126
+ | eff
127
+ ) Boolean
90
128
updateAlways props state = return true
91
129
92
130
foreign import getProps
93
131
" function getProps() { \
94
132
\ return __current.props; \
95
133
\ }"
96
134
:: forall props eff.
97
- Eff (p :: ReadPropsEff props | eff ) props
135
+ Eff (props :: ReactProps props | eff ) props
98
136
99
137
foreign import getRefs
100
138
" function getRefs() { \
101
139
\ return __current.refs; \
102
140
\ }"
103
141
:: forall refs eff.
104
- Eff (f :: ReadRefsEff refs | eff ) refs
142
+ Eff (refs :: ReactRefs refs | eff ) refs
105
143
106
144
foreign import writeState
107
145
" function writeState(state) { \
108
146
\ __current.replaceState({state: state}); \
109
147
\ return function() { return state; } \
110
148
\ }"
111
- :: forall state eff.
149
+ :: forall state state Perms eff.
112
150
state
113
- -> Eff (r :: ReadStateEff state , w :: WriteStateEff state | eff ) state
151
+ -> Eff (state :: ReactState (read :: ReadAllowed, write :: WriteAllowed | statePerms) state | eff ) state
114
152
115
153
foreign import readState
116
154
" function readState() { \
117
155
\ return __current.state.state; \
118
156
\ }"
119
- :: forall state eff. Eff (r :: ReadStateEff state | eff ) state
157
+ :: forall state statePerms eff.
158
+ Eff (state :: ReactState (read :: ReadAllowed | statePerms) state | eff ) state
120
159
121
160
transformState f = do
122
161
state <- readState
@@ -126,8 +165,8 @@ module React where
126
165
" function getSelf() { \
127
166
\ return __current; \
128
167
\ }"
129
- :: forall eff props state .
130
- Eff (p :: ReadPropsEff props , r :: ReadStateEff state | eff ) (UIRef props state )
168
+ :: forall eff.
169
+ Eff (eff ) (UIRef eff )
131
170
132
171
foreign import runUI
133
172
" function runUI(ref) { \
@@ -144,10 +183,7 @@ module React where
144
183
\ } \
145
184
\ } \
146
185
\ }"
147
- :: forall eff props state result.
148
- UIRef props state
149
- -> Eff (p :: ReadPropsEff props , r :: ReadStateEff state , w :: WriteStateEff state | eff ) result
150
- -> Eff (eff ) result
186
+ :: forall refEff eff result. UIRef refEff -> Eff (refEff ) result -> Eff (eff ) result
151
187
152
188
foreign import mkUI
153
189
" var __current; \
@@ -188,9 +224,9 @@ module React where
188
224
\ return React.createClass(specs); \
189
225
\ } \
190
226
\ }"
191
- :: forall props refs state.
192
- UISpec props refs state
193
- -> Render props refs state
227
+ :: forall props refs state eff eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8 .
228
+ UISpec props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8
229
+ -> Render props refs state eff
194
230
-> (props -> UI )
195
231
196
232
type DOMEvent = forall attrs. { | attrs}
@@ -222,10 +258,10 @@ module React where
222
258
, which :: Number
223
259
}
224
260
225
- type EventHandlerContext eff props state result = Eff (
226
- p :: ReadPropsEff props ,
227
- r :: ReadStateEff state ,
228
- w :: WriteStateEff state
261
+ type EventHandlerContext eff props refs state result = forall state Perms. Eff (
262
+ props :: ReactProps props ,
263
+ refs :: ReactRefs refs ,
264
+ state :: ReactState (read :: ReadAllowed, write :: WriteAllowed | statePerms) state
229
265
| eff
230
266
) result
231
267
@@ -242,8 +278,8 @@ module React where
242
278
\ return res; \
243
279
\ } \
244
280
\ }"
245
- :: forall eff ev props state result.
246
- (ev -> EventHandlerContext eff props state result )
281
+ :: forall eff ev props refs state result.
282
+ (ev -> EventHandlerContext eff props refs state result )
247
283
-> EventHandler ev
248
284
249
285
foreign import renderToString
0 commit comments