Skip to content

Commit 0565325

Browse files
Use NODE_ENV check instead of __DEV__
1 parent 829b1e2 commit 0565325

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

__tests__/ReComponent-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ describe("ReComponent", () => {
134134
});
135135

136136
it("does not throw errors in production", () => {
137+
let originalNodeEnv = process.env.NODE_ENV;
137138
try {
138-
global.__DEV__ = false;
139+
process.env.NODE_ENV = "production";
139140

140141
let click;
141142
class Example extends ReComponent {
@@ -156,7 +157,7 @@ describe("ReComponent", () => {
156157
ReactDOM.render(<Example />, container);
157158
expect(() => click()).not.toThrowError();
158159
} finally {
159-
global.__DEV__ = true;
160+
process.env.NODE_ENV = originalNodeEnv;
160161
}
161162
});
162163
});

__tests__/helpers.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// This is necessary to simulate the development environment where errors should
2-
// be reported.
3-
global.__DEV__ = true;
4-
51
export function click(element) {
62
element.dispatchEvent(new Event("click", { bubbles: true }));
73
}

src/re.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function Re(Component) {
1111
constructor(props) {
1212
super(props);
1313

14-
if (__DEV__) {
14+
if (process.env.NODE_ENV !== "production") {
1515
if (typeof this.reducer !== "function") {
1616
const name = this.displayName || this.constructor.name;
1717
throw new Error(
@@ -27,7 +27,7 @@ export function Re(Component) {
2727
const originalSetState = this.setState;
2828
let setState = this.setState;
2929

30-
if (__DEV__) {
30+
if (process.env.NODE_ENV !== "production") {
3131
this.setState = () => {
3232
const name = this.displayName || this.constructor.name;
3333
throw new Error(
@@ -86,7 +86,7 @@ export function Re(Component) {
8686
const updater = state => {
8787
const reduced = this.reducer(action, state);
8888

89-
if (__DEV__) {
89+
if (process.env.NODE_ENV !== "production") {
9090
if (typeof reduced === "undefined") {
9191
const name = this.displayName || this.constructor.name;
9292
throw new Error(
@@ -113,7 +113,7 @@ export function Re(Component) {
113113
sideEffects = reduced.sideEffects;
114114
break;
115115
default: {
116-
if (__DEV__) {
116+
if (process.env.NODE_ENV !== "production") {
117117
const name = this.displayName || this.constructor.name;
118118
throw new Error(
119119
name +

0 commit comments

Comments
 (0)