Skip to content

Commit caae2e1

Browse files
committed
Go back to using CommonJS modules
Our current presets didn't include ES3 transforms by default, so IE8 support is broken. Normally we would have fixed it by adding a few plugins: * babel-plugin-transform-es3-member-expression-literals * babel-plugin-transform-es3-property-literals Unfortunately there is a [bug in Babel](https://phabricator.babeljs.io/T2817) that prevents them from working correctly in certain cases with `export default` declarations. Until this is resolved, we will go back to using CommonJS modules internally.
1 parent f7c5a42 commit caae2e1

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

src/components/Provider.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Component, PropTypes, Children } from 'react'
2-
import storeShape from '../utils/storeShape'
1+
const { Component, PropTypes, Children } = require('react')
2+
const storeShape = require('../utils/storeShape')
33

44
let didWarnAboutReceivingStore = false
55
function warnAboutReceivingStore() {
@@ -17,7 +17,7 @@ function warnAboutReceivingStore() {
1717
)
1818
}
1919

20-
export default class Provider extends Component {
20+
class Provider extends Component {
2121
getChildContext() {
2222
return { store: this.store }
2323
}
@@ -49,3 +49,5 @@ Provider.propTypes = {
4949
Provider.childContextTypes = {
5050
store: storeShape.isRequired
5151
}
52+
53+
module.exports = Provider

src/components/connect.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Component, createElement } from 'react'
2-
import storeShape from '../utils/storeShape'
3-
import shallowEqual from '../utils/shallowEqual'
4-
import isPlainObject from '../utils/isPlainObject'
5-
import wrapActionCreators from '../utils/wrapActionCreators'
6-
import hoistStatics from 'hoist-non-react-statics'
7-
import invariant from 'invariant'
1+
const { Component, createElement } = require('react')
2+
const storeShape = require('../utils/storeShape')
3+
const shallowEqual = require('../utils/shallowEqual')
4+
const isPlainObject = require('../utils/isPlainObject')
5+
const wrapActionCreators = require('../utils/wrapActionCreators')
6+
const hoistStatics = require('hoist-non-react-statics')
7+
const invariant = require('invariant')
88

99
const defaultMapStateToProps = state => ({}) // eslint-disable-line no-unused-vars
1010
const defaultMapDispatchToProps = dispatch => ({ dispatch })
@@ -21,7 +21,7 @@ function getDisplayName(WrappedComponent) {
2121
// Helps track hot reloading.
2222
let nextVersion = 0
2323

24-
export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
24+
function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
2525
const shouldSubscribe = Boolean(mapStateToProps)
2626
const finalMapStateToProps = mapStateToProps || defaultMapStateToProps
2727
const finalMapDispatchToProps = isPlainObject(mapDispatchToProps) ?
@@ -273,3 +273,5 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
273273
return hoistStatics(Connect, WrappedComponent)
274274
}
275275
}
276+
277+
module.exports = connect

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Provider from './components/Provider'
2-
import connect from './components/connect'
1+
const Provider = require('./components/Provider')
2+
const connect = require('./components/connect')
33

4-
export { Provider, connect }
4+
module.exports = { Provider, connect }

src/utils/isPlainObject.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fnToString = (fn) => Function.prototype.toString.call(fn)
44
* @param {any} obj The object to inspect.
55
* @returns {boolean} True if the argument appears to be a plain object.
66
*/
7-
export default function isPlainObject(obj) {
7+
function isPlainObject(obj) {
88
if (!obj || typeof obj !== 'object') {
99
return false
1010
}
@@ -23,3 +23,5 @@ export default function isPlainObject(obj) {
2323
&& constructor instanceof constructor
2424
&& fnToString(constructor) === fnToString(Object)
2525
}
26+
27+
module.exports = isPlainObject

src/utils/shallowEqual.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function shallowEqual(objA, objB) {
1+
function shallowEqual(objA, objB) {
22
if (objA === objB) {
33
return true
44
}
@@ -21,3 +21,5 @@ export default function shallowEqual(objA, objB) {
2121

2222
return true
2323
}
24+
25+
module.exports = shallowEqual

src/utils/storeShape.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { PropTypes } from 'react'
1+
const { PropTypes } = require('react')
22

3-
export default PropTypes.shape({
3+
const storeShape = PropTypes.shape({
44
subscribe: PropTypes.func.isRequired,
55
dispatch: PropTypes.func.isRequired,
66
getState: PropTypes.func.isRequired
77
})
8+
9+
module.exports = storeShape

src/utils/wrapActionCreators.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { bindActionCreators } from 'redux'
22

3-
export default function wrapActionCreators(actionCreators) {
3+
function wrapActionCreators(actionCreators) {
44
return dispatch => bindActionCreators(actionCreators, dispatch)
55
}
6+
7+
module.exports = wrapActionCreators

0 commit comments

Comments
 (0)