Skip to content
This repository has been archived by the owner on Nov 26, 2018. It is now read-only.

Commit

Permalink
feat: compatibility with react 15.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Apr 23, 2017
1 parent 1a253ae commit 0c4fa14
Show file tree
Hide file tree
Showing 14 changed files with 512 additions and 559 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.1
7.9
45 changes: 24 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,47 @@
"recompose"
],
"peerDependencies": {
"react": "^15.3.2"
"prop-types": "^15.5.8",
"react": "^15.5.4"
},
"dependencies": {
"fbjs": "^0.8.9",
"fbjs": "^0.8.12",
"hoist-non-react-statics": "^1.2.0",
"object.omit": "^2.0.1",
"object.pick": "^1.2.0",
"react-test-renderer": "^15.5.4",
"symbol-observable": "^1.0.4"
},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-eslint": "^7.1.0",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-jest": "^19.0.0",
"babel-loader": "^6.4.1",
"babel-preset-latest": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-0": "^6.22.0",
"benchmark": "^2.1.2",
"babel-loader": "^7.0.0",
"babel-preset-latest": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"benchmark": "^2.1.4",
"create-react-class": "^15.5.2",
"docdown": "neoziro/docdown#multiple-files-support",
"enzyme": "^2.7.1",
"eslint": "^3.17.1",
"enzyme": "^2.8.2",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.0",
"eslint-plugin-react": "^6.10.3",
"fs-extra": "^2.1.2",
"html-webpack-plugin": "^2.28.0",
"jest": "^19.0.2",
"jsdom": "^9.12.0",
"microtime": "^2.1.2",
"react": "^15.3.2",
"react-addons-test-utils": "^15.3.2",
"react-dom": "^15.3.2",
"microtime": "^2.1.3",
"prop-types": "^15.5.8",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"reassemble": "^0.5.6",
"recompose": "^0.22.0",
"rxjs": "^5.2.0",
"sinon": "^2.0.0",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.2"
"recompose": "^0.23.1",
"rxjs": "^5.3.0",
"sinon": "^2.1.0",
"webpack": "^2.4.1",
"webpack-dev-server": "^2.4.3"
}
}
3 changes: 2 additions & 1 deletion src/__tests__/getContext.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { mount } from 'enzyme'
import { Dummy } from './utils'
import { compose, getContext } from '../'
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/isClassComponent.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable react/prefer-stateless-function, react/no-multi-comp, react/prefer-es6-class */
import React, { Component } from 'react'
import createReactClass from 'create-react-class'
import { isClassComponent } from '../'

describe('isClassComponent', () => {
Expand All @@ -16,7 +17,7 @@ describe('isClassComponent', () => {
}
}

const Bar = React.createClass({
const Bar = createReactClass({
render() {
return <div />
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import PropTypes from 'prop-types'
/* eslint-disable react/no-multi-comp, react/prefer-stateless-function,
react/prefer-es6-class, react/forbid-prop-types */
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import createReactClass from 'create-react-class'
import isReferentiallyTransparentFunctionComponent
from '../isReferentiallyTransparentFunctionComponent'

Expand All @@ -16,7 +18,7 @@ describe('isReferentiallyTransparentFunctionComponent', () => {
}
}

const Bar = React.createClass({
const Bar = createReactClass({
render() {
return <div />
},
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/onlyUpdateForPropTypes.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react'
import PropTypes from 'prop-types'
import React from 'react'
import { mount, shallow } from 'enzyme'
import { Dummy } from './utils'
import { compose, onlyUpdateForPropTypes, setPropTypes, withProps, withState } from '../'
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/setConfig.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { mount } from 'enzyme'
import Rx from 'rxjs'
import { setConfig, withObs } from '../'
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/setPropTypes.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react'
import PropTypes from 'prop-types'
import React from 'react'
import { setPropTypes } from '../'

describe('setPropTypes', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/setStatic.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react'
import PropTypes from 'prop-types'
import React from 'react'
import { setStatic } from '../'

describe('setStatic', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/toClass.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types'
/* eslint-disable react/prefer-stateless-function, react/no-multi-comp, no-class-assign */
import React, { PropTypes } from 'react'
import React from 'react'
import { mount } from 'enzyme'
import { Dummy } from './utils'
import { compose, toClass, withContext } from '../'
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/withContext.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { mount } from 'enzyme'
import { Dummy } from './utils'
import { compose, getContext, mapProps, withContext } from '../'
Expand Down
44 changes: 34 additions & 10 deletions src/lifecycle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { createClass } from 'react'
import { Component } from 'react'
import createEagerFactory from './createEagerFactory'
import createHelper from './createHelper'

const LIFECYCLE_METHODS = [
'componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'componentDidUpdate',
'componentWillUnmount',
]

/**
* A higher-order component version of
* [`React.createClass()`](https://facebook.github.io/react/docs/react-api.html#createclass).
* It supports the entire `createClass()` API, except the `render()` method,
* which is implemented by default (and overridden if specified; an error will
* be logged to the console). You should use this helper as an escape hatch, in
* A higher-order component that permits to hook a lifecycle method. Available methods are:
* - componentWillMount
* - componentDidMount
* - componentWillReceiveProps
* - shouldComponentUpdate
* - componentWillUpdate
* - componentDidUpdate
* - componentWillUnmount
* You should use this helper as an escape hatch, in
* case you need to access component lifecycle methods.
*
* @static
Expand All @@ -34,17 +48,27 @@ const lifecycle = spec => (BaseComponent) => {
/* eslint-enable no-console */
}

const implementation = {
...spec,

class Lifecycle extends Component {
render() {
return factory({
...this.props,
...this.state,
})
},
}
}

return createClass(implementation)
Object.entries(spec).forEach(([name, impl]) => {
if (!LIFECYCLE_METHODS.includes(name)) {
/* eslint-disable no-console */
console.error(`lifecycle() does not support "${name}" method, only lifecycle methods are supported.`)
/* eslint-enable no-console */
} else {
Lifecycle.prototype[name] = impl
}
})

return Lifecycle
}

export default createHelper(lifecycle, 'lifecycle')
3 changes: 2 additions & 1 deletion src/utils/createHOCFromMapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-console */
import { Component, PropTypes } from 'react'
import { Component } from 'react'
import PropTypes from 'prop-types'
import createBehaviorSubject from './createBehaviorSubject'
import createSymbol from './createSymbol'
import asyncThrow from './asyncThrow'
Expand Down

0 comments on commit 0c4fa14

Please sign in to comment.