|
1 | 1 | ## Module React
|
2 | 2 |
|
| 3 | +This module defines foreign types and functions which wrap React's functionality. |
| 4 | + |
3 | 5 | #### `UI`
|
4 | 6 |
|
5 | 7 | ``` purescript
|
6 | 8 | data UI :: *
|
7 | 9 | ```
|
8 | 10 |
|
| 11 | +A virtual DOM node, or component. |
| 12 | + |
9 | 13 | #### `UIRef`
|
10 | 14 |
|
11 | 15 | ``` purescript
|
12 |
| -data UIRef :: # ! -> * |
| 16 | +data UIRef :: * |
13 | 17 | ```
|
14 | 18 |
|
| 19 | +A reference to a component, essentially React's `this`. |
| 20 | + |
15 | 21 | #### `EventHandler`
|
16 | 22 |
|
17 | 23 | ``` purescript
|
18 | 24 | data EventHandler :: * -> *
|
19 | 25 | ```
|
20 | 26 |
|
| 27 | +An event handler. The type argument represents the type of the event. |
| 28 | + |
21 | 29 | #### `Disallowed`
|
22 | 30 |
|
23 | 31 | ``` purescript
|
24 | 32 | data Disallowed :: !
|
25 | 33 | ```
|
26 | 34 |
|
| 35 | +This phantom effect indicates that both read and write access to a resource are disallowed. |
| 36 | + |
27 | 37 | #### `ReadAllowed`
|
28 | 38 |
|
29 | 39 | ``` purescript
|
30 | 40 | data ReadAllowed :: !
|
31 | 41 | ```
|
32 | 42 |
|
| 43 | +This phantom effect indicates that only read access to a resource is allowed. |
| 44 | + |
33 | 45 | #### `WriteAllowed`
|
34 | 46 |
|
35 | 47 | ``` purescript
|
36 | 48 | data WriteAllowed :: !
|
37 | 49 | ```
|
38 | 50 |
|
| 51 | +This phantom effect indicates that only write access to a resource is allowed. |
| 52 | + |
39 | 53 | #### `ReactState`
|
40 | 54 |
|
41 | 55 | ``` purescript
|
42 | 56 | data ReactState :: # ! -> * -> !
|
43 | 57 | ```
|
44 | 58 |
|
| 59 | +This effect indicates that a computation may read or write the component state. |
| 60 | + |
45 | 61 | #### `ReactProps`
|
46 | 62 |
|
47 | 63 | ``` purescript
|
48 | 64 | data ReactProps :: * -> !
|
49 | 65 | ```
|
50 | 66 |
|
| 67 | +This effect indicates that a computation may read the component props. |
| 68 | + |
51 | 69 | #### `ReactRefs`
|
52 | 70 |
|
53 | 71 | ``` purescript
|
54 | 72 | data ReactRefs :: * -> !
|
55 | 73 | ```
|
56 | 74 |
|
57 |
| -#### `noop0` |
| 75 | +This effect indicates that a computation may read the component refs. |
58 | 76 |
|
59 |
| -``` purescript |
60 |
| -noop0 :: forall eff result. Eff eff result |
61 |
| -``` |
62 |
| - |
63 |
| -#### `noop1` |
| 77 | +#### `Event` |
64 | 78 |
|
65 | 79 | ``` purescript
|
66 |
| -noop1 :: forall a eff result. a -> Eff eff result |
| 80 | +data Event :: * |
67 | 81 | ```
|
68 | 82 |
|
69 |
| -#### `noop2` |
| 83 | +The type of DOM events. |
70 | 84 |
|
71 |
| -``` purescript |
72 |
| -noop2 :: forall a b eff result. a -> b -> Eff eff result |
73 |
| -``` |
74 |
| - |
75 |
| -#### `Render` |
| 85 | +#### `MouseEvent` |
76 | 86 |
|
77 | 87 | ``` 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 } |
79 | 89 | ```
|
80 | 90 |
|
81 |
| -#### `UISpec` |
| 91 | +The type of mouse events. |
82 | 92 |
|
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` |
88 | 94 |
|
89 | 95 | ``` 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 } |
91 | 97 | ```
|
92 | 98 |
|
93 |
| -#### `getProps` |
| 99 | +The type of keyboard events. |
94 | 100 |
|
95 |
| -``` purescript |
96 |
| -getProps :: forall props eff. Eff (props :: ReactProps props | eff) props |
97 |
| -``` |
98 |
| - |
99 |
| -#### `getRefs` |
| 101 | +#### `EventHandlerContext` |
100 | 102 |
|
101 | 103 | ``` 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 |
103 | 105 | ```
|
104 | 106 |
|
105 |
| -#### `writeState` |
| 107 | +A function which handles events. |
106 | 108 |
|
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` |
112 | 110 |
|
113 | 111 | ``` 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 |
115 | 113 | ```
|
116 | 114 |
|
117 |
| -#### `getSelf` |
| 115 | +A rendering function. |
118 | 116 |
|
119 |
| -``` purescript |
120 |
| -getSelf :: forall eff. Eff eff (UIRef eff) |
121 |
| -``` |
122 |
| - |
123 |
| -#### `runUI` |
| 117 | +#### `UISpec` |
124 | 118 |
|
125 | 119 | ``` 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 } |
127 | 121 | ```
|
128 | 122 |
|
129 |
| -#### `mkUI` |
| 123 | +A specification of a component. |
| 124 | + |
| 125 | +#### `spec` |
130 | 126 |
|
131 | 127 | ``` 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 |
133 | 129 | ```
|
134 | 130 |
|
135 |
| -#### `DOMEvent` |
| 131 | +Create a component specification. |
| 132 | + |
| 133 | +#### `getProps` |
136 | 134 |
|
137 | 135 | ``` purescript
|
138 |
| -type DOMEvent = forall attrs. { | attrs } |
| 136 | +getProps :: forall props eff. UIRef -> Eff (props :: ReactProps props | eff) props |
139 | 137 | ```
|
140 | 138 |
|
141 |
| -#### `DOMEventTarget` |
| 139 | +Read the component props. |
| 140 | + |
| 141 | +#### `getRefs` |
142 | 142 |
|
143 | 143 | ``` purescript
|
144 |
| -type DOMEventTarget = forall attrs. { | attrs } |
| 144 | +getRefs :: forall refs eff. UIRef -> Eff (refs :: ReactRefs refs | eff) refs |
145 | 145 | ```
|
146 | 146 |
|
147 |
| -#### `Event` |
| 147 | +Read the component refs. |
| 148 | + |
| 149 | +#### `writeState` |
148 | 150 |
|
149 | 151 | ``` 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 |
151 | 153 | ```
|
152 | 154 |
|
153 |
| -#### `MouseEvent` |
| 155 | +Write the component state. |
| 156 | + |
| 157 | +#### `readState` |
154 | 158 |
|
155 | 159 | ``` purescript
|
156 |
| -type MouseEvent = { pageX :: Number, pageY :: Number } |
| 160 | +readState :: forall state stateEff eff. UIRef -> Eff (state :: ReactState (read :: ReadAllowed | stateEff) state | eff) state |
157 | 161 | ```
|
158 | 162 |
|
159 |
| -#### `KeyboardEvent` |
| 163 | +Read the component state. |
| 164 | + |
| 165 | +#### `transformState` |
160 | 166 |
|
161 | 167 | ``` 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 |
163 | 169 | ```
|
164 | 170 |
|
165 |
| -#### `EventHandlerContext` |
| 171 | +Transform the component state by applying a function. |
| 172 | + |
| 173 | +#### `mkUI` |
166 | 174 |
|
167 | 175 | ``` 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 |
169 | 177 | ```
|
170 | 178 |
|
| 179 | +Create a component from a component spec. |
| 180 | + |
171 | 181 | #### `handle`
|
172 | 182 |
|
173 | 183 | ``` purescript
|
174 | 184 | handle :: forall eff ev props refs state result. (ev -> EventHandlerContext eff props refs state result) -> EventHandler ev
|
175 | 185 | ```
|
176 | 186 |
|
| 187 | +Create an event handler. |
| 188 | + |
177 | 189 | #### `renderToString`
|
178 | 190 |
|
179 | 191 | ``` purescript
|
180 | 192 | renderToString :: UI -> String
|
181 | 193 | ```
|
182 | 194 |
|
| 195 | +Render a component as a string. |
| 196 | + |
183 | 197 | #### `renderToBody`
|
184 | 198 |
|
185 | 199 | ``` purescript
|
186 | 200 | renderToBody :: forall eff. UI -> Eff (dom :: DOM | eff) UI
|
187 | 201 | ```
|
188 | 202 |
|
| 203 | +Render a component to the document body. |
| 204 | + |
189 | 205 | #### `renderToElementById`
|
190 | 206 |
|
191 | 207 | ``` purescript
|
192 | 208 | renderToElementById :: forall eff. String -> UI -> Eff (dom :: DOM | eff) UI
|
193 | 209 | ```
|
194 | 210 |
|
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. |
200 | 212 |
|
201 | 213 |
|
0 commit comments