Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CommonJS modules until ES3 transforms are fixed #233

Merged
merged 2 commits into from
Dec 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
},
"homepage": "https://github.com/gaearon/react-redux",
"devDependencies": {
"babel-cli": "^6.3.15",
"babel-core": "^6.1.20",
"babel-cli": "^6.3.17",
"babel-core": "^6.3.26",
"babel-eslint": "^5.0.0-beta4",
"babel-loader": "^6.2.0",
"babel-plugin-transform-decorators-legacy": "^1.2.0",
"babel-preset-es2015-loose": "^6.1.3",
"babel-preset-es2015-loose": "^6.1.4",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"eslint": "^1.7.1",
Expand Down
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