Skip to content

Commit 0447617

Browse files
committed
Simplify phantom types for access to resources.
1 parent 2b3aa6d commit 0447617

File tree

2 files changed

+125
-72
lines changed

2 files changed

+125
-72
lines changed

docs/React.md

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,63 @@ An event handler. The type argument represents the type of the event.
2929
#### `Disallowed`
3030

3131
``` purescript
32-
data Disallowed :: !
32+
data Disallowed
3333
```
3434

35-
This phantom effect indicates that both read and write access to a resource are disallowed.
35+
This phantom type indicates that both read and write access to a resource are disallowed.
3636

37-
#### `ReadAllowed`
37+
#### `Read`
3838

3939
``` purescript
40-
data ReadAllowed :: !
40+
data Read write
4141
```
4242

43-
This phantom effect indicates that only read access to a resource is allowed.
43+
This phantom type indicates that read access to a resource is allowed.
4444

45-
#### `WriteAllowed`
45+
#### `Write`
4646

4747
``` purescript
48-
data WriteAllowed :: !
48+
data Write
4949
```
5050

51-
This phantom effect indicates that only write access to a resource is allowed.
51+
This phantom type indicates that write access to a resource is allowed.
52+
53+
#### `Only`
54+
55+
``` purescript
56+
data Only
57+
```
58+
59+
This phantom type indicates that only read access to a resource is allowed.
60+
61+
#### `ReadWrite`
62+
63+
``` purescript
64+
type ReadWrite = Read Write
65+
```
66+
67+
An access synonym which indicates that both read and write access are allowed.
68+
69+
#### `ReadOnly`
70+
71+
``` purescript
72+
type ReadOnly = Read Only
73+
```
74+
75+
An access synonym which indicates that reads are allowed but writes are not.
5276

5377
#### `ReactState`
5478

5579
``` purescript
56-
data ReactState :: # ! -> * -> !
80+
data ReactState :: * -> * -> !
5781
```
5882

5983
This effect indicates that a computation may read or write the component state.
6084

85+
The first type argument is either `ReadWrite`, `ReadOnly` or `Disallowed` dependeding on the context.
86+
87+
The second type argument is the type of the state of the component.
88+
6189
#### `ReactProps`
6290

6391
``` purescript
@@ -74,6 +102,16 @@ data ReactRefs :: * -> !
74102

75103
This effect indicates that a computation may read the component refs.
76104

105+
The first type argument is either `ReadOnly` or `Disallowed` dependeding on the context.
106+
107+
#### `Refs`
108+
109+
``` purescript
110+
data Refs :: *
111+
```
112+
113+
The type of refs objects.
114+
77115
#### `Event`
78116

79117
``` purescript
@@ -101,31 +139,31 @@ The type of keyboard events.
101139
#### `EventHandlerContext`
102140

103141
``` purescript
104-
type EventHandlerContext eff props refs state result = Eff (props :: ReactProps props, refs :: ReactRefs refs, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state | eff) result
142+
type EventHandlerContext eff props state result = Eff (props :: ReactProps props, refs :: ReactRefs ReadOnly, state :: ReactState ReadWrite state | eff) result
105143
```
106144

107145
A function which handles events.
108146

109147
#### `Render`
110148

111149
``` purescript
112-
type Render props refs state eff = UIRef -> Eff (props :: ReactProps props, refs :: Disallowed, state :: ReactState (read :: ReadAllowed) state | eff) UI
150+
type Render props state eff = UIRef -> Eff (props :: ReactProps props, refs :: ReactRefs Disallowed, state :: ReactState ReadOnly state | eff) UI
113151
```
114152

115153
A rendering function.
116154

117155
#### `UISpec`
118156

119157
``` purescript
120-
type UISpec props refs state eff = { getInitialState :: UIRef -> Eff (props :: ReactProps props, state :: Disallowed, refs :: Disallowed | eff) state, componentWillMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: Disallowed | eff) Unit, componentDidMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff) Unit, componentWillReceiveProps :: UIRef -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff) Unit, shouldComponentUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff) Boolean, componentWillUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff) Unit, componentDidUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed) state, refs :: ReactRefs refs | eff) Unit, componentWillUnmount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed) state, refs :: ReactRefs refs | eff) Unit }
158+
type UISpec props state eff = { getInitialState :: UIRef -> Eff (props :: ReactProps props, state :: ReactState Disallowed state, refs :: ReactRefs Disallowed | eff) state, componentWillMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs Disallowed | eff) Unit, componentDidMount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillReceiveProps :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, shouldComponentUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Boolean, componentWillUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadWrite state, refs :: ReactRefs ReadOnly | eff) Unit, componentDidUpdate :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit, componentWillUnmount :: UIRef -> Eff (props :: ReactProps props, state :: ReactState ReadOnly state, refs :: ReactRefs ReadOnly | eff) Unit }
121159
```
122160

123161
A specification of a component.
124162

125163
#### `spec`
126164

127165
``` purescript
128-
spec :: forall props refs state eff. state -> UISpec props refs state eff
166+
spec :: forall props state eff. state -> UISpec props state eff
129167
```
130168

131169
Create a component specification.
@@ -141,47 +179,47 @@ Read the component props.
141179
#### `getRefs`
142180

143181
``` purescript
144-
getRefs :: forall refs eff. UIRef -> Eff (refs :: ReactRefs refs | eff) refs
182+
getRefs :: forall write eff. UIRef -> Eff (refs :: ReactRefs (Read write) | eff) Refs
145183
```
146184

147185
Read the component refs.
148186

149187
#### `writeState`
150188

151189
``` purescript
152-
writeState :: forall state eff. UIRef -> state -> Eff (state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state | eff) state
190+
writeState :: forall state eff. UIRef -> state -> Eff (state :: ReactState ReadWrite state | eff) state
153191
```
154192

155193
Write the component state.
156194

157195
#### `readState`
158196

159197
``` purescript
160-
readState :: forall state stateEff eff. UIRef -> Eff (state :: ReactState (read :: ReadAllowed | stateEff) state | eff) state
198+
readState :: forall state write eff. UIRef -> Eff (state :: ReactState (Read write) state | eff) state
161199
```
162200

163201
Read the component state.
164202

165203
#### `transformState`
166204

167205
``` purescript
168-
transformState :: forall state statePerms eff. UIRef -> (state -> state) -> Eff (state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state | eff) state
206+
transformState :: forall state statePerms eff. UIRef -> (state -> state) -> Eff (state :: ReactState ReadWrite state | eff) state
169207
```
170208

171209
Transform the component state by applying a function.
172210

173211
#### `mkUI`
174212

175213
``` purescript
176-
mkUI :: forall props refs state eff. UISpec props refs state eff -> Render props refs state eff -> props -> UI
214+
mkUI :: forall props state eff. UISpec props state eff -> Render props state eff -> props -> UI
177215
```
178216

179217
Create a component from a component spec.
180218

181219
#### `handle`
182220

183221
``` purescript
184-
handle :: forall eff ev props refs state result. (ev -> EventHandlerContext eff props refs state result) -> EventHandler ev
222+
handle :: forall eff ev props state result. (ev -> EventHandlerContext eff props state result) -> EventHandler ev
185223
```
186224

187225
Create an event handler.

0 commit comments

Comments
 (0)