Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert error boundary code to Reason #839

Merged
merged 5 commits into from
Jun 15, 2024

Conversation

anmonteiro
Copy link
Member

generated code looks like:

// Generated by Melange
'use strict';

const Js__Js_undefined = require("melange.js/js_undefined.bs.js");
const React = require("react");

function errorBoundary(_props) {
  let self = this ;
  React.Component.call(self);
  self.state = {
    error: undefined
  };
}

errorBoundary.prototype = Object.create(React.Component.prototype);

errorBoundary.prototype.componentDidCatch = (function (error, info) {
    let self = this ;
    self.setState({
          error: {
            error: error,
            info: info
          }
        });
  });

errorBoundary.prototype.render = (function () {
    let self = this ;
    if (Js__Js_undefined.testAny(self.state.error)) {
      return self.props.children;
    } else {
      return self.props.fallback(self.state.error);
    }
  });

const make = errorBoundary;

exports.make = make;
/* errorBoundary Not a pure module */

Copy link
Member

@davesnx davesnx left a comment

Choose a reason for hiding this comment

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

Very cursed code, but nicely done

src/ReasonReactErrorBoundary.re Show resolved Hide resolved
@anmonteiro anmonteiro merged commit 39a146f into main Jun 15, 2024
3 checks passed
@anmonteiro anmonteiro deleted the anmonteiro/error-boundary-in-reason branch June 15, 2024 22:57
jchavarri added a commit to jchavarri/opam-repository that referenced this pull request Aug 19, 2024
CHANGES:

* Add `isValidElement` (@r17x in
  reasonml/reason-react#837)
* Add `startTransition` (@r17x in
  reasonml/reason-react#838)
* Convert `ReasonReactErrorBoundary` to Reason instead of `%raw` JS. This has
  the benefit of skipping a hardcoded `require('react')` call (@anmonteiro in
  [reasonml/reason-react#839](reasonml/reason-react#839))
* Add CSS Box Alignment Module Level 3 (@davesnx in
  reasonml/reason-react#847)
* Fix: Remove "unique `key` prop" warnings from multi-child fragment elements
  (@jchavarri in reasonml/reason-react#852)
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
CHANGES:

* Add `isValidElement` (@r17x in
  reasonml/reason-react#837)
* Add `startTransition` (@r17x in
  reasonml/reason-react#838)
* Convert `ReasonReactErrorBoundary` to Reason instead of `%raw` JS. This has
  the benefit of skipping a hardcoded `require('react')` call (@anmonteiro in
  [reasonml/reason-react#839](reasonml/reason-react#839))
* Add CSS Box Alignment Module Level 3 (@davesnx in
  reasonml/reason-react#847)
* Fix: Remove "unique `key` prop" warnings from multi-child fragment elements
  (@jchavarri in reasonml/reason-react#852)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants