Skip to content

Commit

Permalink
Avoid crashes on environments without process.env. Fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Aug 9, 2015
1 parent b7ef178 commit 238e7d9
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/components/createConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,6 @@ export default function createConnect(React) {
this.trySubscribe();
}

componentWillUpdate() {
if (process.env.NODE_ENV !== 'production') {
if (this.version === version) {
return;
}

// We are hot reloading!
this.version = version;

// Update the state and bindings.
this.trySubscribe();
this.recomputeStateProps();
this.recomputeDispatchProps();
this.recomputeState();
}
}

componentWillReceiveProps(nextProps) {
if (!shallowEqual(nextProps, this.props)) {
this.recomputeState(nextProps);
Expand Down Expand Up @@ -189,6 +172,32 @@ export default function createConnect(React) {
}
}

if ((
// Node-like CommonJS environments (Browserify, Webpack)
typeof process !== 'undefined' &&
typeof process.env !== 'undefined' &&
process.env.NODE_ENV !== 'production'
) ||
// React Native
typeof __DEV__ !== 'undefined' &&
__DEV__ //eslint-disable-line no-undef
) {
Connect.prototype.componentWillUpdate = function componentWillUpdate() {
if (this.version === version) {
return;
}

// We are hot reloading!
this.version = version;

// Update the state and bindings.
this.trySubscribe();
this.recomputeStateProps();
this.recomputeDispatchProps();
this.recomputeState();
};
}

return Connect;
};
};
Expand Down

0 comments on commit 238e7d9

Please sign in to comment.