diff --git a/src/ReactDOMServer.re b/src/ReactDOMServer.re index e53898ad9..95a1cd02d 100644 --- a/src/ReactDOMServer.re +++ b/src/ReactDOMServer.re @@ -4,72 +4,3 @@ external renderToString: React.element => string = "renderToString"; [@mel.module "react-dom/server"] external renderToStaticMarkup: React.element => string = "renderToStaticMarkup"; - -[@deriving abstract] -type options = { - [@mel.optional] - bootstrapScriptContent: option(string), - [@mel.optional] - bootstrapScripts: option(array(string)), - [@mel.optional] - bootstrapModules: option(array(string)), - [@mel.optional] - identifierPrefix: option(string), - [@mel.optional] - namespaceURI: option(string), - [@mel.optional] - nonce: option(string), - [@mel.optional] - onAllReady: option(unit => unit), - [@mel.optional] - onError: option(Js.Exn.t => unit), - [@mel.optional] - onShellReady: option(unit => unit), - [@mel.optional] - onShellError: option(Js.Exn.t => unit), - [@mel.optional] - progressiveChunkSize: option(int), -}; - -type pipeableStream = { - /* Using empty object instead of Node.stream since Melange don't provide a binding to node's Stream (https://nodejs.org/api/stream.html) */ - pipe: Js.t({.}) => unit, - abort: unit => unit, -}; - -[@mel.module "react-dom/server"] -external renderToPipeableStream: (React.element, options) => pipeableStream = - "renderToPipeableStream"; - -let renderToPipeableStream = - ( - ~bootstrapScriptContent=?, - ~bootstrapScripts=?, - ~bootstrapModules=?, - ~identifierPrefix=?, - ~namespaceURI=?, - ~nonce=?, - ~onAllReady=?, - ~onError=?, - ~onShellReady=?, - ~onShellError=?, - ~progressiveChunkSize=?, - element, - ) => - renderToPipeableStream( - element, - options( - ~bootstrapScriptContent?, - ~bootstrapScripts?, - ~bootstrapModules?, - ~identifierPrefix?, - ~namespaceURI?, - ~nonce?, - ~onAllReady?, - ~onError?, - ~onShellReady?, - ~onShellError?, - ~progressiveChunkSize?, - (), - ), - ); diff --git a/src/ReactDOMServer.rei b/src/ReactDOMServer.rei index 49567a750..b967a1465 100644 --- a/src/ReactDOMServer.rei +++ b/src/ReactDOMServer.rei @@ -5,51 +5,4 @@ external renderToString: React.element => string = "renderToString"; external renderToStaticMarkup: React.element => string = "renderToStaticMarkup"; -[@deriving abstract] -type options = { - [@mel.optional] - bootstrapScriptContent: option(string), - [@mel.optional] - bootstrapScripts: option(array(string)), - [@mel.optional] - bootstrapModules: option(array(string)), - [@mel.optional] - identifierPrefix: option(string), - [@mel.optional] - namespaceURI: option(string), - [@mel.optional] - nonce: option(string), - [@mel.optional] - onAllReady: option(unit => unit), - [@mel.optional] - onError: option(Js.Exn.t => unit), - [@mel.optional] - onShellReady: option(unit => unit), - [@mel.optional] - onShellError: option(Js.Exn.t => unit), - [@mel.optional] - progressiveChunkSize: option(int), -}; -type pipeableStream = { - /* Using empty object instead of Node.stream since Melange don't provide a binding to node's Stream (https://nodejs.org/api/stream.html) */ - pipe: Js.t({.}) => unit, - abort: unit => unit, -}; - -let renderToPipeableStream: - ( - ~bootstrapScriptContent: string=?, - ~bootstrapScripts: array(string)=?, - ~bootstrapModules: array(string)=?, - ~identifierPrefix: string=?, - ~namespaceURI: string=?, - ~nonce: string=?, - ~onAllReady: unit => unit=?, - ~onError: Js.Exn.t => unit=?, - ~onShellReady: unit => unit=?, - ~onShellError: Js.Exn.t => unit=?, - ~progressiveChunkSize: int=?, - React.element - ) => - pipeableStream; diff --git a/src/ReactDOMServerNodeOnly.re b/src/ReactDOMServerNodeOnly.re new file mode 100644 index 000000000..3d00c0121 --- /dev/null +++ b/src/ReactDOMServerNodeOnly.re @@ -0,0 +1,68 @@ +[@deriving abstract] +type options = { + [@mel.optional] + bootstrapScriptContent: option(string), + [@mel.optional] + bootstrapScripts: option(array(string)), + [@mel.optional] + bootstrapModules: option(array(string)), + [@mel.optional] + identifierPrefix: option(string), + [@mel.optional] + namespaceURI: option(string), + [@mel.optional] + nonce: option(string), + [@mel.optional] + onAllReady: option(unit => unit), + [@mel.optional] + onError: option(Js.Exn.t => unit), + [@mel.optional] + onShellReady: option(unit => unit), + [@mel.optional] + onShellError: option(Js.Exn.t => unit), + [@mel.optional] + progressiveChunkSize: option(int), +}; + +type pipeableStream = { + /* Using empty object instead of Node.stream since Melange don't provide a binding to node's Stream (https://nodejs.org/api/stream.html) */ + pipe: Js.t({.}) => unit, + abort: unit => unit, +}; + +[@mel.module "react-dom/server"] +external renderToPipeableStream: (React.element, options) => pipeableStream = + "renderToPipeableStream"; + +let renderToPipeableStream = + ( + ~bootstrapScriptContent=?, + ~bootstrapScripts=?, + ~bootstrapModules=?, + ~identifierPrefix=?, + ~namespaceURI=?, + ~nonce=?, + ~onAllReady=?, + ~onError=?, + ~onShellReady=?, + ~onShellError=?, + ~progressiveChunkSize=?, + element, + ) => + renderToPipeableStream( + element, + options( + ~bootstrapScriptContent?, + ~bootstrapScripts?, + ~bootstrapModules?, + ~identifierPrefix?, + ~namespaceURI?, + ~nonce?, + ~onAllReady?, + ~onError?, + ~onShellReady?, + ~onShellError?, + ~progressiveChunkSize?, + (), + ), + ); diff --git a/src/ReactDOMServerNodeOnly.rei b/src/ReactDOMServerNodeOnly.rei new file mode 100644 index 000000000..c1cef959e --- /dev/null +++ b/src/ReactDOMServerNodeOnly.rei @@ -0,0 +1,49 @@ +[@deriving abstract] +type options = { + [@mel.optional] + bootstrapScriptContent: option(string), + [@mel.optional] + bootstrapScripts: option(array(string)), + [@mel.optional] + bootstrapModules: option(array(string)), + [@mel.optional] + identifierPrefix: option(string), + [@mel.optional] + namespaceURI: option(string), + [@mel.optional] + nonce: option(string), + [@mel.optional] + onAllReady: option(unit => unit), + [@mel.optional] + onError: option(Js.Exn.t => unit), + [@mel.optional] + onShellReady: option(unit => unit), + [@mel.optional] + onShellError: option(Js.Exn.t => unit), + [@mel.optional] + progressiveChunkSize: option(int), +}; + +type pipeableStream = { + /* Using empty object instead of Node.stream since Melange don't provide a binding to node's Stream (https://nodejs.org/api/stream.html) */ + pipe: Js.t({.}) => unit, + abort: unit => unit, +}; + +let renderToPipeableStream: + ( + ~bootstrapScriptContent: string=?, + ~bootstrapScripts: array(string)=?, + ~bootstrapModules: array(string)=?, + ~identifierPrefix: string=?, + ~namespaceURI: string=?, + ~nonce: string=?, + ~onAllReady: unit => unit=?, + ~onError: Js.Exn.t => unit=?, + ~onShellReady: unit => unit=?, + ~onShellError: Js.Exn.t => unit=?, + ~progressiveChunkSize: int=?, + React.element + ) => + + pipeableStream; diff --git a/src/dune b/src/dune index 2d1b62e29..9b13b2e8e 100644 --- a/src/dune +++ b/src/dune @@ -16,3 +16,12 @@ (pps melange.ppx reason-react-ppx)) (libraries melange.dom) (modes melange)) + +(library + (name ReactDOMServerNodeOnly) + (public_name reason-react.node) + (modules ReactDOMServerNodeOnly) + (libraries react) + (preprocess + (pps melange.ppx)) + (modes melange)) diff --git a/test/ReactDOM__test.re b/test/ReactDOM__test.re index 9f1a3c6d9..334b35533 100644 --- a/test/ReactDOM__test.re +++ b/test/ReactDOM__test.re @@ -53,8 +53,8 @@ describe("ReactDOM", () => { hasErrored := true; }, ); - let {pipe, abort: _}: ReactDOMServer.pipeableStream = - ReactDOMServer.renderToPipeableStream( + let {pipe, abort: _}: ReactDOMServerNodeOnly.pipeableStream = + ReactDOMServerNodeOnly.renderToPipeableStream(
"Hello world!"->React.string
, ); pipe(stream); diff --git a/test/dune b/test/dune index c595839ce..a50a84e20 100644 --- a/test/dune +++ b/test/dune @@ -3,6 +3,6 @@ (target test) (module_systems (commonjs bs.js)) - (libraries reason-react jest melange.belt) + (libraries reason-react reason-react.node jest melange.belt) (preprocess (pps melange.ppx reason-react-ppx)))