Skip to content

Commit 09b7851

Browse files
committed
Updating README and documentation
1 parent 2c040de commit 09b7851

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
purescript-react
22
================
33

4-
[![Maintainer: paf31](https://img.shields.io/badge/maintainer-paf31-lightgrey.svg)](http://github.com/paf31) ![React: 0.12.2](https://img.shields.io/badge/react-0.12.2-lightgrey.svg)
4+
[![Maintainer: paf31](https://img.shields.io/badge/maintainer-paf31-lightgrey.svg)](http://github.com/paf31) ![React: 0.13.3](https://img.shields.io/badge/react-0.13.3-lightgrey.svg)
55

66
Low-level React Bindings for PureScript.
77

@@ -28,6 +28,17 @@ import Prelude
2828
2929
import Control.Monad.Eff
3030
31+
import Data.Maybe.Unsafe (fromJust)
32+
import Data.Nullable (toMaybe)
33+
34+
import DOM (DOM())
35+
import DOM.HTML (window)
36+
import DOM.HTML.Document (body)
37+
import DOM.HTML.Types (htmlElementToElement)
38+
import DOM.HTML.Window (document)
39+
40+
import DOM.Node.Types (Element())
41+
3142
import React
3243
3344
import qualified React.DOM as D
@@ -41,12 +52,20 @@ counter = mkUI $ spec 0 \ctx -> do
4152
val <- readState ctx
4253
return $ D.p [ P.className "Counter"
4354
, P.onClick (incrementCounter ctx)
44-
]
55+
]
4556
[ D.text (show val)
4657
, D.text " Click me to increment!"
4758
]
4859
49-
main = do
50-
let component = D.div [] [ counter {} ]
51-
renderToBody component
60+
main = container >>= render ui
61+
where
62+
ui :: UI
63+
ui = D.div [] [ createFactory counter {} ]
64+
65+
container :: forall eff. Eff (dom :: DOM | eff) Element
66+
container = do
67+
win <- window
68+
doc <- document win
69+
elm <- fromJust <$> toMaybe <$> body doc
70+
return $ htmlElementToElement elm
5271
```

docs/React.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,21 @@ type UISpec props state eff = { render :: Render props state eff, displayName ::
160160

161161
A specification of a component.
162162

163-
#### `UIFactory`
163+
#### `spec`
164164

165165
``` purescript
166-
type UIFactory props = props -> UI
166+
spec :: forall props state eff. state -> Render props state eff -> UISpec props state eff
167167
```
168168

169-
Factory function for components.
169+
Create a component specification.
170170

171-
#### `spec`
171+
#### `UIClass`
172172

173173
``` purescript
174-
spec :: forall props state eff. state -> Render props state eff -> UISpec props state eff
174+
data UIClass :: * -> *
175175
```
176176

177-
Create a component specification.
177+
Factory function for components.
178178

179179
#### `getProps`
180180

@@ -227,10 +227,10 @@ Transform the component state by applying a function.
227227
#### `mkUI`
228228

229229
``` purescript
230-
mkUI :: forall props state eff. UISpec props state eff -> UIFactory props
230+
mkUI :: forall props state eff. UISpec props state eff -> UIClass props
231231
```
232232

233-
Create a component from a component spec.
233+
Create a React class from a specification.
234234

235235
#### `handle`
236236

@@ -240,36 +240,36 @@ handle :: forall eff ev props state result. (ev -> EventHandlerContext eff props
240240

241241
Create an event handler.
242242

243-
#### `renderToString`
243+
#### `render`
244244

245245
``` purescript
246-
renderToString :: UI -> String
246+
render :: forall eff. UI -> Element -> Eff (dom :: DOM | eff) UI
247247
```
248248

249-
Render a component as a string.
249+
Render a React element in a document element.
250250

251-
#### `renderToBody`
251+
#### `renderToString`
252252

253253
``` purescript
254-
renderToBody :: forall eff. UI -> Eff (dom :: DOM | eff) UI
254+
renderToString :: UI -> String
255255
```
256256

257-
Render a component to the document body.
257+
Render a React element as a string.
258258

259-
#### `renderToElementById`
259+
#### `createElement`
260260

261261
``` purescript
262-
renderToElementById :: forall eff. String -> UI -> Eff (dom :: DOM | eff) UI
262+
createElement :: forall props. UIClass props -> props -> Array UI -> UI
263263
```
264264

265-
Render a component to the element with the specified ID.
265+
Create an element from a React class.
266266

267-
#### `createElement`
267+
#### `createFactory`
268268

269269
``` purescript
270-
createElement :: forall props. UIFactory props -> props -> Array UI -> UI
270+
createFactory :: forall props. UIClass props -> props -> UI
271271
```
272272

273-
Create an element from a component factory.
273+
Create a factory from a React class.
274274

275275

test/Main.purs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,3 @@ main = body' >>= render ui
7575
doc <- document win
7676
elm <- fromJust <$> toMaybe <$> body doc
7777
return $ htmlElementToElement elm
78-

0 commit comments

Comments
 (0)