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

Create a redistributable bundle #256

Closed
Closed
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
14 changes: 10 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"presets": ["es2015-loose", "stage-0", "react"],
"plugins": [
"transform-decorators-legacy"
]
"env": {
"development": {
"presets": ["es2015-loose", "stage-0", "react"],
"plugins": ["transform-decorators-legacy"]
},
"buildmodule": {
"presets": ["es2015-loose-rollup", "stage-0", "react"],
"plugins": ["transform-decorators-legacy"]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ npm-debug.log
.DS_Store
dist
lib
mod
coverage
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "4.0.6",
"description": "Official React bindings for Redux",
"main": "./lib/index.js",
"jsnext:main": "./src/index.js",
"jsnext:main": "./mod/index.js",
"scripts": {
"build:lib": "babel src --out-dir lib",
"build:mod": "BABEL_ENV=buildmodule babel src --out-dir mod",
"build:umd": "webpack src/index.js dist/react-redux.js --config webpack.config.development.js",
"build:umd:min": "webpack src/index.js dist/react-redux.min.js --config webpack.config.production.js",
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
"clean": "rimraf lib dist coverage",
"build": "npm run build:lib && npm run build:mod && npm run build:umd && npm run build:umd:min",
"clean": "rimraf lib mod 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",
Expand All @@ -23,7 +24,7 @@
"files": [
"dist",
"lib",
"src"
"mod"
],
"keywords": [
"react",
Expand All @@ -49,6 +50,7 @@
"babel-loader": "^6.2.0",
"babel-plugin-transform-decorators-legacy": "^1.2.0",
"babel-preset-es2015-loose": "^6.1.4",
"babel-preset-es2015-loose-rollup": "^7.0.0",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"eslint": "^1.7.1",
Expand Down
8 changes: 3 additions & 5 deletions src/components/Provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Component, PropTypes, Children } = require('react')
const storeShape = require('../utils/storeShape')
import { Component, PropTypes, Children } from 'react'
import storeShape from '../utils/storeShape'

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

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

module.exports = Provider
18 changes: 8 additions & 10 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 isPlainObject = require('../utils/isPlainObject')
const wrapActionCreators = require('../utils/wrapActionCreators')
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 isPlainObject from '../utils/isPlainObject'
import wrapActionCreators from '../utils/wrapActionCreators'
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 @@ -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/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.
*/
function isPlainObject(obj) {
export default function isPlainObject(obj) {
if (!obj || typeof obj !== 'object') {
return false
}
Expand All @@ -23,5 +23,3 @@ function isPlainObject(obj) {
&& constructor instanceof constructor
&& fnToString(constructor) === fnToString(Object)
}

module.exports = isPlainObject
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