diff --git a/.babelrc b/.babelrc index 09bc2e93c..735385d1b 100644 --- a/.babelrc +++ b/.babelrc @@ -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" ] } diff --git a/package.json b/package.json index 1430c42e6..f87dbaf8a 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", diff --git a/prepublish.js b/prepublish.js new file mode 100644 index 000000000..c614e538e --- /dev/null +++ b/prepublish.js @@ -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 + }) + }) + }) +}) diff --git a/src/components/Provider.js b/src/components/Provider.js index 2a5bf4178..51f6f7670 100644 --- a/src/components/Provider.js +++ b/src/components/Provider.js @@ -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( - ' 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( + ' 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 } } @@ -59,5 +55,3 @@ Provider.propTypes = { Provider.childContextTypes = { store: storeShape.isRequired } - -module.exports = Provider diff --git a/src/components/connect.js b/src/components/connect.js index 33726bf61..02510299b 100644 --- a/src/components/connect.js +++ b/src/components/connect.js @@ -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 }) @@ -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) ? @@ -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() } } @@ -273,5 +273,3 @@ function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) return hoistStatics(Connect, WrappedComponent) } } - -module.exports = connect diff --git a/src/index.js b/src/index.js index 65a2e6c4a..ad89eec2d 100644 --- a/src/index.js +++ b/src/index.js @@ -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 } diff --git a/src/utils/shallowEqual.js b/src/utils/shallowEqual.js index e10c4ae52..76df37841 100644 --- a/src/utils/shallowEqual.js +++ b/src/utils/shallowEqual.js @@ -1,4 +1,4 @@ -function shallowEqual(objA, objB) { +export default function shallowEqual(objA, objB) { if (objA === objB) { return true } @@ -21,5 +21,3 @@ function shallowEqual(objA, objB) { return true } - -module.exports = shallowEqual diff --git a/src/utils/storeShape.js b/src/utils/storeShape.js index c28b20d9e..16b1b141a 100644 --- a/src/utils/storeShape.js +++ b/src/utils/storeShape.js @@ -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 diff --git a/src/utils/wrapActionCreators.js b/src/utils/wrapActionCreators.js index ad4f48947..349e03d0f 100644 --- a/src/utils/wrapActionCreators.js +++ b/src/utils/wrapActionCreators.js @@ -1,7 +1,5 @@ import { bindActionCreators } from 'redux' -function wrapActionCreators(actionCreators) { +export default function wrapActionCreators(actionCreators) { return dispatch => bindActionCreators(actionCreators, dispatch) } - -module.exports = wrapActionCreators