Skip to content

Commit cccebcb

Browse files
committed
Open effect rows for React methods (#22).
1 parent 39fddc1 commit cccebcb

File tree

2 files changed

+110
-74
lines changed

2 files changed

+110
-74
lines changed

example/app/app.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ foreign import interval
1111
\ return function() { return setInterval(action, ms); } \
1212
\ } \
1313
\}"
14-
:: forall eff r. Number -> Eff (trace :: Trace) r -> Eff (eff) {}
14+
:: forall eff r. Number -> Eff (trace :: Trace) r -> Eff (eff) Unit
1515

1616
helloInConsole e = do
1717
props <- getProps

src/React.purs

Lines changed: 109 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ module React where
44
import Control.Monad.Eff
55

66
foreign import data DOM :: !
7-
foreign import data ReadPropsEff :: * -> !
8-
foreign import data ReadRefsEff :: * -> !
9-
foreign import data ReadStateEff :: * -> !
10-
foreign import data WriteStateEff :: * -> !
117
foreign import data UI :: *
12-
foreign import data UIRef :: * -> * -> *
8+
foreign import data UIRef :: # ! -> *
139
foreign import data EventHandler :: * -> *
1410

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+
1519
foreign import noop0
1620
"function noop0() { return null; }"
1721
:: forall eff result. Eff ( eff ) result
@@ -24,57 +28,83 @@ module React where
2428
"var noop2 = noop0"
2529
:: forall a b eff result. a -> b -> Eff ( eff ) result
2630

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
5537
) UI
5638

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
75103
}
76104

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
78108
spec =
79109
{ getInitialState: noop0
80110
, componentWillMount: noop0
@@ -86,37 +116,46 @@ module React where
86116
, componentWillUnmount: noop0
87117
}
88118
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
90128
updateAlways props state = return true
91129

92130
foreign import getProps
93131
" function getProps() { \
94132
\ return __current.props; \
95133
\ }"
96134
:: forall props eff.
97-
Eff (p :: ReadPropsEff props | eff) props
135+
Eff (props :: ReactProps props | eff) props
98136

99137
foreign import getRefs
100138
" function getRefs() { \
101139
\ return __current.refs; \
102140
\ }"
103141
:: forall refs eff.
104-
Eff (f :: ReadRefsEff refs | eff) refs
142+
Eff (refs :: ReactRefs refs | eff) refs
105143

106144
foreign import writeState
107145
" function writeState(state) { \
108146
\ __current.replaceState({state: state}); \
109147
\ return function() { return state; } \
110148
\ }"
111-
:: forall state eff.
149+
:: forall state statePerms eff.
112150
state
113-
-> Eff (r :: ReadStateEff state, w :: WriteStateEff state | eff) state
151+
-> Eff (state :: ReactState (read :: ReadAllowed, write :: WriteAllowed | statePerms) state | eff) state
114152

115153
foreign import readState
116154
" function readState() { \
117155
\ return __current.state.state; \
118156
\ }"
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
120159

121160
transformState f = do
122161
state <- readState
@@ -126,8 +165,8 @@ module React where
126165
" function getSelf() { \
127166
\ return __current; \
128167
\ }"
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)
131170

132171
foreign import runUI
133172
" function runUI(ref) { \
@@ -144,10 +183,7 @@ module React where
144183
\ } \
145184
\ } \
146185
\ }"
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
151187

152188
foreign import mkUI
153189
" var __current; \
@@ -188,9 +224,9 @@ module React where
188224
\ return React.createClass(specs); \
189225
\ } \
190226
\ }"
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
194230
-> (props -> UI)
195231

196232
type DOMEvent = forall attrs. { | attrs}
@@ -222,10 +258,10 @@ module React where
222258
, which :: Number
223259
}
224260

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 statePerms. Eff (
262+
props :: ReactProps props,
263+
refs :: ReactRefs refs,
264+
state :: ReactState (read :: ReadAllowed, write :: WriteAllowed | statePerms) state
229265
| eff
230266
) result
231267

@@ -242,8 +278,8 @@ module React where
242278
\ return res; \
243279
\ } \
244280
\ }"
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)
247283
-> EventHandler ev
248284

249285
foreign import renderToString

0 commit comments

Comments
 (0)