Skip to content

Commit

Permalink
Merge pull request #59 from abarriel/develop
Browse files Browse the repository at this point in the history
Fix deprecation warnings - Update to React 15.6.2
  • Loading branch information
Clément Fiorio authored Sep 28, 2017
2 parents 6c55119 + 5bf58ce commit a118f54
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 82 deletions.
11 changes: 6 additions & 5 deletions lib/__tests__/fixtures/components/User.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React from 'react';

import { deps } from '../../../';
Expand All @@ -11,11 +12,11 @@ export default deps(({ userId }) => ({
static displayName = 'User';

static propTypes = {
deleteUser: React.PropTypes.func,
rank: React.PropTypes.string,
updateUser: React.PropTypes.func,
userId: React.PropTypes.number,
userName: React.PropTypes.string,
deleteUser: PropTypes.func,
rank: PropTypes.string,
updateUser: PropTypes.func,
userId: PropTypes.number,
userName: PropTypes.string,
};

constructor(props) {
Expand Down
15 changes: 8 additions & 7 deletions lib/__tests__/fixtures/components/Users.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React from 'react';

import { deps, Store } from '../../../';
Expand All @@ -17,14 +18,14 @@ export default deps(() => ({
static displayName = 'Users';

static propTypes = {
createUser: React.PropTypes.func,
createUser: PropTypes.func,
optionalStore: Store.State.propType(React.any),
toggleUsersVisibility: React.PropTypes.func,
uiUsersVisibility: Store.State.propType(React.PropTypes.bool.isRequired).isRequired,
users: Store.State.propType(React.PropTypes.arrayOf(React.PropTypes.shape({
userId: React.PropTypes.number.isRequired,
userName: React.PropTypes.string.isRequired,
rank: React.PropTypes.string.isRequired,
toggleUsersVisibility: PropTypes.func,
uiUsersVisibility: Store.State.propType(PropTypes.bool.isRequired).isRequired,
users: Store.State.propType(PropTypes.arrayOf(PropTypes.shape({
userId: PropTypes.number.isRequired,
userName: PropTypes.string.isRequired,
rank: PropTypes.string.isRequired,
}))).isRequired,
};

Expand Down
5 changes: 3 additions & 2 deletions lib/__tests__/node/components.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component, PropTypes as T } from 'react';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import stores from '../../stores';
import Store from '../../Store';
import MemoryStore from '../../MemoryStore';
Expand All @@ -18,7 +19,7 @@ describe('stores', () => {
class Bar extends Component {
static displayName = 'Bar';
static propTypes = {
foo: Store.State.propType(T.string),
foo: Store.State.propType(PropTypes.string),
};
render() {
const { foo } = this.props;
Expand Down
13 changes: 11 additions & 2 deletions lib/__tests__/node/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Promise from 'bluebird';
import HTTPStatus from 'http-status-codes';
import _ from 'lodash';
import nock from 'nock';
import PropTypes from 'prop-types';
import React from 'react';
import ReactDOMServer from 'react-dom/server';
import should from 'should/as-function';
Expand Down Expand Up @@ -91,7 +92,15 @@ describe('prepare', () => {
should(prepareInner).have.property('calledOnce').which.is.exactly(true);
});
});

it('prepares stateless components correctly', async function test() {
const StatelessComponent = () => null;
StatelessComponent[preparable.$prepare] = async function preps(props, context) {
context.bar = await Promise.resolve('foo');
};
const context = {};
return await prepare(<StatelessComponent />, context)
.then(() => should(context).have.property('bar').which.is.exactly('foo'));
});
it('doesn’t fetch the same HTTPStore more than once', async function test() {
const testHttpConf = {
protocol: 'http',
Expand All @@ -112,7 +121,7 @@ describe('prepare', () => {
@stores(getStoreDeps)
class Child extends React.Component {
static propTypes = {
testStore: React.PropTypes.object,
testStore: PropTypes.object,
};
render() {
return <span>{this.props.testStore.value.message}</span>;
Expand Down
7 changes: 4 additions & 3 deletions lib/actions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import PropTypes from 'prop-types';
import React from 'react';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import _ from 'lodash';
const __DEV__ = process && process.env && process.env.NODE_ENV === 'development';

import Flux from './Flux';
import defaultFluxKey from './defaultFluxKey';
import shouldPureComponentUpdate from './util/shouldPureComponentUpdate';

/**
* Enhance a React Component and make context's {@link Flux}'s {@link Actions}s requested by bindings avaliable as props.
Expand All @@ -18,7 +19,7 @@ import defaultFluxKey from './defaultFluxKey';
function actions(getBindings, {
displayName = void 0,
fluxKey = defaultFluxKey,
shouldNexusComponentUpdate = PureRenderMixin.shouldComponentUpdate,
shouldNexusComponentUpdate = shouldPureComponentUpdate,
} = {}) {
return (Component) => {
/**
Expand All @@ -28,7 +29,7 @@ function actions(getBindings, {
static displayName = displayName || `@actions(${Component.displayName})`;

static contextTypes = {
[fluxKey]: React.PropTypes.instanceOf(Flux),
[fluxKey]: PropTypes.instanceOf(Flux),
};

/**
Expand Down
6 changes: 2 additions & 4 deletions lib/preparable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React from 'react';

import isExtensionOf from './util/isExtensionOf';
import isReactComponent from './util/isReactComponent';
const $prepare = Symbol('preparable');

/**
Expand All @@ -14,7 +12,7 @@ function preparable(prepare) {
throw new TypeError('@preparable() should be passed an async function');
}
return function extendComponent(Component) {
if(!isExtensionOf(Component, React.Component)) {
if(!isReactComponent(Component)) {
throw new TypeError('@preparable should only be applied to React Components');
}
return class extends Component {
Expand Down
6 changes: 3 additions & 3 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Promise from 'bluebird';
import React from 'react';
import _ from 'lodash';

import isExtensionOf from './util/isExtensionOf';
import isReactComponent from './util/isReactComponent';
import preparable from './preparable';
const { $prepare } = preparable;

Expand Down Expand Up @@ -81,12 +81,12 @@ async function prepareElement(element, context) {
if(typeof type === 'string') {
return [props.children, context];
}
await satisfy(element, context);
// Function component (new in react 0.14.x)
if(!isExtensionOf(type, React.Component)) {
if(!isReactComponent(type)) {
return [type(props), context];
}
// Composite element
await satisfy(element, context);
let inst = null;
try {
inst = create(type, props, context);
Expand Down
5 changes: 3 additions & 2 deletions lib/root.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PropTypes from 'prop-types';
import React from 'react';

import Flux from './Flux';
Expand All @@ -20,11 +21,11 @@ function root({ fluxKey = defaultFluxKey, displayName = void 0 } = {}) {
static displayName = displayName || `@root(${Component.displayName})`;

static propTypes = {
flux: React.PropTypes.instanceOf(Flux),
flux: PropTypes.instanceOf(Flux),
};

static childContextTypes = {
[fluxKey]: React.PropTypes.instanceOf(Flux),
[fluxKey]: PropTypes.instanceOf(Flux),
};

getChildContext() {
Expand Down
7 changes: 4 additions & 3 deletions lib/stores.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Promise from 'bluebird';
import PropTypes from 'prop-types';
import React from 'react';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import _ from 'lodash';
import deepEqual from 'deep-equal';
const __DEV__ = process && process.env && process.NODE_ENV === 'development';
Expand All @@ -9,6 +9,7 @@ import defaultFluxKey from './defaultFluxKey';
import diff from './util/diff';
import Flux from './Flux';
import preparable from './preparable';
import shouldPureComponentUpdate from './util/shouldPureComponentUpdate';

/**
* Enhance a React Component and make context's {@link Flux}'s {@link Store}'s {@link State}s requested by bindings
Expand All @@ -24,7 +25,7 @@ function stores(
getBindings, {
displayName = void 0,
fluxKey = defaultFluxKey,
shouldNexusComponentUpdate = PureRenderMixin.shouldComponentUpdate,
shouldNexusComponentUpdate = shouldPureComponentUpdate,
} = {}) {
return (Component) => preparable(async function prepare(props, context) {
const flux = context[fluxKey];
Expand All @@ -46,7 +47,7 @@ function stores(
static displayName = displayName || `@stores(${Component.displayName})`;

static contextTypes = {
[fluxKey]: React.PropTypes.instanceOf(Flux),
[fluxKey]: PropTypes.instanceOf(Flux),
};

/**
Expand Down
22 changes: 0 additions & 22 deletions lib/util/__tests__/isExtensionOf.js

This file was deleted.

27 changes: 27 additions & 0 deletions lib/util/__tests__/isReactComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import isReactComponent from '../isReactComponent';
import should from 'should/as-function';
const { describe, it } = global;

describe('isReactComponent(type)', () => {
it('returns true on React.Component', () => {
class C extends React.Component {
render() {
return null;
}
}
should(isReactComponent(C)).be.true();
});
it('returns true on React.PureComponent', () => {
class C extends React.PureComponent {
render() {
return null;
}
}
should(isReactComponent(C)).be.true();
});
it('returns false on a functional component', () => {
const C = () => (<div>{'foo'}</div>);
should(isReactComponent(C)).be.false();
});
});
22 changes: 0 additions & 22 deletions lib/util/isExtensionOf.js

This file was deleted.

6 changes: 6 additions & 0 deletions lib/util/isReactComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function isReactCompositeComponent(component) {
if(typeof component.prototype === 'object' && component.prototype.isReactComponent) {
return true;
}
return false;
}
7 changes: 7 additions & 0 deletions lib/util/shouldPureComponentUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import shallowEqual from 'shallowequal';

function shouldPureComponentUpdate(nextProps, nextState) {
return (!shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState));
}

export default shouldPureComponentUpdate;
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@
"koa-router": "^5.3.0",
"mocha": "^2.3.4",
"nock": "^8.0.0",
"react": "^15.3.0",
"react-addons-pure-render-mixin": "^15.3.0",
"react-addons-test-utils": "^15.3.0",
"react-dom": "^15.3.0",
"prop-types": "^15.6.0",
"react": "^15.6.2",
"react-dom": "^15.6.2",
"react-test-renderer": "^16.0.0",
"rimraf": "^2.5.0",
"run-sequence": "^1.1.5",
"selenium-standalone": "^4.9.0",
Expand All @@ -125,10 +125,10 @@
"lodash": "^4.0.0",
"path-to-regexp": "^1.2.1",
"setimmediate": "^1.0.4",
"should": "^8.1.1"
"shallowequal": "^1.0.2"
},
"peerDependencies": {
"react": "^15.3.0",
"react-dom": "^15.3.0"
"react": "^15.6.2",
"react-dom": "^15.6.2"
}
}

0 comments on commit a118f54

Please sign in to comment.