From 942ef0fbf8191015c2096bf361387a44863116d1 Mon Sep 17 00:00:00 2001 From: Matthias Le Brun Date: Thu, 16 Apr 2020 13:00:18 +0200 Subject: [PATCH] Use Console.error instead of throwing so that ReactDOMRe doesn't import Caml_builtin_exceptions --- lib/js/src/ReactDOMRe.js | 25 ++++++++----------------- src/ReactDOMRe.re | 30 ++++++++++++------------------ 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/lib/js/src/ReactDOMRe.js b/lib/js/src/ReactDOMRe.js index 041f774ae..ad9ff5f37 100644 --- a/lib/js/src/ReactDOMRe.js +++ b/lib/js/src/ReactDOMRe.js @@ -2,7 +2,6 @@ var React = require("react"); var ReactDom = require("react-dom"); -var Caml_builtin_exceptions = require("bs-platform/lib/js/caml_builtin_exceptions.js"); function renderToElementWithClassName(reactElement, className) { var elements = document.getElementsByClassName(className); @@ -10,20 +9,16 @@ function renderToElementWithClassName(reactElement, className) { ReactDom.render(reactElement, elements[0]); return /* () */0; } else { - throw [ - Caml_builtin_exceptions.invalid_argument, - "ReactDOMRe.renderToElementWithClassName: no element of class " + (className + " found in the HTML.") - ]; + console.error("ReactDOMRe.renderToElementWithClassName: no element of class " + (className + " found in the HTML.")); + return /* () */0; } } function renderToElementWithId(reactElement, id) { var match = document.getElementById(id); if (match == null) { - throw [ - Caml_builtin_exceptions.invalid_argument, - "ReactDOMRe.renderToElementWithId : no element of id " + (id + " found in the HTML.") - ]; + console.error("ReactDOMRe.renderToElementWithId : no element of id " + (id + " found in the HTML.")); + return /* () */0; } else { ReactDom.render(reactElement, match); return /* () */0; @@ -36,20 +31,16 @@ function hydrateToElementWithClassName(reactElement, className) { ReactDom.hydrate(reactElement, elements[0]); return /* () */0; } else { - throw [ - Caml_builtin_exceptions.invalid_argument, - "ReactDOMRe.hydrateToElementWithClassName: no element of class " + (className + " found in the HTML.") - ]; + console.error("ReactDOMRe.hydrateToElementWithClassName: no element of class " + (className + " found in the HTML.")); + return /* () */0; } } function hydrateToElementWithId(reactElement, id) { var match = document.getElementById(id); if (match == null) { - throw [ - Caml_builtin_exceptions.invalid_argument, - "ReactDOMRe.hydrateToElementWithId : no element of id " + (id + " found in the HTML.") - ]; + console.error("ReactDOMRe.hydrateToElementWithId : no element of id " + (id + " found in the HTML.")); + return /* () */0; } else { ReactDom.hydrate(reactElement, match); return /* () */0; diff --git a/src/ReactDOMRe.re b/src/ReactDOMRe.re index d61b3e913..a63fdd011 100644 --- a/src/ReactDOMRe.re +++ b/src/ReactDOMRe.re @@ -18,12 +18,10 @@ external _getElementById: string => option(Dom.element) = let renderToElementWithClassName = (reactElement, className) => switch (_getElementsByClassName(className)) { | [||] => - raise( - Invalid_argument( - "ReactDOMRe.renderToElementWithClassName: no element of class " - ++ className - ++ " found in the HTML.", - ), + Js.Console.error( + "ReactDOMRe.renderToElementWithClassName: no element of class " + ++ className + ++ " found in the HTML.", ) | elements => render(reactElement, Array.unsafe_get(elements, 0)) }; @@ -31,12 +29,10 @@ let renderToElementWithClassName = (reactElement, className) => let renderToElementWithId = (reactElement, id) => switch (_getElementById(id)) { | None => - raise( - Invalid_argument( - "ReactDOMRe.renderToElementWithId : no element of id " - ++ id - ++ " found in the HTML.", - ), + Js.Console.error( + "ReactDOMRe.renderToElementWithId : no element of id " + ++ id + ++ " found in the HTML.", ) | Some(element) => render(reactElement, element) }; @@ -47,12 +43,10 @@ external hydrate: (React.element, Dom.element) => unit = "hydrate"; let hydrateToElementWithClassName = (reactElement, className) => switch (_getElementsByClassName(className)) { | [||] => - raise( - Invalid_argument( - "ReactDOMRe.hydrateToElementWithClassName: no element of class " - ++ className - ++ " found in the HTML.", - ), + Js.Console.error( + "ReactDOMRe.hydrateToElementWithClassName: no element of class " + ++ className + ++ " found in the HTML.", ) | elements => hydrate(reactElement, Array.unsafe_get(elements, 0)) };