File tree Expand file tree Collapse file tree 6 files changed +149
-1
lines changed Expand file tree Collapse file tree 6 files changed +149
-1
lines changed Original file line number Diff line number Diff line change 33Low-level React DOM bindings for PureScript
44
55- [ Module Documentation] ( docs/ )
6+
7+ ## Installation
8+
9+ ```
10+ bower install purescript-react-dom
11+ ```
12+
13+ ## Example
14+
15+ Please refer to [ purescript-react-example] ( https://github.com/ethul/purescript-react-example )
Original file line number Diff line number Diff line change 11{
22 "name" : " purescript-react-dom" ,
3+ "description" : " PureScript bindings for react-dom" ,
34 "main" : " " ,
5+ "keywords" : [
6+ " purescript" ,
7+ " react"
8+ ],
9+ "license" : " MIT" ,
410 "ignore" : [
511 " *" ,
612 " !src/**/*"
7- ]
13+ ],
14+ "repository" : {
15+ "type" : " git" ,
16+ "url" : " git://github.com/purescript-contrib/purescript-react-dom.git"
17+ },
18+ "dependencies" : {
19+ "purescript-dom" : " ~0.2.15" ,
20+ "purescript-react" : " ~0.6.0"
21+ }
822}
Original file line number Diff line number Diff line change 1+ ## Module ReactDOM
2+
3+ #### ` render `
4+
5+ ``` purescript
6+ render :: forall eff. ReactElement -> Element -> Eff (dom :: DOM | eff) (Maybe ReactComponent)
7+ ```
8+
9+ Render a React element in a document element. Returns Nothing for stateless components.
10+
11+ #### ` unmountComponentAtNode `
12+
13+ ``` purescript
14+ unmountComponentAtNode :: forall eff. Element -> Eff (dom :: DOM | eff) Boolean
15+ ```
16+
17+ Removes a mounted React element in a document element. Returns true if it was unmounted, false otherwise.
18+
19+ #### ` findDOMNode `
20+
21+ ``` purescript
22+ findDOMNode :: forall eff. ReactComponent -> Eff (dom :: DOM | eff) Element
23+ ```
24+
25+ Finds the DOM node rendered by the component.
26+
27+ #### ` renderToString `
28+
29+ ``` purescript
30+ renderToString :: ReactElement -> String
31+ ```
32+
33+ Render a React element as a string.
34+
35+ #### ` renderToStaticMarkup `
36+
37+ ``` purescript
38+ renderToStaticMarkup :: ReactElement -> String
39+ ```
40+
41+ Render a React element as static markup string without extra DOM attributes.
42+
43+
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " purescript-react-dom" ,
3+ "files" : [],
4+ "peerDependencies" : {
5+ "react-dom" : " ^0.14.6"
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ /* global exports */
2+ "use strict" ;
3+
4+ // module ReactDOM
5+
6+ var ReactDOM = require ( 'react-dom' ) ;
7+
8+ var ReactDOMServer = require ( 'react-dom/server' ) ;
9+
10+ function renderFn ( nothing , just , element , container ) {
11+ return function ( ) {
12+ var result = ReactDOM . render ( element , container ) ;
13+ return result === null ? nothing : just ( result ) ;
14+ }
15+ }
16+ exports . renderFn = renderFn ;
17+
18+ function unmountComponentAtNode ( container ) {
19+ return function ( ) {
20+ return ReactDOM . unmountComponentAtNode ( container ) ;
21+ } ;
22+ }
23+ exports . unmountComponentAtNode = unmountComponentAtNode ;
24+
25+ function findDOMNode ( component ) {
26+ return function ( ) {
27+ return ReactDOM . findDOMNode ( component ) ;
28+ } ;
29+ }
30+ exports . findDOMNode = findDOMNode ;
31+
32+ exports . renderToString = ReactDOMServer . renderToString ;
33+
34+ exports . renderToStaticMarkup = ReactDOMServer . renderToStaticMarkup ;
Original file line number Diff line number Diff line change 1+ module ReactDOM
2+ ( render
3+ , unmountComponentAtNode
4+ , findDOMNode
5+ , renderToString
6+ , renderToStaticMarkup
7+ ) where
8+
9+ import Control.Monad.Eff (Eff ())
10+
11+ import Data.Function (Fn4 (), runFn4 )
12+ import Data.Maybe (Maybe (..))
13+
14+ import DOM (DOM ())
15+ import DOM.Node.Types (Element ())
16+
17+ import React (ReactElement (), ReactComponent ())
18+
19+ -- | Render a React element in a document element. Returns Nothing for stateless components.
20+ render :: forall eff . ReactElement -> Element -> Eff (dom :: DOM | eff ) (Maybe ReactComponent )
21+ render = runFn4 renderFn Nothing Just
22+
23+ foreign import renderFn
24+ :: forall eff . Fn4 (Maybe ReactComponent )
25+ (ReactComponent -> Maybe ReactComponent )
26+ ReactElement
27+ Element
28+ (Eff (dom :: DOM | eff ) (Maybe ReactComponent ))
29+
30+ -- | Removes a mounted React element in a document element. Returns true if it was unmounted, false otherwise.
31+ foreign import unmountComponentAtNode :: forall eff . Element -> Eff (dom :: DOM | eff ) Boolean
32+
33+ -- | Finds the DOM node rendered by the component.
34+ foreign import findDOMNode :: forall eff . ReactComponent -> Eff (dom :: DOM | eff ) Element
35+
36+ -- | Render a React element as a string.
37+ foreign import renderToString :: ReactElement -> String
38+
39+ -- | Render a React element as static markup string without extra DOM attributes.
40+ foreign import renderToStaticMarkup :: ReactElement -> String
You can’t perform that action at this time.
0 commit comments