Skip to content

Commit

Permalink
Upgraded to connected-react-router
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdh committed Nov 3, 2018
1 parent c789814 commit b29b2c2
Show file tree
Hide file tree
Showing 56 changed files with 55 additions and 1,517 deletions.
8 changes: 4 additions & 4 deletions app/app.js
Expand Up @@ -12,9 +12,10 @@ import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { ConnectedRouter, push } from 'react-router-redux';
import Immutable from 'immutable';
import { ConnectedRouter, push } from 'connected-react-router/immutable';
import FontFaceObserver from 'fontfaceobserver';
import createHistory from 'history/createBrowserHistory';
import history from 'utils/history';
import 'sanitize.css/sanitize.css';
import axios from 'axios';

Expand Down Expand Up @@ -48,8 +49,7 @@ openSansObserver.load().then(() => {
});

// Create redux store with history
const initialState = {};
const history = createHistory();
const initialState = Immutable.Map();
const store = configureStore(initialState, history);
const MOUNT_NODE = document.getElementById('app');

Expand Down
8 changes: 2 additions & 6 deletions app/configureStore.js
Expand Up @@ -4,7 +4,7 @@

import { createStore, applyMiddleware, compose } from 'redux';
import { fromJS } from 'immutable';
import { routerMiddleware } from 'react-router-redux';
import { routerMiddleware } from 'connected-react-router/immutable';
import createSagaMiddleware from 'redux-saga';
import createReducer from './reducers';

Expand All @@ -24,11 +24,7 @@ export default function configureStore(initialState = {}, history) {
process.env.NODE_ENV !== 'production' &&
typeof window === 'object' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// TODO: Try to remove when `react-router-redux` is out of beta, LOCATION_CHANGE should not be fired more than once after hot reloading
// Prevent recomputing reducers for `replaceReducer`
shouldHotReload: false,
})
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;
/* eslint-enable */

Expand Down
2 changes: 1 addition & 1 deletion app/containers/Agents/index.js
Expand Up @@ -10,7 +10,7 @@ import PropTypes from 'prop-types';
import IIcon from 'images/iIcon.png';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import defaultAvatar from 'images/agent.png';
import Wrapper from 'components/Grid/Wrapper';
import { createStructuredSelector } from 'reselect';
Expand Down
6 changes: 4 additions & 2 deletions app/containers/App/selectors.js
Expand Up @@ -7,7 +7,7 @@ import { initialState } from './reducer';

const selectGlobal = state => state.get('global', initialState);

const selectRoute = state => state.get('route');
const selectRouter = state => state.get('router');

const makeSelectCurrentUser = () =>
createSelector(selectGlobal, globalState => globalState.get('currentUser'));
Expand All @@ -24,7 +24,9 @@ const makeSelectRepos = () =>
);

const makeSelectLocation = () =>
createSelector(selectRoute, routeState => routeState.get('location').toJS());
createSelector(selectRouter, routerState =>
routerState.get('location').toJS(),
);

export {
selectGlobal,
Expand Down
7 changes: 2 additions & 5 deletions app/containers/App/tests/selectors.test.js
Expand Up @@ -76,14 +76,11 @@ describe('makeSelectRepos', () => {
describe('makeSelectLocation', () => {
const locationStateSelector = makeSelectLocation();
it('should select the location', () => {
const route = fromJS({
location: { pathname: '/foo' },
});
const mockedState = fromJS({
route,
router: { location: { pathname: '/foo' } },
});
expect(locationStateSelector(mockedState)).toEqual(
route.get('location').toJS(),
mockedState.getIn(['router', 'location']).toJS(),
);
});
});
2 changes: 1 addition & 1 deletion app/containers/Entities/index.js
Expand Up @@ -9,7 +9,7 @@ import { compose } from 'redux';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import injectSaga from 'utils/injectSaga';
import Wrapper from 'components/Grid/Wrapper';
import injectReducer from 'utils/injectReducer';
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Expression/saga.js
@@ -1,5 +1,5 @@
import { put, takeLatest, select, call } from 'redux-saga/effects';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import axios from 'axios';
import * as a from './actions';
import {
Expand Down
2 changes: 1 addition & 1 deletion app/containers/NodePage/index.js
Expand Up @@ -9,7 +9,7 @@ import { compose } from 'redux';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import Wrapper from 'components/Grid/Wrapper';
import BackButton from 'components/BackButton';
import injectSaga from 'utils/injectSaga';
Expand Down
2 changes: 1 addition & 1 deletion app/containers/NodePage/saga.js
@@ -1,5 +1,5 @@
import { call, put, takeLatest } from 'redux-saga/effects';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import { reset } from 'redux-form/immutable';
import axios from 'axios';

Expand Down
2 changes: 1 addition & 1 deletion app/containers/SingleTalkFlow/saga.js
@@ -1,6 +1,6 @@
import axios from 'axios';
import _debug from 'debug';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import { put, takeLatest } from 'redux-saga/effects';

import { ADD_NODE, MOVE_NODE, REMOVE_NODE, SET_PARENT_NODE } from './constants';
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Talk/index.js
Expand Up @@ -9,7 +9,7 @@ import { compose } from 'redux';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import injectSaga from 'utils/injectSaga';
import injectReducer from 'utils/injectReducer';
import { createStructuredSelector } from 'reselect';
Expand Down
2 changes: 1 addition & 1 deletion app/containers/Talk/saga.js
@@ -1,5 +1,5 @@
import { put, takeLatest } from 'redux-saga/effects';
import { push } from 'react-router-redux';
import { push } from 'connected-react-router/immutable';
import axios from 'axios';
import _debug from 'debug';

Expand Down
35 changes: 7 additions & 28 deletions app/reducers.js
Expand Up @@ -2,10 +2,10 @@
* Combine all reducers in this file and export the combined reducers.
*/

import { fromJS } from 'immutable';
import { combineReducers } from 'redux-immutable';
import { LOCATION_CHANGE } from 'react-router-redux';
import { connectRouter } from 'connected-react-router/immutable';

import history from 'utils/history';
import globalReducer from 'containers/App/reducer';
import { reducer as formReducer } from 'redux-form/immutable';
import languageProviderReducer from 'containers/LanguageProvider/reducer';
Expand All @@ -18,35 +18,14 @@ import languageProviderReducer from 'containers/LanguageProvider/reducer';
*
*/

// Initial routing state
const routeInitialState = fromJS({
location: null,
});

/**
* Merge route into the global application state
*/
export function routeReducer(state = routeInitialState, action) {
switch (action.type) {
/* istanbul ignore next */
case LOCATION_CHANGE:
return state.merge({
location: action.payload,
});
default:
return state;
}
}

/**
* Creates the main reducer with the dynamically injected ones
*/
export default function createReducer(injectedReducers) {
return combineReducers({
route: routeReducer,
export default function createReducer(injectedReducers = {}) {
const rootReducer = combineReducers({
global: globalReducer,
form: formReducer,
language: languageProviderReducer,
...injectedReducers,
});
// Wrap the root reducer and return a new root reducer with router state
const mergeWithRouterState = connectRouter(history);
return mergeWithRouterState(rootReducer);
}
24 changes: 0 additions & 24 deletions app/tests/reducers.test.js

This file was deleted.

3 changes: 3 additions & 0 deletions app/utils/history.js
@@ -0,0 +1,3 @@
import createHistory from 'history/createBrowserHistory';
const history = createHistory();
export default history;
87 changes: 0 additions & 87 deletions internals/templates/app.js

This file was deleted.

55 changes: 0 additions & 55 deletions internals/templates/configureStore.js

This file was deleted.

10 changes: 0 additions & 10 deletions internals/templates/containers/App/constants.js

This file was deleted.

0 comments on commit b29b2c2

Please sign in to comment.