Skip to content

Add createPortal #57

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
Oct 1, 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
3 changes: 1 addition & 2 deletions examples/component/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
all: node_modules
purs compile src/*.purs '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs'
purs bundle output/*/*.js > output/bundle.js
echo 'PS.Main.main();' >> output/bundle.js
purs bundle -m Main --main Main output/*/*.js > output/bundle.js
node_modules/.bin/browserify output/bundle.js -o html/index.js

node_modules:
Expand Down
3 changes: 1 addition & 2 deletions examples/controlled-input/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
all: node_modules
purs compile src/*.purs '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs'
purs bundle output/*/*.js > output/bundle.js
echo 'PS.Main.main();' >> output/bundle.js
purs bundle -m Main --main Main output/*/*.js > output/bundle.js
node_modules/.bin/browserify output/bundle.js -o html/index.js

node_modules:
Expand Down
3 changes: 1 addition & 2 deletions examples/counter/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
all: node_modules
purs compile src/*.purs '../../src/**/*.purs' '../../bower_components/purescript-*/src/**/*.purs'
purs bundle output/*/*.js > output/bundle.js
echo 'PS.Main.main();' >> output/bundle.js
purs bundle -m Main --main Main output/*/*.js > output/bundle.js
node_modules/.bin/browserify output/bundle.js -o html/index.js

node_modules:
Expand Down
4 changes: 4 additions & 0 deletions src/React/Basic/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ exports.findDOMNode_ = function(instance) {
return ReactDOM.findDOMNode(instance);
};

exports.createPortal_ = function(jsx, node) {
return ReactDOM.createPortal(jsx, node);
};

exports.mergeStyles = function(styles) {
return Object.assign.apply(null, [ {} ].concat(styles));
};
10 changes: 10 additions & 0 deletions src/React/Basic/DOM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module React.Basic.DOM
, hydrate'
, unmount
, findDOMNode
, createPortal
, text
, css
, mergeStyles
Expand All @@ -22,6 +23,7 @@ module React.Basic.DOM
import Prelude

import Data.Either (Either)
import Data.Function.Uncurried (Fn2, runFn2)
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, toMaybe)
import Effect (Effect)
Expand Down Expand Up @@ -98,6 +100,14 @@ findDOMNode instance_ = try do
-- | Warning: Relies on `ReactDOM.findDOMNode` which may throw exceptions
foreign import findDOMNode_ :: EffectFn1 ComponentInstance (Nullable Node)

-- | Divert a render tree into a separate DOM node. The node's
-- | content will be overwritten and managed by React, similar
-- | to `render` and `hydrate`.
createPortal :: JSX -> Element -> JSX
createPortal = runFn2 createPortal_

foreign import createPortal_ :: Fn2 JSX Element JSX

-- | Create a text node.
text :: String -> JSX
text = unsafeCoerce
Expand Down