From a4d649f62a511d6a27317f2e11868fe77c597cc2 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Mon, 17 Jun 2019 12:59:33 +0200 Subject: [PATCH] Return store object instead of a function ES6 modules are evaluated only once on first import. They behave like singleton. Some redux librairies except the store to be a singleton. Returning a function and invoking it remove this behavior. Change-Id: I74ff516567d4b7bcf5f1e2d3004eb4617817f117 --- web/src/App.test.jsx | 5 +---- web/src/containers/status/ChangePanel.test.jsx | 4 +--- web/src/index.js | 4 +--- web/src/store.js | 6 +++--- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/web/src/App.test.jsx b/web/src/App.test.jsx index de68c6a66e..ea981dea28 100644 --- a/web/src/App.test.jsx +++ b/web/src/App.test.jsx @@ -20,7 +20,7 @@ import { Link, BrowserRouter as Router } from 'react-router-dom' import { Provider } from 'react-redux' import { fetchInfoIfNeeded } from './actions/info' -import createZuulStore from './store' +import store from './store' import App from './App' import TenantsPage from './pages/Tenants' import StatusPage from './pages/Status' @@ -35,7 +35,6 @@ api.fetchConfigErrors.mockImplementation(() => Promise.resolve({data: []})) it('renders without crashing', () => { const div = document.createElement('div') - const store = createZuulStore() ReactDOM.render(, div) ReactDOM.unmountComponentAtNode(div) @@ -50,7 +49,6 @@ it('renders multi tenant', () => { api.fetchTenants.mockImplementation( () => Promise.resolve({data: [{name: 'openstack'}]}) ) - const store = createZuulStore() const application = ReactTestUtils.renderIntoDocument( ) @@ -81,7 +79,6 @@ it('renders single tenant', () => { api.fetchStatus.mockImplementation( () => Promise.resolve({data: {pipelines: []}}) ) - const store = createZuulStore() const application = ReactTestUtils.renderIntoDocument( ) diff --git a/web/src/containers/status/ChangePanel.test.jsx b/web/src/containers/status/ChangePanel.test.jsx index c46daf13bb..a44c9c8b4e 100644 --- a/web/src/containers/status/ChangePanel.test.jsx +++ b/web/src/containers/status/ChangePanel.test.jsx @@ -19,7 +19,7 @@ import { Link, BrowserRouter as Router } from 'react-router-dom' import { Provider } from 'react-redux' import { setTenantAction } from '../../actions/tenant' -import createZuulStore from '../../store' +import store from '../../store' import ChangePanel from './ChangePanel' @@ -33,7 +33,6 @@ const fakeChange = { } it('change panel render multi tenant links', () => { - const store = createZuulStore() store.dispatch(setTenantAction('tenant-one', false)) const application = ReactTestUtils.renderIntoDocument( @@ -49,7 +48,6 @@ it('change panel render multi tenant links', () => { }) it('change panel render white-label tenant links', () => { - const store = createZuulStore() store.dispatch(setTenantAction('tenant-one', true)) const application = ReactTestUtils.renderIntoDocument( diff --git a/web/src/index.js b/web/src/index.js index 07ad3ce37c..98e0b06d0a 100644 --- a/web/src/index.js +++ b/web/src/index.js @@ -26,11 +26,9 @@ import './index.css' import { getHomepageUrl } from './api' import registerServiceWorker from './registerServiceWorker' import { fetchInfoIfNeeded } from './actions/info' -import createZuulStore from './store' +import store from './store' import App from './App' -const store = createZuulStore() - // Load info endpoint store.dispatch(fetchInfoIfNeeded()) diff --git a/web/src/store.js b/web/src/store.js index bad6b19466..ec1b8443b5 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -17,6 +17,6 @@ import thunk from 'redux-thunk' import appReducers from './reducers' -export default function createZuulStore() { - return createStore(appReducers, applyMiddleware(thunk)) -} +const store = createStore(appReducers, applyMiddleware(thunk)) + +export default store \ No newline at end of file