From 208efae97b59c39930533c6b3825a23f6f3d4b33 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 29 Jan 2016 17:34:29 +0000 Subject: [PATCH] Don't depend on console and don't warn in production builds --- src/components/Provider.js | 48 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/components/Provider.js b/src/components/Provider.js index b62c0e6b1..2a5bf4178 100644 --- a/src/components/Provider.js +++ b/src/components/Provider.js @@ -1,20 +1,28 @@ const { Component, PropTypes, Children } = require('react') const storeShape = require('../utils/storeShape') -let didWarnAboutReceivingStore = false -function warnAboutReceivingStore() { - if (didWarnAboutReceivingStore) { - return +if (process.env.NODE_ENV !== 'production') { + let didWarnAboutReceivingStore = false + /* eslint-disable no-var */ + var warnAboutReceivingStore = function () { + /* eslint-enable no-var */ + if (didWarnAboutReceivingStore) { + return + } + didWarnAboutReceivingStore = true + + /* eslint-disable no-console */ + if (typeof console !== 'undefined' && typeof console.error === 'function') { + console.error( + ' does not support changing `store` on the fly. ' + + 'It is most likely that you see this error because you updated to ' + + 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + + 'automatically. See https://github.com/rackt/react-redux/releases/' + + 'tag/v2.0.0 for the migration instructions.' + ) + } + /* eslint-disable no-console */ } - - didWarnAboutReceivingStore = true - console.error( // eslint-disable-line no-console - ' does not support changing `store` on the fly. ' + - 'It is most likely that you see this error because you updated to ' + - 'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' + - 'automatically. See https://github.com/rackt/react-redux/releases/' + - 'tag/v2.0.0 for the migration instructions.' - ) } class Provider extends Component { @@ -27,7 +35,14 @@ class Provider extends Component { this.store = props.store } - componentWillReceiveProps(nextProps) { + render() { + let { children } = this.props + return Children.only(children) + } +} + +if (process.env.NODE_ENV !== 'production') { + Provider.prototype.componentWillReceiveProps = function (nextProps) { const { store } = this const { store: nextStore } = nextProps @@ -35,11 +50,6 @@ class Provider extends Component { warnAboutReceivingStore() } } - - render() { - let { children } = this.props - return Children.only(children) - } } Provider.propTypes = {