Skip to content

Commit 2b3aa6d

Browse files
committed
Remove use of __current
1 parent e05f6bd commit 2b3aa6d

File tree

5 files changed

+320
-266
lines changed

5 files changed

+320
-266
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ import Control.Monad.Eff
3131
import React
3232
import React.DOM
3333
34-
hello = mkUI spec do
35-
props <- getProps
34+
hello = mkUI (spec unit) \ctx -> do
35+
props <- getProps ctx
3636
return $ h1 [ className "Hello"
3737
]
3838
[ text "Hello, "
3939
, text props.name
4040
]
4141
42-
incrementCounter e = do
43-
val <- readState
44-
writeState (val + 1)
42+
incrementCounter ctx e = do
43+
val <- readState ctx
44+
writeState ctx (val + 1)
4545
46-
counter = mkUI (spec { getInitialState = return 0 }) do
47-
val <- readState
46+
counter = mkUI (spec 0) \ctx -> do
47+
val <- readState ctx
4848
return $ p [ className "Counter"
49-
, onClick incrementCounter
49+
, onClick (incrementCounter ctx)
5050
]
5151
[ text (show val)
5252
, text " Click me to increment!"

docs/React.md

Lines changed: 74 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,201 +1,213 @@
11
## Module React
22

3+
This module defines foreign types and functions which wrap React's functionality.
4+
35
#### `UI`
46

57
``` purescript
68
data UI :: *
79
```
810

11+
A virtual DOM node, or component.
12+
913
#### `UIRef`
1014

1115
``` purescript
12-
data UIRef :: # ! -> *
16+
data UIRef :: *
1317
```
1418

19+
A reference to a component, essentially React's `this`.
20+
1521
#### `EventHandler`
1622

1723
``` purescript
1824
data EventHandler :: * -> *
1925
```
2026

27+
An event handler. The type argument represents the type of the event.
28+
2129
#### `Disallowed`
2230

2331
``` purescript
2432
data Disallowed :: !
2533
```
2634

35+
This phantom effect indicates that both read and write access to a resource are disallowed.
36+
2737
#### `ReadAllowed`
2838

2939
``` purescript
3040
data ReadAllowed :: !
3141
```
3242

43+
This phantom effect indicates that only read access to a resource is allowed.
44+
3345
#### `WriteAllowed`
3446

3547
``` purescript
3648
data WriteAllowed :: !
3749
```
3850

51+
This phantom effect indicates that only write access to a resource is allowed.
52+
3953
#### `ReactState`
4054

4155
``` purescript
4256
data ReactState :: # ! -> * -> !
4357
```
4458

59+
This effect indicates that a computation may read or write the component state.
60+
4561
#### `ReactProps`
4662

4763
``` purescript
4864
data ReactProps :: * -> !
4965
```
5066

67+
This effect indicates that a computation may read the component props.
68+
5169
#### `ReactRefs`
5270

5371
``` purescript
5472
data ReactRefs :: * -> !
5573
```
5674

57-
#### `noop0`
75+
This effect indicates that a computation may read the component refs.
5876

59-
``` purescript
60-
noop0 :: forall eff result. Eff eff result
61-
```
62-
63-
#### `noop1`
77+
#### `Event`
6478

6579
``` purescript
66-
noop1 :: forall a eff result. a -> Eff eff result
80+
data Event :: *
6781
```
6882

69-
#### `noop2`
83+
The type of DOM events.
7084

71-
``` purescript
72-
noop2 :: forall a b eff result. a -> b -> Eff eff result
73-
```
74-
75-
#### `Render`
85+
#### `MouseEvent`
7686

7787
``` purescript
78-
type Render props refs state eff = Eff (props :: ReactProps props, refs :: Disallowed, state :: ReactState (read :: ReadAllowed) state | eff) UI
88+
type MouseEvent = { pageX :: Number, pageY :: Number }
7989
```
8090

81-
#### `UISpec`
91+
The type of mouse events.
8292

83-
``` purescript
84-
type UISpec props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8 = { getInitialState :: Eff (props :: ReactProps props, state :: Disallowed, refs :: Disallowed | eff1) state, componentWillMount :: Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: Disallowed | eff2) Unit, componentDidMount :: Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff3) Unit, componentWillReceiveProps :: props -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff4) Unit, shouldComponentUpdate :: props -> state -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff5) Boolean, componentWillUpdate :: props -> state -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state, refs :: ReactRefs refs | eff6) Unit, componentDidUpdate :: props -> state -> Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed) state, refs :: ReactRefs refs | eff7) Unit, componentWillUnmount :: Eff (props :: ReactProps props, state :: ReactState (read :: ReadAllowed) state, refs :: ReactRefs refs | eff8) Unit }
85-
```
86-
87-
#### `spec`
93+
#### `KeyboardEvent`
8894

8995
``` purescript
90-
spec :: forall props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8. UISpec props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8
96+
type KeyboardEvent = { altKey :: Boolean, ctrlKey :: Boolean, charCode :: Int, key :: String, keyCode :: Int, locale :: String, location :: Int, metaKey :: Boolean, repeat :: Boolean, shiftKey :: Boolean, which :: Int }
9197
```
9298

93-
#### `getProps`
99+
The type of keyboard events.
94100

95-
``` purescript
96-
getProps :: forall props eff. Eff (props :: ReactProps props | eff) props
97-
```
98-
99-
#### `getRefs`
101+
#### `EventHandlerContext`
100102

101103
``` purescript
102-
getRefs :: forall refs eff. Eff (refs :: ReactRefs refs | eff) refs
104+
type EventHandlerContext eff props refs state result = Eff (props :: ReactProps props, refs :: ReactRefs refs, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state | eff) result
103105
```
104106

105-
#### `writeState`
107+
A function which handles events.
106108

107-
``` purescript
108-
writeState :: forall state statePerms eff. state -> Eff (state :: ReactState (read :: ReadAllowed, write :: WriteAllowed | statePerms) state | eff) state
109-
```
110-
111-
#### `readState`
109+
#### `Render`
112110

113111
``` purescript
114-
readState :: forall state statePerms eff. Eff (state :: ReactState (read :: ReadAllowed | statePerms) state | eff) state
112+
type Render props refs state eff = UIRef -> Eff (props :: ReactProps props, refs :: Disallowed, state :: ReactState (read :: ReadAllowed) state | eff) UI
115113
```
116114

117-
#### `getSelf`
115+
A rendering function.
118116

119-
``` purescript
120-
getSelf :: forall eff. Eff eff (UIRef eff)
121-
```
122-
123-
#### `runUI`
117+
#### `UISpec`
124118

125119
``` purescript
126-
runUI :: forall refEff eff result. UIRef refEff -> Eff refEff result -> Eff eff result
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 }
127121
```
128122

129-
#### `mkUI`
123+
A specification of a component.
124+
125+
#### `spec`
130126

131127
``` purescript
132-
mkUI :: forall props refs state eff eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8. UISpec props refs state eff1 eff2 eff3 eff4 eff5 eff6 eff7 eff8 -> Render props refs state eff -> props -> UI
128+
spec :: forall props refs state eff. state -> UISpec props refs state eff
133129
```
134130

135-
#### `DOMEvent`
131+
Create a component specification.
132+
133+
#### `getProps`
136134

137135
``` purescript
138-
type DOMEvent = forall attrs. { | attrs }
136+
getProps :: forall props eff. UIRef -> Eff (props :: ReactProps props | eff) props
139137
```
140138

141-
#### `DOMEventTarget`
139+
Read the component props.
140+
141+
#### `getRefs`
142142

143143
``` purescript
144-
type DOMEventTarget = forall attrs. { | attrs }
144+
getRefs :: forall refs eff. UIRef -> Eff (refs :: ReactRefs refs | eff) refs
145145
```
146146

147-
#### `Event`
147+
Read the component refs.
148+
149+
#### `writeState`
148150

149151
``` purescript
150-
type Event = { bubbles :: Boolean, cancelable :: Boolean, currentTarget :: DOMEventTarget, defaultPrevented :: Boolean, eventPhase :: Number, isTrusted :: Boolean, nativeEvent :: DOMEvent, preventDefault :: { } -> { }, stopPropagation :: { } -> { }, target :: DOMEventTarget, timeStamp :: Number, eventType :: String }
152+
writeState :: forall state eff. UIRef -> state -> Eff (state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state | eff) state
151153
```
152154

153-
#### `MouseEvent`
155+
Write the component state.
156+
157+
#### `readState`
154158

155159
``` purescript
156-
type MouseEvent = { pageX :: Number, pageY :: Number }
160+
readState :: forall state stateEff eff. UIRef -> Eff (state :: ReactState (read :: ReadAllowed | stateEff) state | eff) state
157161
```
158162

159-
#### `KeyboardEvent`
163+
Read the component state.
164+
165+
#### `transformState`
160166

161167
``` purescript
162-
type KeyboardEvent = { altKey :: Boolean, ctrlKey :: Boolean, charCode :: Number, key :: String, keyCode :: Number, locale :: String, location :: Number, metaKey :: Boolean, repeat :: Boolean, shiftKey :: Boolean, which :: Number }
168+
transformState :: forall state statePerms eff. UIRef -> (state -> state) -> Eff (state :: ReactState (read :: ReadAllowed, write :: WriteAllowed) state | eff) state
163169
```
164170

165-
#### `EventHandlerContext`
171+
Transform the component state by applying a function.
172+
173+
#### `mkUI`
166174

167175
``` purescript
168-
type EventHandlerContext eff props refs state result = forall statePerms. Eff (props :: ReactProps props, refs :: ReactRefs refs, state :: ReactState (read :: ReadAllowed, write :: WriteAllowed | statePerms) state | eff) result
176+
mkUI :: forall props refs state eff. UISpec props refs state eff -> Render props refs state eff -> props -> UI
169177
```
170178

179+
Create a component from a component spec.
180+
171181
#### `handle`
172182

173183
``` purescript
174184
handle :: forall eff ev props refs state result. (ev -> EventHandlerContext eff props refs state result) -> EventHandler ev
175185
```
176186

187+
Create an event handler.
188+
177189
#### `renderToString`
178190

179191
``` purescript
180192
renderToString :: UI -> String
181193
```
182194

195+
Render a component as a string.
196+
183197
#### `renderToBody`
184198

185199
``` purescript
186200
renderToBody :: forall eff. UI -> Eff (dom :: DOM | eff) UI
187201
```
188202

203+
Render a component to the document body.
204+
189205
#### `renderToElementById`
190206

191207
``` purescript
192208
renderToElementById :: forall eff. String -> UI -> Eff (dom :: DOM | eff) UI
193209
```
194210

195-
#### `deferred`
196-
197-
``` purescript
198-
deferred :: forall a eff. Eff eff a -> Eff eff a
199-
```
211+
Render a component to the element with the specified ID.
200212

201213

example/index.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
<!doctype>
22
<html>
33
<head>
4-
<style>
5-
.Counter, .Hello {
6-
cursor: pointer;
7-
user-select: none;
8-
-webkit-user-select: none;
9-
-moz-user-select: none;
10-
}
11-
</style>
4+
<title>purescript-react example</title>
125
</head>
136
<body>
14-
<script src="../bower_components/react/react.js"></script>
15-
<script src="index.js"></script>
7+
<script src="../bower_components/react/react.js"></script>
8+
<script src="index.js"></script>
169
</body>
1710
</html>

0 commit comments

Comments
 (0)