Skip to content

Commit

Permalink
feat(react-dom): add experimental module
Browse files Browse the repository at this point in the history
list of experimental bind:
* preconnect
* prefetchDNS
* preinit
* preinitModule
* preload
* preloadModule
  • Loading branch information
r17x committed Jul 21, 2024
1 parent 15affd0 commit 7b56214
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/ReactDOM.re
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,33 @@ external unmountComponentAtNode: Dom.element => unit =
[@mel.module "react-dom"]
external flushSync: (unit => unit) => unit = "flushSync";

module Experimental = {
[@deriving jsProperties]
type preOptions = {
[@mel.as "as"] [@mel.optional]
_as: option([ | `script ]),
[@mel.optional]
crossOrigin: option(string),
[@mel.optional]
integrity: option(string),
[@mel.optional]
nonce: option(string),
};

[@mel.module "react-dom"]
external preconnect: string => unit = "preconnect";
[@mel.module "react-dom"]
external prefetchDNS: string => unit = "prefetchDNS";
[@mel.module "react-dom"]
external preinit: string => unit = "preinit";
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
external preload: string => unit = "preload";
[@mel.module "react-dom"]
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
}

external domElementToObj: Dom.element => Js.t({..}) = "%identity";

type style = Style.t;
Expand Down
47 changes: 47 additions & 0 deletions src/ReactDOM.rei
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,53 @@ external unmountComponentAtNode: Dom.element => unit =
[@mel.module "react-dom"]
external flushSync: (unit => unit) => unit = "flushSync";

module Experimental: {
/* This module is used to bind to APIs for future versions of ReactDOM. There is no guarantee of backwards compatibility or stability. */

/*
preinitModule and preloadModule options.
https://react.dev/reference/react-dom/preinitModule#parameters
https://react.dev/reference/react-dom/preloadModule#parameters
*/
[@deriving jsProperties]
type preOptions = {
/* a required string. It must be 'script'. */
[@mel.as "as"] [@mel.optional]
_as: option([ | `script ]),
/*
a required string. It must be "anonymous", "use-credentials", and "".
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin
*/
[@mel.optional]
crossOrigin: option(string),
/*
A cryptographic hash of the module, to verify its authenticity.
https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
*/
[@mel.optional]
integrity: option(string),
/*
A cryptographic nonce to allow the module when using a strict Content Security Policy.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce
*/
[@mel.optional]
nonce: option(string),
};

[@mel.module "react-dom"]
external preconnect: string => unit = "preconnect";
[@mel.module "react-dom"]
external prefetchDNS: string => unit = "prefetchDNS";
[@mel.module "react-dom"]
external preinit: string => unit = "preinit";
[@mel.module "react-dom"]
external preinitModule: (string, ~options: preOptions=?, unit) => unit = "preinitModule";
[@mel.module "react-dom"]
external preload: string => unit = "preload";
[@mel.module "react-dom"]
external preloadModule: (string, ~options: preOptions=?, unit) => unit = "preloadModule";
}

external domElementToObj: Dom.element => Js.t({..}) = "%identity";

type style = Style.t;
Expand Down

0 comments on commit 7b56214

Please sign in to comment.