Skip to content

Commit

Permalink
Use ES6 modules again with es3ify as a temporary fix against IE8
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Feb 2, 2016
1 parent 0eda221 commit 65a80f8
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 58 deletions.
26 changes: 23 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
{
"presets": ["es2015-loose", "stage-0", "react"],
"plugins": [
"transform-decorators-legacy"
plugins: [
"transform-decorators-legacy",
["transform-es2015-template-literals", { "loose": true }],
"transform-es2015-literals",
"transform-es2015-function-name",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
["transform-es2015-classes", { "loose": true }],
"transform-es2015-object-super",
"transform-es2015-shorthand-properties",
["transform-es2015-computed-properties", { "loose": true }],
["transform-es2015-for-of", { "loose": true }],
"transform-es2015-sticky-regex",
"transform-es2015-unicode-regex",
"check-es2015-constants",
["transform-es2015-spread", { "loose": true }],
"transform-es2015-parameters",
["transform-es2015-destructuring", { "loose": true }],
"transform-es2015-block-scoping",
["transform-es2015-modules-commonjs", { "loose": true }],
"transform-object-rest-spread",
"transform-react-jsx",
"syntax-jsx"
]
}
32 changes: 27 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"build:lib": "babel src --out-dir lib",
"build:umd": "cross-env NODE_ENV=development webpack src/index.js dist/react-redux.js",
"build:umd:min": "cross-env NODE_ENV=production webpack src/index.js dist/react-redux.min.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min && node ./prepublish",
"clean": "rimraf lib dist coverage",
"lint": "eslint src test",
"prepublish": "npm run clean && npm run build",
"test": "mocha --compilers js:babel-core/register --recursive --require ./test/setup.js",
"test": "mocha --compilers js:babel-register --recursive --require ./test/setup.js",
"test:watch": "npm test -- --watch",
"test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive"
},
Expand Down Expand Up @@ -47,15 +47,37 @@
"babel-core": "^6.3.26",
"babel-eslint": "^5.0.0-beta9",
"babel-loader": "^6.2.0",
"babel-plugin-check-es2015-constants": "^6.3.13",
"babel-plugin-syntax-jsx": "^6.3.13",
"babel-plugin-transform-decorators-legacy": "^1.2.0",
"babel-preset-es2015-loose": "^6.1.4",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-plugin-transform-es2015-arrow-functions": "^6.3.13",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.3.13",
"babel-plugin-transform-es2015-block-scoping": "^6.3.13",
"babel-plugin-transform-es2015-classes": "^6.3.13",
"babel-plugin-transform-es2015-computed-properties": "^6.3.13",
"babel-plugin-transform-es2015-destructuring": "^6.3.13",
"babel-plugin-transform-es2015-for-of": "^6.3.13",
"babel-plugin-transform-es2015-function-name": "^6.3.13",
"babel-plugin-transform-es2015-literals": "^6.3.13",
"babel-plugin-transform-es2015-modules-commonjs": "^6.3.13",
"babel-plugin-transform-es2015-object-super": "^6.3.13",
"babel-plugin-transform-es2015-parameters": "^6.3.13",
"babel-plugin-transform-es2015-shorthand-properties": "^6.3.13",
"babel-plugin-transform-es2015-spread": "^6.3.13",
"babel-plugin-transform-es2015-sticky-regex": "^6.3.13",
"babel-plugin-transform-es2015-template-literals": "^6.3.13",
"babel-plugin-transform-es2015-unicode-regex": "^6.3.13",
"babel-plugin-transform-object-rest-spread": "^6.3.13",
"babel-plugin-transform-react-display-name": "^6.4.0",
"babel-plugin-transform-react-jsx": "^6.4.0",
"babel-register": "^6.3.13",
"cross-env": "^1.0.7",
"es3ify": "^0.2.0",
"eslint": "^1.7.1",
"eslint-config-rackt": "1.1.0",
"eslint-plugin-react": "^3.6.3",
"expect": "^1.8.0",
"glob": "^6.0.4",
"isparta": "4.0.0",
"istanbul": "^0.3.17",
"jsdom": "~5.4.3",
Expand Down
25 changes: 25 additions & 0 deletions prepublish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var glob = require('glob')
var fs = require('fs')
var es3ify = require('es3ify')

glob('./@(lib|dist)/**/*.js', function (err, files) {
if (err) {
throw err
}

files.forEach(function (file) {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
throw err
}

fs.writeFile(file, es3ify.transform(data), function (err) {
if (err) {
throw err
}

console.log('es3ified ' + file) // eslint-disable-line no-console
})
})
})
})
46 changes: 20 additions & 26 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
const { Component, PropTypes, Children } = require('react')
const storeShape = require('../utils/storeShape')
import { Component, PropTypes, Children } from 'react'
import storeShape from '../utils/storeShape'

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(
'<Provider> 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 */
let didWarnAboutReceivingStore = false
function warnAboutReceivingStore() {
if (didWarnAboutReceivingStore) {
return
}
didWarnAboutReceivingStore = true

/* eslint-disable no-console */
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(
'<Provider> 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 */
}

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

module.exports = Provider
20 changes: 9 additions & 11 deletions src/components/connect.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { Component, createElement } = require('react')
const storeShape = require('../utils/storeShape')
const shallowEqual = require('../utils/shallowEqual')
const wrapActionCreators = require('../utils/wrapActionCreators')
const isPlainObject = require('lodash/isPlainObject')
const hoistStatics = require('hoist-non-react-statics')
const invariant = require('invariant')
import { Component, createElement } from 'react'
import storeShape from '../utils/storeShape'
import shallowEqual from '../utils/shallowEqual'
import wrapActionCreators from '../utils/wrapActionCreators'
import isPlainObject from 'lodash/isPlainObject'
import hoistStatics from 'hoist-non-react-statics'
import invariant from '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

function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
export default function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
const shouldSubscribe = Boolean(mapStateToProps)
const finalMapStateToProps = mapStateToProps || defaultMapStateToProps
const finalMapDispatchToProps = isPlainObject(mapDispatchToProps) ?
Expand Down Expand Up @@ -130,7 +130,7 @@ function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {})

trySubscribe() {
if (shouldSubscribe && !this.unsubscribe) {
this.unsubscribe = this.store.subscribe(::this.handleChange)
this.unsubscribe = this.store.subscribe(this.handleChange.bind(this))
this.handleChange()
}
}
Expand Down Expand Up @@ -273,5 +273,3 @@ function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {})
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 @@
const Provider = require('./components/Provider')
const connect = require('./components/connect')
import Provider from './components/Provider'
import connect from './components/connect'

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

return true
}

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

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

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

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

module.exports = wrapActionCreators

5 comments on commit 65a80f8

@jdalton
Copy link

@jdalton jdalton commented on 65a80f8 Feb 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about?

Ah, to enable loose mode https://twitter.com/dan_abramov/status/694512168788692992 (thread).

@jdalton
Copy link

@jdalton jdalton commented on 65a80f8 Feb 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon
Copy link
Contributor Author

@gaearon gaearon commented on 65a80f8 Feb 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdalton Unfortunately they are broken: https://phabricator.babeljs.io/T2817

@jdalton
Copy link

@jdalton jdalton commented on 65a80f8 Feb 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broke since Nov. @thejameskyle

@sirugh
Copy link

@sirugh sirugh commented on 65a80f8 Feb 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.