Skip to content

Updates for 0.12 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2018
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
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"url": "git://github.com/purescript-contrib/purescript-react-dom.git"
},
"dependencies": {
"purescript-dom": "^4.5.0",
"purescript-react": "^5.0.0",
"purescript-eff": "^3.1.0"
"purescript-web-dom": "^1.0.0",
"purescript-react": "https://github.com/natefaubion/purescript-react.git#compiler/0.12",
"purescript-effect": "^2.0.0"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"build": "pulp build"
},
"devDependencies": {
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"pulp": "^12.0.0",
"purescript-psa": "^0.6.0",
"purescript": "^0.12.0",
"rimraf": "^2.5.4"
},
"peerDependencies": {
Expand Down
45 changes: 14 additions & 31 deletions src/ReactDOM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,30 @@ module ReactDOM
, findDOMNode
, renderToString
, renderToStaticMarkup
, refToNode
) where

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Uncurried (runEffFn1, EffFn4, EffFn1, runEffFn4)
import DOM (DOM)
import DOM.Node.Types (Element, Node)
import Effect (Effect)
import Effect.Uncurried (runEffectFn1, EffectFn4, EffectFn1, runEffectFn4)
import Data.Function.Uncurried (runFn1, Fn1)
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, toMaybe)
import React (ReactElement, ReactComponent, Ref)
import Unsafe.Coerce (unsafeCoerce)
import React (ReactElement, ReactComponent)
import Web.DOM.Element (Element)

-- | Render a React element in a document element. Returns Nothing for stateless components.
render
:: forall eff
. ReactElement
:: ReactElement
-> Element
-> Eff (dom :: DOM | eff) (Maybe ReactComponent)
render = runEffFn4 renderImpl Nothing Just
-> Effect (Maybe ReactComponent)
render = runEffectFn4 renderImpl Nothing Just

-- | Removes a mounted React element in a document element.
-- | Returns true if it was unmounted, false otherwise.
unmountComponentAtNode :: forall eff. Element -> Eff (dom :: DOM | eff) Boolean
unmountComponentAtNode = runEffFn1 unmountComponentAtNodeImpl
unmountComponentAtNode :: Element -> Effect Boolean
unmountComponentAtNode = runEffectFn1 unmountComponentAtNodeImpl

-- | Finds the DOM node rendered by the component.
findDOMNode :: forall eff. ReactComponent -> Eff (dom :: DOM | eff) Element
findDOMNode = runEffFn1 findDOMNodeImpl
findDOMNode :: ReactComponent -> Effect Element
findDOMNode = runEffectFn1 findDOMNodeImpl

-- | Render a React element as a string.
renderToString :: ReactElement -> String
Expand All @@ -43,35 +38,23 @@ renderToStaticMarkup :: ReactElement -> String
renderToStaticMarkup = runFn1 renderToStaticMarkupImpl

foreign import renderImpl
:: forall eff
. EffFn4
(dom :: DOM | eff)
:: EffectFn4
(Maybe ReactComponent)
(ReactComponent -> Maybe ReactComponent)
ReactElement
Element
(Maybe ReactComponent)

foreign import unmountComponentAtNodeImpl
:: forall eff
. EffFn1
(dom :: DOM | eff)
:: EffectFn1
Element
Boolean

foreign import findDOMNodeImpl
:: forall eff
. EffFn1
(dom :: DOM | eff)
:: EffectFn1
ReactComponent
Element

foreign import renderToStringImpl :: Fn1 ReactElement String

foreign import renderToStaticMarkupImpl :: Fn1 ReactElement String

refToNode :: Nullable Ref -> Maybe Node
refToNode ref = toMaybe (coerce ref)
where
coerce :: Nullable Ref -> Nullable Node
coerce = unsafeCoerce
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this function was here and exported since it is unsafe and unnecessary. It's much better to just go through Foreign and use Web.DOM's readers.