@@ -10,7 +10,7 @@ module React where
10
10
foreign import data EventHandler :: * -> *
11
11
12
12
foreign import noop0
13
- " function noop0() {}"
13
+ " function noop0() { return null; }"
14
14
:: forall eff result. Eff ( eff ) result
15
15
16
16
foreign import noop1
@@ -21,26 +21,11 @@ module React where
21
21
" var noop2 = noop0"
22
22
:: forall a b eff result. a -> b -> Eff ( eff ) result
23
23
24
- type Render props = Eff (p :: ReadPropsEff props ) UI
25
-
26
24
type ReadProps eff props result = Eff (
27
25
p :: ReadPropsEff props
28
26
| eff
29
27
) result
30
28
31
- type ShouldComponentUpdate props =
32
- props -> Eff ( p :: ReadPropsEff props ) Boolean
33
-
34
- type UISpec eff props =
35
- { componentWillMount :: ReadProps eff props {}
36
- , componentDidMount :: ReadProps eff props {}
37
- , componentWillReceiveProps :: props -> ReadProps eff props {}
38
- , shouldComponentUpdate :: ShouldComponentUpdate props
39
- , componentWillUpdate :: props -> ReadProps eff props {}
40
- , componentDidUpdate :: props -> ReadProps eff props {}
41
- , componentWillUnmount :: ReadProps eff props {}
42
- }
43
-
44
29
type ReadState eff props state result = Eff (
45
30
p :: ReadPropsEff props ,
46
31
r :: ReadStateEff state
@@ -54,43 +39,33 @@ module React where
54
39
| eff
55
40
) result
56
41
57
- type StatefulRender props state = Eff (
42
+ type Render props state = Eff (
58
43
p :: ReadPropsEff props ,
59
44
r :: ReadStateEff state
60
45
) UI
61
46
62
- type StatefulShouldComponentUpdate props state =
47
+ type ShouldComponentUpdate props state =
63
48
props -> state -> Eff (
64
49
p :: ReadPropsEff props ,
65
50
r :: ReadStateEff state ,
66
51
w :: WriteStateEff state
67
52
) Boolean
68
53
69
- type StatefulUISpec eff props state =
70
- { componentWillMount :: ReadState eff props state {}
54
+ type UISpec eff props state =
55
+ { getInitialState :: ReadProps eff props state
56
+ , componentWillMount :: ReadState eff props state {}
71
57
, componentDidMount :: ReadWriteState eff props state {}
72
58
, componentWillReceiveProps :: props -> ReadWriteState eff props state {}
73
- , shouldComponentUpdate :: StatefulShouldComponentUpdate props state
59
+ , shouldComponentUpdate :: ShouldComponentUpdate props state
74
60
, componentWillUpdate :: props -> state -> ReadWriteState eff props state {}
75
61
, componentDidUpdate :: props -> state -> ReadState eff props state {}
76
62
, componentWillUnmount :: ReadState eff props state {}
77
63
}
78
64
79
- defaultSpec =
80
- { componentWillMount : noop0
81
- , componentDidMount : noop0
82
- , componentWillReceiveProps : noop1
83
- , shouldComponentUpdate : updateAlways
84
- , componentWillUpdate : noop2
85
- , componentDidUpdate : noop2
86
- , componentWillUnmount : noop0
87
- }
88
- where
89
- updateAlways :: forall props. ShouldComponentUpdate props
90
- updateAlways props = return true
91
-
92
- defaultStatefulSpec =
93
- { componentWillMount : noop0
65
+ spec :: forall eff props state. UISpec eff props state
66
+ spec =
67
+ { getInitialState : noop0
68
+ , componentWillMount : noop0
94
69
, componentDidMount : noop0
95
70
, componentWillReceiveProps : noop1
96
71
, shouldComponentUpdate : updateAlways
@@ -99,33 +74,38 @@ module React where
99
74
, componentWillUnmount : noop0
100
75
}
101
76
where
102
- updateAlways :: forall props state. StatefulShouldComponentUpdate props state
77
+ updateAlways :: forall props state. ShouldComponentUpdate props state
103
78
updateAlways props state = return true
104
79
105
- foreign import mkUI
106
- " function mkUI(render) { \
107
- \ return React.createClass({ \
108
- \ render: function() { \
109
- \ __current = this; \
110
- \ try { \
111
- \ var ui = render.call(this); \
112
- \ } finally { \
113
- \ __current = null; \
114
- \ } \
115
- \ return ui; \
116
- \ } \
117
- \ }); \
80
+ foreign import getProps
81
+ " function getProps() { \
82
+ \ return __current.props; \
118
83
\ }"
119
- :: forall props.
120
- Render props
121
- -> (props -> UI )
84
+ :: forall props eff.
85
+ Eff (p :: ReadPropsEff props | eff ) props
122
86
123
- foreign import mkUIFromSpec
124
- " function mkUIFromSpec(render) { \
125
- \ return function(ss) { \
87
+ foreign import writeState
88
+ " function writeState(state) { \
89
+ \ __current.replaceState({state: state}); \
90
+ \ return function() { return state; } \
91
+ \ }"
92
+ :: forall state eff.
93
+ state
94
+ -> Eff (r :: ReadStateEff state , w :: WriteStateEff state | eff ) state
95
+
96
+ foreign import readState
97
+ " function readState() { \
98
+ \ return __current.state.state; \
99
+ \ }"
100
+ :: forall state eff. Eff (r :: ReadStateEff state | eff ) state
101
+
102
+ foreign import mkUI
103
+ " var __current; \
104
+ \ function mkUI(ss) { \
105
+ \ return function(render) { \
126
106
\ var specs = {}; \
127
107
\ for (var s in ss) { \
128
- \ if (ps .hasOwnProperty(s)) { \
108
+ \ if (ss .hasOwnProperty(s)) { \
129
109
\ specs[s] = (function(impl) { \
130
110
\ return function() { \
131
111
\ __current = this; \
@@ -138,114 +118,31 @@ module React where
138
118
\ })(ss[s]); \
139
119
\ } \
140
120
\ } \
121
+ \ specs.getInitialState= function() { \
122
+ \ __current = this; \
123
+ \ try { \
124
+ \ return {state: ss.getInitialState()}; \
125
+ \ } finally { \
126
+ \ __current = null; \
127
+ \ } \
128
+ \ }; \
141
129
\ specs.render = function() { \
142
130
\ __current = this; \
143
131
\ try { \
144
- \ var ui = render(); \
132
+ \ var ui = render.call(this); \
145
133
\ } finally { \
146
134
\ __current = null; \
147
135
\ } \
148
136
\ return ui; \
149
137
\ }; \
150
138
\ return React.createClass(specs); \
151
- \ }; \
152
- \ }"
153
- :: forall eff props.
154
- Render props
155
- -> UISpec eff props
156
- -> (props -> UI )
157
-
158
- foreign import getProps
159
- " function getProps() { \
160
- \ return __current.props; \
161
- \ }"
162
- :: forall props eff.
163
- Eff (p :: ReadPropsEff props | eff ) props
164
-
165
- foreign import mkStatefulUI
166
- " var __current; \
167
- \ function mkStatefulUI(state) { \
168
- \ return function(render) { \
169
- \ return React.createClass({ \
170
- \ \
171
- \ getInitialState: function() { \
172
- \ return {state: state}; \
173
- \ }, \
174
- \ \
175
- \ render: function() { \
176
- \ __current = this; \
177
- \ try { \
178
- \ var ui = render.call(this); \
179
- \ } finally { \
180
- \ __current = null; \
181
- \ } \
182
- \ return ui; \
183
- \ } \
184
- \ }); \
185
- \ }; \
186
- \ }"
187
- :: forall props state.
188
- state
189
- -> StatefulRender props state
190
- -> (props -> UI )
191
-
192
- foreign import mkStatefulUIFromSpec
193
- " var __current; \
194
- \ function mkStatefulUIFromSpec(state) { \
195
- \ return function(render) { \
196
- \ return function (ss) { \
197
- \ var specs = {}; \
198
- \ for (var s in ss) { \
199
- \ if (ss.hasOwnProperty(s)) { \
200
- \ specs[s] = (function(impl) { \
201
- \ return function() { \
202
- \ __current = this; \
203
- \ try { \
204
- \ return impl.apply(this, arguments); \
205
- \ } finally { \
206
- \ __current = null; \
207
- \ } \
208
- \ } \
209
- \ })(ss[s]); \
210
- \ } \
211
- \ } \
212
- \ specs.getInitialState = function() { \
213
- \ return {state: state}; \
214
- \ }; \
215
- \ specs.render = function() { \
216
- \ __current = this; \
217
- \ try { \
218
- \ var ui = render.call(this); \
219
- \ } finally { \
220
- \ __current = null; \
221
- \ } \
222
- \ return ui; \
223
- \ }; \
224
- \ return React.createClass(specs); \
225
- \ } \
226
- \ } \
139
+ \ } \
227
140
\ }"
228
141
:: forall eff props state.
229
- state
230
- -> StatefulRender props state
231
- -> StatefulUISpec eff props state
142
+ UISpec eff props state
143
+ -> Render props state
232
144
-> (props -> UI )
233
145
234
- foreign import writeState
235
- " function writeState(state) { \
236
- \ __current.replaceState({state: state}); \
237
- \ return function() { return state; } \
238
- \ }"
239
- :: forall state eff.
240
- state
241
- -> Eff (r :: ReadStateEff state , w :: WriteStateEff state | eff ) state
242
-
243
- foreign import readState
244
- " function readState() { \
245
- \ return __current.state.state; \
246
- \ }"
247
- :: forall state eff. Eff (r :: ReadStateEff state | eff ) state
248
-
249
146
type Event = { }
250
147
type MouseEvent = { pageX :: Number , pageY :: Number }
251
148
0 commit comments