Skip to content

Commit

Permalink
Add createPortal (#57)
Browse files Browse the repository at this point in the history
* Add createPortal

* Simplify Makefiles
  • Loading branch information
spicydonuts authored Oct 1, 2018
1 parent 3dc3f53 commit 43f08b5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
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

0 comments on commit 43f08b5

Please sign in to comment.