Skip to content

Commit 6a81df7

Browse files
committed
fix ErrorBoundary comp by external binding
This reverts commit 8704f78.
1 parent 0f74265 commit 6a81df7

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ finalOutput/*.js
99
/docs/
1010
*.log
1111
.bsb.lock
12-
/src/**/*.js
1312
_esy
1413
_build
1514
*.install

Changes.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## master
44

5-
- Rewrite the `RescriptReactErrorBoundary` component implementation with `@react.component`, so it can be compatible with the changes of JSX PPX.
5+
- Nothing yet
66

77
## v0.10.3
88

@@ -26,14 +26,12 @@ For history on previous evolution of the code, check out the original [reason-re
2626
- **IMPORTANT:** Currently, old third-party packages that are still dependent on `reason-react` will not mix with other `@rescript/react` based code due to a build system problem. Which means that every third-party dependency needs to be upgraded to `@rescript/react` first to make it compatible. See [this forum discussion](https://forum.rescript-lang.org/t/discussion-reason-react-rescript-react-migration-path/1086) for more details.
2727

2828
- Removed legacy modules ("record api"):
29-
3029
- `ReasonReactCompat`
3130
- `ReactDOMServerRe`
3231
- `ReactEventRe`
3332
- `ReasonReactOptimizedCreateClass`
3433

3534
- Renamed existing modules:
36-
3735
- `ReasonReactErrorBoundary` -> `RescriptReactErrorBoundary`
3836
- `ReasonReactRouter` -> `RescriptReactRouter`
3937
- (Note: Usually the two only valid styles would be `ReScript` or `rescript`, the latter being the version for technical writing. We are using `Rescript` here, since it is essentially the capitalized version of `rescript`)

src/RescriptReactErrorBoundary.res

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,15 @@
33
* As soon as React provides a mechanism for error-catching using functional component,
44
* this is likely to be deprecated and/or move to user space.
55
")
6-
type reactComponentClass
7-
8-
@module("react") external component: reactComponentClass = "Component"
9-
106
type info = {componentStack: string}
117

128
type params<'error> = {
139
error: 'error,
1410
info: info,
1511
}
1612

17-
let getErrorBoundary: reactComponentClass => React.element = %raw(`
18-
function (Component) {
19-
function ErrorBoundary(props) {
20-
Component.call(this);
21-
this.state = {error: undefined};
22-
};
23-
ErrorBoundary.prototype = Object.create(Component.prototype);
24-
ErrorBoundary.prototype.componentDidCatch = function(error, info) {
25-
this.setState({error: {error: error, info: info}})
26-
};
27-
ErrorBoundary.prototype.render = function() {
28-
return this.state.error != undefined ? this.props.fallback(this.state.error) : this.props.children
29-
}
30-
return ErrorBoundary;
31-
}
32-
`)
33-
34-
@react.component
35-
let make = (~children as _: React.element, ~fallback as _: params<'error> => React.element) =>
36-
getErrorBoundary(component)
13+
@react.component @module("./react/ErrorBoundary.js")
14+
external make: (
15+
~children: React.element,
16+
~fallback: params<'error> => React.element,
17+
) => React.element = "default"

src/react/ErrorBoundary.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var React = require("react");
2+
3+
export default (function (Component) {
4+
function ErrorBoundary(props) {
5+
Component.call(this);
6+
this.state = { error: undefined };
7+
}
8+
ErrorBoundary.prototype = Object.create(Component.prototype);
9+
ErrorBoundary.prototype.componentDidCatch = function (error, info) {
10+
this.setState({ error: { error: error, info: info } });
11+
};
12+
ErrorBoundary.prototype.render = function () {
13+
return this.state.error != undefined
14+
? this.props.fallback(this.state.error)
15+
: this.props.children;
16+
};
17+
return ErrorBoundary;
18+
})(React.Component);

0 commit comments

Comments
 (0)