mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
feat: Redux store persist gate.
This commit is contained in:
@@ -89,7 +89,7 @@
|
|||||||
"react-use": "^13.26.1",
|
"react-use": "^13.26.1",
|
||||||
"react-window": "^1.8.5",
|
"react-window": "^1.8.5",
|
||||||
"redux": "^4.0.5",
|
"redux": "^4.0.5",
|
||||||
"redux-localstorage": "^0.4.1",
|
"redux-persist": "^6.0.0",
|
||||||
"redux-thunk": "^2.3.0",
|
"redux-thunk": "^2.3.0",
|
||||||
"resolve": "1.15.0",
|
"resolve": "1.15.0",
|
||||||
"resolve-url-loader": "3.1.1",
|
"resolve-url-loader": "3.1.1",
|
||||||
|
|||||||
@@ -2,36 +2,37 @@ import React from 'react';
|
|||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
|
import { PersistGate } from 'redux-persist/integration/react';
|
||||||
import 'services/yup';
|
import 'services/yup';
|
||||||
import App from 'components/App';
|
import App from 'components/App';
|
||||||
import * as serviceWorker from 'serviceWorker';
|
import * as serviceWorker from 'serviceWorker';
|
||||||
import createStore from 'store/createStore';
|
import { store, persistor } from 'store/createStore';
|
||||||
import AppProgress from 'components/NProgress/AppProgress';
|
import AppProgress from 'components/NProgress/AppProgress';
|
||||||
|
|
||||||
import {locale} from 'lang/en/locale';
|
import whyDidYouRender from '@welldone-software/why-did-you-render';
|
||||||
import whyDidYouRender from "@welldone-software/why-did-you-render";
|
|
||||||
|
|
||||||
whyDidYouRender(React, {
|
whyDidYouRender(React, {
|
||||||
onlyLogs: true,
|
onlyLogs: true,
|
||||||
titleColor: "green",
|
titleColor: 'green',
|
||||||
diffNameColor: "aqua"
|
diffNameColor: 'aqua',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Provider store={createStore}>
|
<Provider store={store}>
|
||||||
|
<PersistGate loading={null} persistor={persistor}>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<App />
|
<App />
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
</PersistGate>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
document.getElementById('root')
|
document.getElementById('root'),
|
||||||
);
|
);
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Provider store={createStore}>
|
<Provider store={store}>
|
||||||
<AppProgress />
|
<AppProgress />
|
||||||
</Provider>,
|
</Provider>,
|
||||||
document.getElementById('nprogress')
|
document.getElementById('nprogress'),
|
||||||
);
|
);
|
||||||
|
|
||||||
// If you want your app to work offline and load faster, you can change
|
// If you want your app to work offline and load faster, you can change
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
import store from 'store/createStore';
|
import { store } from 'store/createStore';
|
||||||
import { logout } from 'store/authentication/authentication.actions';
|
import { logout } from 'store/authentication/authentication.actions';
|
||||||
import AppToaster from 'components/AppToaster';
|
import AppToaster from 'components/AppToaster';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
|||||||
@@ -1,34 +1,35 @@
|
|||||||
import { createStore as createReduxStore, applyMiddleware, compose } from 'redux';
|
import {
|
||||||
|
createStore as createReduxStore,
|
||||||
|
applyMiddleware,
|
||||||
|
compose,
|
||||||
|
} from 'redux';
|
||||||
import thunkMiddleware from 'redux-thunk';
|
import thunkMiddleware from 'redux-thunk';
|
||||||
|
import { persistStore, persistReducer } from 'redux-persist';
|
||||||
|
import storage from 'redux-persist/lib/storage';
|
||||||
import monitorReducerEnhancer from 'store/enhancers/monitorReducer';
|
import monitorReducerEnhancer from 'store/enhancers/monitorReducer';
|
||||||
import loggerMiddleware from 'middleware/logger'
|
import loggerMiddleware from 'middleware/logger';
|
||||||
import rootReducer from 'store/reducers';
|
import rootReducer from 'store/reducers';
|
||||||
import persistState from 'redux-localstorage'
|
|
||||||
|
|
||||||
const persistPaths = ['dashboard', 'authentication'];
|
const persistConfig = {
|
||||||
|
key: 'bigcapital:root',
|
||||||
|
blacklist: ['dashboard'],
|
||||||
|
storage,
|
||||||
|
};
|
||||||
|
|
||||||
const createStore = (initialState = {
|
const createStoreFactory = (initialState = {}) => {
|
||||||
// ...loadState(),
|
|
||||||
}) => {
|
|
||||||
/**
|
/**
|
||||||
|--------------------------------------------------
|
|--------------------------------------------------
|
||||||
| Middleware Configuration
|
| Middleware Configuration
|
||||||
|--------------------------------------------------
|
|--------------------------------------------------
|
||||||
*/
|
*/
|
||||||
const middleware = [
|
const middleware = [thunkMiddleware, loggerMiddleware];
|
||||||
thunkMiddleware,
|
|
||||||
loggerMiddleware,
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|--------------------------------------------------
|
|--------------------------------------------------
|
||||||
| Store Enhancers
|
| Store Enhancers
|
||||||
|--------------------------------------------------
|
|--------------------------------------------------
|
||||||
*/
|
*/
|
||||||
const enhancers = [
|
const enhancers = [monitorReducerEnhancer];
|
||||||
monitorReducerEnhancer,
|
|
||||||
persistState(persistPaths, { key: 'bigcapital' }),
|
|
||||||
];
|
|
||||||
let composeEnhancers = compose;
|
let composeEnhancers = compose;
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
@@ -43,11 +44,14 @@ const createStore = (initialState = {
|
|||||||
|--------------------------------------------------
|
|--------------------------------------------------
|
||||||
*/
|
*/
|
||||||
const store = createReduxStore(
|
const store = createReduxStore(
|
||||||
rootReducer,
|
persistReducer(persistConfig, rootReducer),
|
||||||
initialState,
|
initialState,
|
||||||
composeEnhancers(applyMiddleware(...middleware), ...enhancers)
|
composeEnhancers(applyMiddleware(...middleware), ...enhancers),
|
||||||
);
|
);
|
||||||
store.asyncReducers = {};
|
store.asyncReducers = {};
|
||||||
return store;
|
return store;
|
||||||
};
|
};
|
||||||
export default createStore();
|
|
||||||
|
export const createStore = createStoreFactory;
|
||||||
|
export const store = createStoreFactory();
|
||||||
|
export const persistor = persistStore(store);
|
||||||
|
|||||||
Reference in New Issue
Block a user