Skip to content

refactor: convert error boundary code to Reason#839

Merged
anmonteiro merged 5 commits intomainfrom
anmonteiro/error-boundary-in-reason
Jun 15, 2024
Merged

refactor: convert error boundary code to Reason#839
anmonteiro merged 5 commits intomainfrom
anmonteiro/error-boundary-in-reason

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

@anmonteiro anmonteiro merged commit 39a146f into main Jun 15, 2024
@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