Skip to content

Commit 65a80f8

Browse files
committed
Use ES6 modules again with es3ify as a temporary fix against IE8
1 parent 0eda221 commit 65a80f8

9 files changed

+111
-58
lines changed

.babelrc

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
{
2-
"presets": ["es2015-loose", "stage-0", "react"],
3-
"plugins": [
4-
"transform-decorators-legacy"
2+
plugins: [
3+
"transform-decorators-legacy",
4+
["transform-es2015-template-literals", { "loose": true }],
5+
"transform-es2015-literals",
6+
"transform-es2015-function-name",
7+
"transform-es2015-arrow-functions",
8+
"transform-es2015-block-scoped-functions",
9+
["transform-es2015-classes", { "loose": true }],
10+
"transform-es2015-object-super",
11+
"transform-es2015-shorthand-properties",
12+
["transform-es2015-computed-properties", { "loose": true }],
13+
["transform-es2015-for-of", { "loose": true }],
14+
"transform-es2015-sticky-regex",
15+
"transform-es2015-unicode-regex",
16+
"check-es2015-constants",
17+
["transform-es2015-spread", { "loose": true }],
18+
"transform-es2015-parameters",
19+
["transform-es2015-destructuring", { "loose": true }],
20+
"transform-es2015-block-scoping",
21+
["transform-es2015-modules-commonjs", { "loose": true }],
22+
"transform-object-rest-spread",
23+
"transform-react-jsx",
24+
"syntax-jsx"
525
]
626
}

package.json

+27-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"build:lib": "babel src --out-dir lib",
99
"build:umd": "cross-env NODE_ENV=development webpack src/index.js dist/react-redux.js",
1010
"build:umd:min": "cross-env NODE_ENV=production webpack src/index.js dist/react-redux.min.js",
11-
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
11+
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min && node ./prepublish",
1212
"clean": "rimraf lib dist coverage",
1313
"lint": "eslint src test",
1414
"prepublish": "npm run clean && npm run build",
15-
"test": "mocha --compilers js:babel-core/register --recursive --require ./test/setup.js",
15+
"test": "mocha --compilers js:babel-register --recursive --require ./test/setup.js",
1616
"test:watch": "npm test -- --watch",
1717
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive"
1818
},
@@ -47,15 +47,37 @@
4747
"babel-core": "^6.3.26",
4848
"babel-eslint": "^5.0.0-beta9",
4949
"babel-loader": "^6.2.0",
50+
"babel-plugin-check-es2015-constants": "^6.3.13",
51+
"babel-plugin-syntax-jsx": "^6.3.13",
5052
"babel-plugin-transform-decorators-legacy": "^1.2.0",
51-
"babel-preset-es2015-loose": "^6.1.4",
52-
"babel-preset-react": "^6.3.13",
53-
"babel-preset-stage-0": "^6.3.13",
53+
"babel-plugin-transform-es2015-arrow-functions": "^6.3.13",
54+
"babel-plugin-transform-es2015-block-scoped-functions": "^6.3.13",
55+
"babel-plugin-transform-es2015-block-scoping": "^6.3.13",
56+
"babel-plugin-transform-es2015-classes": "^6.3.13",
57+
"babel-plugin-transform-es2015-computed-properties": "^6.3.13",
58+
"babel-plugin-transform-es2015-destructuring": "^6.3.13",
59+
"babel-plugin-transform-es2015-for-of": "^6.3.13",
60+
"babel-plugin-transform-es2015-function-name": "^6.3.13",
61+
"babel-plugin-transform-es2015-literals": "^6.3.13",
62+
"babel-plugin-transform-es2015-modules-commonjs": "^6.3.13",
63+
"babel-plugin-transform-es2015-object-super": "^6.3.13",
64+
"babel-plugin-transform-es2015-parameters": "^6.3.13",
65+
"babel-plugin-transform-es2015-shorthand-properties": "^6.3.13",
66+
"babel-plugin-transform-es2015-spread": "^6.3.13",
67+
"babel-plugin-transform-es2015-sticky-regex": "^6.3.13",
68+
"babel-plugin-transform-es2015-template-literals": "^6.3.13",
69+
"babel-plugin-transform-es2015-unicode-regex": "^6.3.13",
70+
"babel-plugin-transform-object-rest-spread": "^6.3.13",
71+
"babel-plugin-transform-react-display-name": "^6.4.0",
72+
"babel-plugin-transform-react-jsx": "^6.4.0",
73+
"babel-register": "^6.3.13",
5474
"cross-env": "^1.0.7",
75+
"es3ify": "^0.2.0",
5576
"eslint": "^1.7.1",
5677
"eslint-config-rackt": "1.1.0",
5778
"eslint-plugin-react": "^3.6.3",
5879
"expect": "^1.8.0",
80+
"glob": "^6.0.4",
5981
"isparta": "4.0.0",
6082
"istanbul": "^0.3.17",
6183
"jsdom": "~5.4.3",

prepublish.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var glob = require('glob')
2+
var fs = require('fs')
3+
var es3ify = require('es3ify')
4+
5+
glob('./@(lib|dist)/**/*.js', function (err, files) {
6+
if (err) {
7+
throw err
8+
}
9+
10+
files.forEach(function (file) {
11+
fs.readFile(file, 'utf8', function (err, data) {
12+
if (err) {
13+
throw err
14+
}
15+
16+
fs.writeFile(file, es3ify.transform(data), function (err) {
17+
if (err) {
18+
throw err
19+
}
20+
21+
console.log('es3ified ' + file) // eslint-disable-line no-console
22+
})
23+
})
24+
})
25+
})

src/components/Provider.js

+20-26
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1-
const { Component, PropTypes, Children } = require('react')
2-
const storeShape = require('../utils/storeShape')
1+
import { Component, PropTypes, Children } from 'react'
2+
import storeShape from '../utils/storeShape'
33

4-
if (process.env.NODE_ENV !== 'production') {
5-
let didWarnAboutReceivingStore = false
6-
/* eslint-disable no-var */
7-
var warnAboutReceivingStore = function () {
8-
/* eslint-enable no-var */
9-
if (didWarnAboutReceivingStore) {
10-
return
11-
}
12-
didWarnAboutReceivingStore = true
13-
14-
/* eslint-disable no-console */
15-
if (typeof console !== 'undefined' && typeof console.error === 'function') {
16-
console.error(
17-
'<Provider> does not support changing `store` on the fly. ' +
18-
'It is most likely that you see this error because you updated to ' +
19-
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
20-
'automatically. See https://github.com/rackt/react-redux/releases/' +
21-
'tag/v2.0.0 for the migration instructions.'
22-
)
23-
}
24-
/* eslint-disable no-console */
4+
let didWarnAboutReceivingStore = false
5+
function warnAboutReceivingStore() {
6+
if (didWarnAboutReceivingStore) {
7+
return
258
}
9+
didWarnAboutReceivingStore = true
10+
11+
/* eslint-disable no-console */
12+
if (typeof console !== 'undefined' && typeof console.error === 'function') {
13+
console.error(
14+
'<Provider> does not support changing `store` on the fly. ' +
15+
'It is most likely that you see this error because you updated to ' +
16+
'Redux 2.x and React Redux 2.x which no longer hot reload reducers ' +
17+
'automatically. See https://github.com/rackt/react-redux/releases/' +
18+
'tag/v2.0.0 for the migration instructions.'
19+
)
20+
}
21+
/* eslint-disable no-console */
2622
}
2723

28-
class Provider extends Component {
24+
export default class Provider extends Component {
2925
getChildContext() {
3026
return { store: this.store }
3127
}
@@ -59,5 +55,3 @@ Provider.propTypes = {
5955
Provider.childContextTypes = {
6056
store: storeShape.isRequired
6157
}
62-
63-
module.exports = Provider

src/components/connect.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { Component, createElement } = require('react')
2-
const storeShape = require('../utils/storeShape')
3-
const shallowEqual = require('../utils/shallowEqual')
4-
const wrapActionCreators = require('../utils/wrapActionCreators')
5-
const isPlainObject = require('lodash/isPlainObject')
6-
const hoistStatics = require('hoist-non-react-statics')
7-
const invariant = require('invariant')
1+
import { Component, createElement } from 'react'
2+
import storeShape from '../utils/storeShape'
3+
import shallowEqual from '../utils/shallowEqual'
4+
import wrapActionCreators from '../utils/wrapActionCreators'
5+
import isPlainObject from 'lodash/isPlainObject'
6+
import hoistStatics from 'hoist-non-react-statics'
7+
import invariant from '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-
function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
24+
export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
2525
const shouldSubscribe = Boolean(mapStateToProps)
2626
const finalMapStateToProps = mapStateToProps || defaultMapStateToProps
2727
const finalMapDispatchToProps = isPlainObject(mapDispatchToProps) ?
@@ -130,7 +130,7 @@ function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {})
130130

131131
trySubscribe() {
132132
if (shouldSubscribe && !this.unsubscribe) {
133-
this.unsubscribe = this.store.subscribe(::this.handleChange)
133+
this.unsubscribe = this.store.subscribe(this.handleChange.bind(this))
134134
this.handleChange()
135135
}
136136
}
@@ -273,5 +273,3 @@ function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {})
273273
return hoistStatics(Connect, WrappedComponent)
274274
}
275275
}
276-
277-
module.exports = connect

src/index.js

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

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

src/utils/shallowEqual.js

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

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

src/utils/storeShape.js

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

3-
const storeShape = PropTypes.shape({
3+
export default 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

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { bindActionCreators } from 'redux'
22

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

0 commit comments

Comments
 (0)