Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 3 additions & 0 deletions src/React.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/React.res
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,23 @@ captureOwnerStack reads the current Owner Stack in development and returns it as
@module("react")
@return(null_to_opt)
external captureOwnerStack: unit => option<string> = "captureOwnerStack"

/**
<Activity> lets you hide and restore the UI and internal state of its children.
[Read more on the React Documentation](https://react.dev/reference/react/Activity)
*/
module Activity = {
type mode = [#visible | #hidden]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we shouldn't rather do

type mode =
  | @as("visible") Visible
  | @as("hidden") Hidden

?

I know that's not how we did it for domProps and also not for the React Native bindings, but I think that was because @as for variant constructors was not available at the time of their writing.

In general, these days I would only use polymorphic variants instead of normal variants when there is a good reason to do so.

One example for use of normal variants everywhere are the rescript-mui bindings.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ok I made the change.

But I'm curious now : what's the good reason to use polyvariants ? 😄

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But I'm curious now : what's the good reason to use polyvariants ? 😄

Composable error handling for example.
There was some post about this for ReScript, cannot find it right now.

Here is an article about that for OCaml: https://keleshev.com/composable-error-handling-in-ocaml


type props = {mode?: mode, children: element, name?: string}

@module("react")
external make: component<props> = "Activity"
}

/**
useEffectEvent is a React Hook that lets you extract non-reactive logic from your Effects into a reusable function called an Effect Event.
[Read more on the React Documentation](https://react.dev/reference/react/useEffectEvent)
*/
@module("react")
external useEffectEvent: (unit => unit) => unit = "useEffectEvent"
28 changes: 28 additions & 0 deletions src/ReactDOMServer.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,31 @@ external renderToString: React.element => string = "renderToString"

@module("react-dom/server")
external renderToStaticMarkup: React.element => string = "renderToStaticMarkup"

type resumeOptions<'error> = {
nonce?: string,
signal?: ReactDOMStatic.abortSignal,
onError?: 'error => unit,
}

/**
resume streams a pre-rendered React tree to a Readable Web Stream.
[Read more on the React Documentation](https://react.dev/reference/react-dom/server/resume)
*/
@module("react-dom/server")
external resume: (
React.element,
ReactDOMStatic.postponedState,
~options: resumeOptions<'error>=?,
) => promise<ReactDOMStatic.readableStream> = "resume"

/**
resumeToPipeableStream streams a pre-rendered React tree to a pipeable Node.js Stream.
[Read more on the React Documentation](https://react.dev/reference/react-dom/server/resumeToPipeableStream)
*/
@module("react-dom/server")
external resumeToPipeableStream: (
React.element,
ReactDOMStatic.postponedState,
~options: resumeOptions<'error>=?,
) => promise<ReactDOMStatic.nodeStream> = "resumeToPipeableStream"
36 changes: 34 additions & 2 deletions src/ReactDOMStatic.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type nodeStream // NodeJs.Stream.stream

type readableStream // WebAPI.FileAPI.readableStream

type postponedState

type prerenderOptions<'error> = {
bootstrapScriptContent?: string,
bootstrapScripts?: array<string>,
Expand All @@ -15,16 +17,46 @@ type prerenderOptions<'error> = {
signal?: abortSignal,
}

type staticResult = {prelude: readableStream}
type staticResult = {prelude: readableStream, postponed: postponedState}

/**
prerender renders a React tree to a static HTML string using a Web Stream.
[Read more on the React Documentation](https://react.dev/reference/react-dom/static/prerender)
*/
@module("react-dom/static")
external prerender: (React.element, ~options: prerenderOptions<'error>=?) => promise<staticResult> =
"prerender"

type staticResultNode = {prelude: nodeStream}
/**
resumeAndPrerender continues a prerendered React tree to a static HTML string using a Web Stream.
[Read more on the React Documentation](https://react.dev/reference/react-dom/static/resumeAndPrerender)
*/
@module("react-dom/static")
external resumeAndPrerender: (
React.element,
postponedState,
~options: prerenderOptions<'error>=?,
) => promise<staticResult> = "resumeAndPrerender"

type staticResultNode = {prelude: nodeStream, postponed: postponedState}

/**
prerenderToNodeStream renders a React tree to a static HTML string using a Node.js Stream.
[Read more on the React Documentation](https://react.dev/reference/react-dom/static/prerenderToNodeStream)
*/
@module("react-dom/static")
external prerenderToNodeStream: (
React.element,
~options: prerenderOptions<'error>=?,
) => promise<staticResultNode> = "prerenderToNodeStream"

/**
resumeAndPrerenderToNodeStream continues a prerendered React tree to a static HTML string using a a Node.js Stream.
[Read more on the React Documentation](https://react.dev/reference/react-dom/static/resumeAndPrerenderToNodeStream)
*/
@module("react-dom/static")
external resumeAndPrerenderToNodeStream: (
React.element,
postponedState,
~options: prerenderOptions<'error>=?,
) => promise<staticResultNode> = "resumeAndPrerenderToNodeStream"