From 6f4eb97b48ca2e8c632afe3bf2a80740deb7bb5f Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Mon, 8 May 2017 22:34:50 +0300 Subject: [PATCH] #85: drop react-router-redux dependency --- npm-shrinkwrap.json | 5 ----- package.json | 1 - src/components/accounts/actions.js | 4 ++-- src/components/auth/actions.js | 10 ++++++---- src/pages/profile/ProfilePage.jsx | 4 ++-- src/reducers.js | 5 +---- src/services/authFlow/AuthFlow.js | 5 +++-- src/storeFactory.js | 4 ---- tests/components/accounts/actions.test.js | 8 +++++--- 9 files changed, 19 insertions(+), 27 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 95701a5..a54682d 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -6172,11 +6172,6 @@ "from": "react-router@3.0.5", "resolved": "https://registry.npmjs.org/react-router/-/react-router-3.0.5.tgz" }, - "react-router-redux": { - "version": "3.0.0", - "from": "react-router-redux@>=3.0.0 <4.0.0", - "resolved": "https://registry.npmjs.org/react-router-redux/-/react-router-redux-3.0.0.tgz" - }, "react-side-effect": { "version": "1.1.0", "from": "react-side-effect@>=1.1.0 <2.0.0", diff --git a/package.json b/package.json index 808f0a6..e3cd40f 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "react-motion": "^0.4.0", "react-redux": "^5.0.0", "react-router": "^3.0.0", - "react-router-redux": "^3.0.0", "redux": "^3.0.4", "redux-localstorage": "^0.4.1", "redux-thunk": "^2.0.0", diff --git a/src/components/accounts/actions.js b/src/components/accounts/actions.js index b8793ef..54e76e7 100644 --- a/src/components/accounts/actions.js +++ b/src/components/accounts/actions.js @@ -1,4 +1,4 @@ -import { routeActions } from 'react-router-redux'; +import { browserHistory } from 'react-router'; import { sessionStorage } from 'services/localStorage'; import authentication from 'services/api/authentication'; @@ -124,7 +124,7 @@ export function logoutAll() { dispatch(reset()); - dispatch(routeActions.push('/login')); + browserHistory.push('/login'); return Promise.resolve(); }; diff --git a/src/components/auth/actions.js b/src/components/auth/actions.js index f369dac..94ee292 100644 --- a/src/components/auth/actions.js +++ b/src/components/auth/actions.js @@ -1,4 +1,4 @@ -import { routeActions } from 'react-router-redux'; +import { browserHistory } from 'react-router'; import logger from 'services/logger'; import localStorage from 'services/localStorage'; @@ -25,9 +25,9 @@ export { authenticate, logoutAll as logout } from 'components/accounts/actions'; */ export function goBack(fallbackUrl = null) { if (history.canGoBack()) { - return routeActions.goBack(); + browserHistory.goBack(); } else if (fallbackUrl) { - return routeActions.push(fallbackUrl); + browserHistory.push(fallbackUrl); } return { @@ -125,8 +125,10 @@ export function register({ username, email })); + dispatch(needActivation()); - dispatch(routeActions.push('/activation')); + + browserHistory.push('/activation'); }) .catch(validationErrorsHandler(dispatch)) ); diff --git a/src/pages/profile/ProfilePage.jsx b/src/pages/profile/ProfilePage.jsx index c8165b2..05b04ac 100644 --- a/src/pages/profile/ProfilePage.jsx +++ b/src/pages/profile/ProfilePage.jsx @@ -42,14 +42,14 @@ class ProfilePage extends Component { } import { connect } from 'react-redux'; -import { routeActions } from 'react-router-redux'; +import { browserHistory } from 'react-router'; import { fetchUserData } from 'components/user/actions'; import { create as createPopup } from 'components/ui/popup/actions'; import PasswordRequestForm from 'components/profile/passwordRequestForm/PasswordRequestForm'; export default connect(null, { goToProfile() { - return routeActions.push('/'); + return browserHistory.push('/'); }, fetchUserData, onSubmit: ({form, sendData}) => (dispatch) => { diff --git a/src/reducers.js b/src/reducers.js index 7161456..67a321d 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -1,7 +1,5 @@ import { combineReducers } from 'redux'; -import { routeReducer } from 'react-router-redux'; - import auth from 'components/auth/reducer'; import user from 'components/user/reducer'; import accounts from 'components/accounts/reducer'; @@ -15,6 +13,5 @@ export default combineReducers({ user, accounts, i18n, - popup, - routing: routeReducer + popup }); diff --git a/src/services/authFlow/AuthFlow.js b/src/services/authFlow/AuthFlow.js index 2ed6fb8..ed84514 100644 --- a/src/services/authFlow/AuthFlow.js +++ b/src/services/authFlow/AuthFlow.js @@ -1,4 +1,4 @@ -import { routeActions } from 'react-router-redux'; +import { browserHistory } from 'react-router'; import logger from 'services/logger'; import localStorage from 'services/localStorage'; @@ -40,7 +40,8 @@ export default class AuthFlow { if (this.replace) { this.replace(route); } - store.dispatch(routeActions[options.replace ? 'replace' : 'push'](route)); + + browserHistory[options.replace ? 'replace' : 'push'](route); } this.replace = null; diff --git a/src/storeFactory.js b/src/storeFactory.js index b393efd..7167bbb 100644 --- a/src/storeFactory.js +++ b/src/storeFactory.js @@ -5,15 +5,11 @@ import { createStore, applyMiddleware, compose } from 'redux'; // или даже вообще его не запускать в зависимости от условий import thunk from 'redux-thunk'; import persistState from 'redux-localstorage'; -import { syncHistory } from 'react-router-redux'; -import { browserHistory } from 'react-router'; import reducers from 'reducers'; export default function storeFactory() { - const reduxRouterMiddleware = syncHistory(browserHistory); const middlewares = applyMiddleware( - reduxRouterMiddleware, thunk ); const persistStateEnhancer = persistState([ diff --git a/tests/components/accounts/actions.test.js b/tests/components/accounts/actions.test.js index 6877cde..58b9c39 100644 --- a/tests/components/accounts/actions.test.js +++ b/tests/components/accounts/actions.test.js @@ -1,7 +1,7 @@ import expect from 'unexpected'; import sinon from 'sinon'; -import { routeActions } from 'react-router-redux'; +import { browserHistory } from 'react-router'; import logger from 'services/logger'; import { InternalServerError } from 'services/request'; @@ -292,10 +292,12 @@ describe('components/accounts/actions', () => { }); sinon.stub(authentication, 'logout').named('authentication.logout'); + sinon.stub(browserHistory, 'push').named('browserHistory.push'); }); afterEach(() => { authentication.logout.restore(); + browserHistory.push.restore(); }); it('should call logout api method for each account', () => { @@ -317,8 +319,8 @@ describe('components/accounts/actions', () => { it('should redirect to /login', () => logoutAll()(dispatch, getState).then(() => { - expect(dispatch, 'to have a call satisfying', [ - routeActions.push('/login') + expect(browserHistory.push, 'to have a call satisfying', [ + '/login' ]); }) );