Skip to content

Commit

Permalink
chore: merge branch 'ioanlucut-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Mar 10, 2019
2 parents bb7e64f + 72d45b2 commit 31bb37d
Show file tree
Hide file tree
Showing 9 changed files with 2,315 additions and 1,953 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "9"
- "8"
- "10"
- "8"
13 changes: 6 additions & 7 deletions __tests__/redux-connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Provider, connect } from 'react-redux';
import withRouter from 'react-router/withRouter';
import StaticRouter from 'react-router/StaticRouter';
import MemoryRouter from 'react-router/MemoryRouter';
import renderRoutes from 'react-router-config/renderRoutes';
import { renderRoutes } from 'react-router-config';
import { createStore, combineReducers } from 'redux';
import { combineReducers as combineImmutableReducers } from 'redux-immutable';
import { spy } from 'sinon';
Expand All @@ -15,7 +15,7 @@ import { setToImmutableStateFunc, setToMutableStateFunc } from '../modules/helpe

// import module
import { endGlobalLoad, beginGlobalLoad } from '../modules/store';
import { AsyncConnect } from '../modules/components/AsyncConnect';
import AsyncConnectWithContext, { AsyncConnect } from '../modules/components/AsyncConnect';
import {
asyncConnect,
reducer as reduxAsyncConnect,
Expand All @@ -36,7 +36,7 @@ describe('<ReduxAsyncConnect />', function suite() {
const ReduxAsyncConnect = withRouter(connect(null, {
beginGlobalLoad: beginGlobalLoadSpy,
endGlobalLoad: endGlobalLoadSpy,
})(AsyncConnect));
})(AsyncConnectWithContext));

/* eslint-disable no-unused-vars */
const App = ({
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('<ReduxAsyncConnect />', function suite() {

it('properly picks data up from the server', function test() {
const store = createStore(reducers, testState);
const proto = ReduxAsyncConnect.WrappedComponent.prototype;
const proto = AsyncConnect.prototype;
const eat = spy(() => 'yammi');

spy(proto, 'loadAsyncData');
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('<ReduxAsyncConnect />', function suite() {
it('loads data on client side when it wasn\'t provided by server', function test() {
const store = createStore(reducers);
const eat = spy(() => 'yammi');
const proto = ReduxAsyncConnect.WrappedComponent.prototype;
const proto = AsyncConnect.prototype;

spy(proto, 'loadAsyncData');
spy(proto, 'componentDidMount');
Expand Down Expand Up @@ -265,7 +265,7 @@ describe('<ReduxAsyncConnect />', function suite() {
it('supports extended connect signature', function test() {
const store = createStore(reducers, initialState);
const eat = spy(() => 'yammi');
const proto = ReduxAsyncConnect.WrappedComponent.prototype;
const proto = AsyncConnect.prototype;

spy(proto, 'loadAsyncData');
spy(proto, 'componentDidMount');
Expand Down Expand Up @@ -302,7 +302,6 @@ describe('<ReduxAsyncConnect />', function suite() {
});
});


it('renders even when no component is connected', function test() {
const store = createStore(reducers);
const eat = spy(() => 'yammi');
Expand Down
2 changes: 1 addition & 1 deletion examples/api-redirect-err/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Link from 'react-router-dom/Link';
import renderRoutes from 'react-router-config/renderRoutes';
import { renderRoutes } from 'react-router-config';

import './App.css';

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Link from 'react-router-dom/Link';
import renderRoutes from 'react-router-config/renderRoutes';
import { renderRoutes } from 'react-router-config';
import './App.css';

function App({ route }) {
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/src/components/Wrapped.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import Link from 'react-router-dom/Link';
import renderRoutes from 'react-router-config/renderRoutes';
import { renderRoutes } from 'react-router-config';

function Wrapped({ route, lunch }) {
return (
Expand Down
55 changes: 40 additions & 15 deletions modules/components/AsyncConnect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable react/forbid-prop-types,react/no-unused-prop-types,react/require-default-props */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Route } from 'react-router';
import { renderRoutes } from 'react-router-config';
import { ReactReduxContext } from 'react-redux';
import { loadAsyncConnect } from '../helpers/utils';
import { getMutableState } from '../helpers/state';

Expand All @@ -11,16 +13,11 @@ export class AsyncConnect extends Component {
beginGlobalLoad: PropTypes.func.isRequired,
endGlobalLoad: PropTypes.func.isRequired,
reloadOnPropsChange: PropTypes.func,
/* eslint-disable react/forbid-prop-types, react/no-unused-prop-types */
routes: PropTypes.array.isRequired,
location: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
helpers: PropTypes.any,
/* eslint-enable */
};

static contextTypes = {
store: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
reduxConnectStore: PropTypes.object.isRequired,
};

static defaultProps = {
Expand All @@ -33,8 +30,8 @@ export class AsyncConnect extends Component {
},
};

constructor(props, context) {
super(props, context);
constructor(props) {
super(props);

this.state = {
previousLocation: this.isLoaded() ? null : props.location,
Expand Down Expand Up @@ -69,14 +66,16 @@ export class AsyncConnect extends Component {
}

isLoaded() {
const { store } = this.context;
return getMutableState(store.getState()).reduxAsyncConnect.loaded;
const { reduxConnectStore } = this.props;
return getMutableState(reduxConnectStore.getState()).reduxAsyncConnect.loaded;
}

loadAsyncData(props) {
const { store } = this.context;
loadAsyncData({ reduxConnectStore, ...otherProps }) {
const { location, beginGlobalLoad, endGlobalLoad } = this.props;
const loadResult = loadAsyncConnect({ ...props, store });
const loadResult = loadAsyncConnect({
...otherProps,
store: reduxConnectStore,
});

this.setState({ previousLocation: location });

Expand All @@ -88,7 +87,10 @@ export class AsyncConnect extends Component {
// is the last invocation of loadAsyncData method. Otherwise we can face a situation
// when user is changing route several times and we finally show him route that has
// loaded props last time and not the last called route
if (this.loadDataCounter === loadDataCounterOriginal && this.mounted !== false) {
if (
this.loadDataCounter === loadDataCounterOriginal
&& this.mounted !== false
) {
this.setState({ previousLocation: null });
}

Expand All @@ -111,4 +113,27 @@ export class AsyncConnect extends Component {
}
}

export default AsyncConnect;
const AsyncConnectWithContext = ({ context, ...otherProps }) => {
const Context = context || ReactReduxContext;

if (Context == null) {
throw new Error('Please upgrade to react-redux v6');
}

return (
<Context.Consumer>
{({ store: reduxConnectStore }) => (
<AsyncConnect
reduxConnectStore={reduxConnectStore}
{...otherProps}
/>
)}
</Context.Consumer>
);
};

AsyncConnectWithContext.propTypes = {
context: PropTypes.object,
};

export default AsyncConnectWithContext;
7 changes: 5 additions & 2 deletions modules/containers/AsyncConnect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import { AsyncConnect } from '../components/AsyncConnect';
import AsyncConnectWithContext from '../components/AsyncConnect';
import { beginGlobalLoad, endGlobalLoad } from '../store';

export default withRouter(connect(null, { beginGlobalLoad, endGlobalLoad })(AsyncConnect));
export default withRouter(connect(null, {
beginGlobalLoad,
endGlobalLoad,
})(AsyncConnectWithContext));
73 changes: 35 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,54 @@
},
"homepage": "https://github.com/makeomatic/redux-connect",
"peerDependencies": {
"prop-types": "15.x.x || 16.x.x",
"prop-types": "16.x.x",
"react": "16.x.x",
"react-redux": "5.x.x",
"react-redux": "6.x.x",
"react-router": "4.x.x",
"react-router-config": "1.x.x || ^1.0.0-beta"
"react-router-config": "1.x.x || ^1.0.0-beta || ^4.4.0-beta.6",
"react-router-dom": "^4.3.1",
"redux-actions": "2.x.x"
},
"devDependencies": {
"@babel/cli": "^7.0.0-beta.55",
"@babel/core": "^7.0.0-beta.55",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.55",
"@babel/plugin-proposal-export-default-from": "^7.0.0-beta.55",
"@babel/preset-env": "^7.0.0-beta.55",
"@babel/preset-react": "^7.0.0-beta.55",
"@babel/cli": "^7.2.3",
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-class-properties": "^7.3.4",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^8.2.6",
"babel-jest": "^23.4.2",
"babel-plugin-transform-react-remove-prop-types": "^0.4.13",
"bluebird": "^3.5.1",
"babel-eslint": "^10.0.1",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"bluebird": "^3.5.3",
"cross-env": "^5.2.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^5.2.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-jsx-a11y": "6.1.1",
"eslint-plugin-react": "^7.10.0",
"immutable": "^3.8.1",
"jest": "^23.4.2",
"prop-types": "^15.6.2",
"raf": "^3.3.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-redux": "^5.0.7",
"enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.10.0",
"eslint": "^5.15.1",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "^7.12.4",
"immutable": "^3.8.2",
"jest": "^24.3.1",
"prop-types": "^15.7.2",
"raf": "^3.4.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-redux": "^6.0.1",
"react-router": "4.3.1",
"react-router-config": "^1.0.0 || ^1.0.0-beta",
"react-test-renderer": "^16.4.2",
"redux": "^4.0.0",
"react-router-config": "^4.4.0-beta.6",
"react-router-dom": "^4.3.1",
"react-test-renderer": "^16.8.4",
"redux": "^4.0.1",
"redux-actions": "^2.6.5",
"redux-immutable": "^4.0.0",
"regenerator-runtime": "^0.12.0",
"sinon": "^6.1.4"
},
"dependencies": {
"redux-actions": "^2.6.1"
"regenerator-runtime": "^0.13.1",
"sinon": "^7.2.7"
},
"jest": {
"automock": false,
"testEnvironment": "jsdom",
"testURL": "http://localhost",
"transform": {
".*": "<rootDir>/node_modules/babel-jest"
},
"setupFiles": [
"raf/polyfill"
]
Expand Down
Loading

0 comments on commit 31bb37d

Please sign in to comment.