Skip to content

Commit

Permalink
Go back to using CommonJS modules
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gaearon committed Dec 28, 2015
1 parent f7c5a42 commit caae2e1
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, PropTypes, Children } from 'react'
import storeShape from '../utils/storeShape'
const { Component, PropTypes, Children } = require('react')
const storeShape = require('../utils/storeShape')

let didWarnAboutReceivingStore = false
function warnAboutReceivingStore() {
Expand All @@ -17,7 +17,7 @@ function warnAboutReceivingStore() {
)
}

export default class Provider extends Component {
class Provider extends Component {
getChildContext() {
return { store: this.store }
}
Expand Down Expand Up @@ -49,3 +49,5 @@ Provider.propTypes = {
Provider.childContextTypes = {
store: storeShape.isRequired
}

module.exports = Provider
18 changes: 10 additions & 8 deletions src/components/connect.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component, createElement } from 'react'
import storeShape from '../utils/storeShape'
import shallowEqual from '../utils/shallowEqual'
import isPlainObject from '../utils/isPlainObject'
import wrapActionCreators from '../utils/wrapActionCreators'
import hoistStatics from 'hoist-non-react-statics'
import invariant from 'invariant'
const { Component, createElement } = require('react')
const storeShape = require('../utils/storeShape')
const shallowEqual = require('../utils/shallowEqual')
const isPlainObject = require('../utils/isPlainObject')
const wrapActionCreators = require('../utils/wrapActionCreators')
const hoistStatics = require('hoist-non-react-statics')
const invariant = require('invariant')

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

export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
const shouldSubscribe = Boolean(mapStateToProps)
const finalMapStateToProps = mapStateToProps || defaultMapStateToProps
const finalMapDispatchToProps = isPlainObject(mapDispatchToProps) ?
Expand Down Expand Up @@ -273,3 +273,5 @@ export default function connect(mapStateToProps, mapDispatchToProps, mergeProps,
return hoistStatics(Connect, WrappedComponent)
}
}

module.exports = connect
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Provider from './components/Provider'
import connect from './components/connect'
const Provider = require('./components/Provider')
const connect = require('./components/connect')

export { Provider, connect }
module.exports = { Provider, connect }
4 changes: 3 additions & 1 deletion src/utils/isPlainObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fnToString = (fn) => Function.prototype.toString.call(fn)
* @param {any} obj The object to inspect.
* @returns {boolean} True if the argument appears to be a plain object.
*/
export default function isPlainObject(obj) {
function isPlainObject(obj) {
if (!obj || typeof obj !== 'object') {
return false
}
Expand All @@ -23,3 +23,5 @@ export default function isPlainObject(obj) {
&& constructor instanceof constructor
&& fnToString(constructor) === fnToString(Object)
}

module.exports = isPlainObject
4 changes: 3 additions & 1 deletion src/utils/shallowEqual.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function shallowEqual(objA, objB) {
function shallowEqual(objA, objB) {
if (objA === objB) {
return true
}
Expand All @@ -21,3 +21,5 @@ export default function shallowEqual(objA, objB) {

return true
}

module.exports = shallowEqual
6 changes: 4 additions & 2 deletions src/utils/storeShape.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { PropTypes } from 'react'
const { PropTypes } = require('react')

export default PropTypes.shape({
const storeShape = PropTypes.shape({
subscribe: PropTypes.func.isRequired,
dispatch: PropTypes.func.isRequired,
getState: PropTypes.func.isRequired
})

module.exports = storeShape
4 changes: 3 additions & 1 deletion src/utils/wrapActionCreators.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { bindActionCreators } from 'redux'

export default function wrapActionCreators(actionCreators) {
function wrapActionCreators(actionCreators) {
return dispatch => bindActionCreators(actionCreators, dispatch)
}

module.exports = wrapActionCreators

0 comments on commit caae2e1

Please sign in to comment.