Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 4 additions & 41 deletions psc-package.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,9 @@
{
"name": "purescript-react-dom",
"set": "psc-0.10.1",
"source": "https://raw.githubusercontent.com/purescript/package-sets/psc-0.10.1/packages.json",
"set": "psc-0.12.5-20190504",
"source": "https://github.com/purescript/package-sets.git",
"depends": [
"arrays",
"bifunctors",
"control",
"datetime",
"distributive",
"dom",
"eff",
"eff-functions",
"either",
"enums",
"exceptions",
"foldable-traversable",
"foreign",
"functions",
"generics",
"identity",
"integers",
"invariant",
"js-date",
"lazy",
"lists",
"math",
"maybe",
"media-types",
"monoid",
"newtype",
"nonempty",
"nullable",
"partial",
"prelude",
"proxy",
"react",
"st",
"strings",
"tailrec",
"transformers",
"tuples",
"unfoldable",
"unsafe-coerce"
"web-dom",
"react"
]
}
9 changes: 6 additions & 3 deletions src/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
var ReactDOM = require("react-dom");
var ReactDOMServer = require("react-dom/server");

exports.renderImpl = function (nothing, just, element, container) {
var result = ReactDOM.render(element, container);
return result === null ? nothing : just(result);
exports.renderImpl = function (element, container) {
return ReactDOM.render(element, container);
};

exports.hydrateImpl = function (element, container) {
return ReactDOM.hydrate(element, container);
};

exports.unmountComponentAtNodeImpl = ReactDOM.unmountComponentAtNode;
Expand Down
31 changes: 23 additions & 8 deletions src/ReactDOM.purs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module ReactDOM
( render
, hydrate
, unmountComponentAtNode
, findDOMNode
, renderToString
, renderToStaticMarkup
) where

import Effect (Effect)
import Effect.Uncurried (runEffectFn1, EffectFn4, EffectFn1, runEffectFn4)
import Prelude

import Data.Function.Uncurried (runFn1, Fn1)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe)
import Data.Nullable (Nullable, toMaybe)
import Effect (Effect)
import Effect.Uncurried (EffectFn1, EffectFn2, runEffectFn1, runEffectFn2)
import React (ReactElement, ReactComponent)
import Web.DOM.Element (Element)

Expand All @@ -18,7 +22,14 @@ render
:: ReactElement
-> Element
-> Effect (Maybe ReactComponent)
render = runEffectFn4 renderImpl Nothing Just
render rEl el = toMaybe <$> runEffectFn2 renderImpl rEl el

-- | Same as `render`, but is used to hydrate a container whose HTML contents were rendered on the server.
hydrate
:: ReactElement
-> Element
-> Effect (Maybe ReactComponent)
hydrate rEl el = toMaybe <$> runEffectFn2 hydrateImpl rEl el

-- | Removes a mounted React element in a document element.
-- | Returns true if it was unmounted, false otherwise.
Expand All @@ -38,12 +49,16 @@ renderToStaticMarkup :: ReactElement -> String
renderToStaticMarkup = runFn1 renderToStaticMarkupImpl

foreign import renderImpl
:: EffectFn4
(Maybe ReactComponent)
(ReactComponent -> Maybe ReactComponent)
:: EffectFn2
ReactElement
Element
(Nullable ReactComponent)

foreign import hydrateImpl
:: EffectFn2
ReactElement
Element
(Maybe ReactComponent)
(Nullable ReactComponent)

foreign import unmountComponentAtNodeImpl
:: EffectFn1
Expand Down