Skip to content

Commit

Permalink
ref #133: chore: Use reduxConnectStore instead of store in the As…
Browse files Browse the repository at this point in the history
…yncConnect to avoid possible collisions
  • Loading branch information
ioanlucut committed Mar 6, 2019
1 parent 9a5e31e commit 5a72112
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion __tests__/redux-connect.spec.js
Expand Up @@ -15,7 +15,7 @@ import { setToImmutableStateFunc, setToMutableStateFunc } from '../modules/helpe

// import module
import { endGlobalLoad, beginGlobalLoad } from '../modules/store';
import AsyncConnectWithContext,{ AsyncConnect } from '../modules/components/AsyncConnect';
import AsyncConnectWithContext, { AsyncConnect } from '../modules/components/AsyncConnect';
import {
asyncConnect,
reducer as reduxAsyncConnect,
Expand Down
22 changes: 15 additions & 7 deletions modules/components/AsyncConnect.js
Expand Up @@ -17,7 +17,7 @@ export class AsyncConnect extends Component {
location: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
helpers: PropTypes.any,
store: PropTypes.object.isRequired,
reduxConnectStore: PropTypes.object.isRequired,
};

static defaultProps = {
Expand Down Expand Up @@ -66,13 +66,16 @@ export class AsyncConnect extends Component {
}

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

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

this.setState({ previousLocation: location });

Expand All @@ -86,7 +89,7 @@ export class AsyncConnect extends Component {
// loaded props last time and not the last called route
if (
this.loadDataCounter === loadDataCounterOriginal
&& this.mounted !== false
&& this.mounted !== false
) {
this.setState({ previousLocation: null });
}
Expand Down Expand Up @@ -119,7 +122,12 @@ const AsyncConnectWithContext = ({ context, ...otherProps }) => {

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

0 comments on commit 5a72112

Please sign in to comment.