mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-07-17 23:33:00 +08:00
add redux-persist
This commit is contained in:
parent
014ec92ff9
commit
05244c4a66
@ -13,11 +13,13 @@
|
|||||||
"@types/node": "^17.0.25",
|
"@types/node": "^17.0.25",
|
||||||
"@types/react": "^18.0.6",
|
"@types/react": "^18.0.6",
|
||||||
"@types/react-dom": "^18.0.2",
|
"@types/react-dom": "^18.0.2",
|
||||||
|
"@types/redux-persist": "^4.3.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-redux": "^8.0.1",
|
"react-redux": "^8.0.1",
|
||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
|
"redux-persist": "^6.0.0",
|
||||||
"typescript": "^4.6.0",
|
"typescript": "^4.6.0",
|
||||||
"web-vitals": "^2.1.0"
|
"web-vitals": "^2.1.0"
|
||||||
},
|
},
|
||||||
@ -47,9 +49,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.32.0 || ^8.2.0",
|
|
||||||
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
||||||
"@typescript-eslint/parser": "^5.31.0",
|
"@typescript-eslint/parser": "^5.31.0",
|
||||||
|
"eslint": "^7.32.0 || ^8.2.0",
|
||||||
"eslint-config-airbnb": "^19.0.4",
|
"eslint-config-airbnb": "^19.0.4",
|
||||||
"eslint-config-airbnb-typescript": "^17.0.0",
|
"eslint-config-airbnb-typescript": "^17.0.0",
|
||||||
"eslint-import-resolver-typescript": "^3.3.0",
|
"eslint-import-resolver-typescript": "^3.3.0",
|
||||||
|
@ -1,21 +1,50 @@
|
|||||||
import { configureStore, ThunkAction, Action } from '@reduxjs/toolkit';
|
import {
|
||||||
|
Action, combineReducers, configureStore, ThunkAction,
|
||||||
|
} from '@reduxjs/toolkit';
|
||||||
|
import {
|
||||||
|
persistStore,
|
||||||
|
persistReducer,
|
||||||
|
FLUSH,
|
||||||
|
REHYDRATE,
|
||||||
|
PAUSE,
|
||||||
|
PERSIST,
|
||||||
|
PURGE,
|
||||||
|
REGISTER,
|
||||||
|
} from 'redux-persist';
|
||||||
|
import storage from 'redux-persist/lib/storage';
|
||||||
import authReducer from '../features/auth/authSlice';
|
import authReducer from '../features/auth/authSlice';
|
||||||
import globalConfReducer from '../features/globalConf/globalConfSlice';
|
import globalConfReducer from '../features/globalConf/globalConfSlice';
|
||||||
import { subscribeApi } from '../features/subsribeConfigManager/subscribeConfigSlice';
|
import { subscribeApi } from '../features/subsribeConfigManager/subscribeConfigSlice';
|
||||||
import { weightApi } from '../features/weightConfig/weightConfigSlice';
|
import { weightApi } from '../features/weightConfig/weightConfigSlice';
|
||||||
|
|
||||||
|
const rootReducer = combineReducers({
|
||||||
|
auth: authReducer,
|
||||||
|
globalConf: globalConfReducer,
|
||||||
|
[subscribeApi.reducerPath]: subscribeApi.reducer,
|
||||||
|
[weightApi.reducerPath]: weightApi.reducer,
|
||||||
|
});
|
||||||
|
|
||||||
|
const persistConfig = {
|
||||||
|
key: 'root',
|
||||||
|
storage,
|
||||||
|
whitelist: ['auth'],
|
||||||
|
};
|
||||||
|
|
||||||
|
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||||
|
|
||||||
export const store = configureStore({
|
export const store = configureStore({
|
||||||
reducer: {
|
reducer: persistedReducer,
|
||||||
auth: authReducer,
|
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
|
||||||
globalConf: globalConfReducer,
|
serializableCheck: {
|
||||||
[subscribeApi.reducerPath]: subscribeApi.reducer,
|
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
|
||||||
[weightApi.reducerPath]: weightApi.reducer,
|
},
|
||||||
},
|
})
|
||||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware()
|
|
||||||
.concat(subscribeApi.middleware)
|
.concat(subscribeApi.middleware)
|
||||||
.concat(weightApi.middleware),
|
.concat(weightApi.middleware),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const persistor = persistStore(store);
|
||||||
|
|
||||||
export type AppDispatch = typeof store.dispatch;
|
export type AppDispatch = typeof store.dispatch;
|
||||||
export type RootState = ReturnType<typeof store.getState>;
|
export type RootState = ReturnType<typeof store.getState>;
|
||||||
export type AppThunk<ReturnType = void> = ThunkAction<
|
export type AppThunk<ReturnType = void> = ThunkAction<
|
||||||
|
@ -2,8 +2,9 @@ import React from 'react';
|
|||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
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 App from './App';
|
import App from './App';
|
||||||
import { store } from './app/store';
|
import { persistor, store } from './app/store';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import reportWebVitals from './reportWebVitals';
|
import reportWebVitals from './reportWebVitals';
|
||||||
|
|
||||||
@ -13,9 +14,11 @@ const root = createRoot(container);
|
|||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<BrowserRouter basename="/bison">
|
<PersistGate loading={null} persistor={persistor}>
|
||||||
<App />
|
<BrowserRouter basename="/bison">
|
||||||
</BrowserRouter>
|
<App />
|
||||||
|
</BrowserRouter>
|
||||||
|
</PersistGate>
|
||||||
</Provider>
|
</Provider>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
);
|
);
|
||||||
|
@ -2085,6 +2085,13 @@
|
|||||||
"@types/scheduler" "*"
|
"@types/scheduler" "*"
|
||||||
csstype "^3.0.2"
|
csstype "^3.0.2"
|
||||||
|
|
||||||
|
"@types/redux-persist@^4.3.1":
|
||||||
|
version "4.3.1"
|
||||||
|
resolved "https://registry.npmmirror.com/@types/redux-persist/-/redux-persist-4.3.1.tgz#aa4c876859e0bea5155e5f7980e5b8c4699dc2e6"
|
||||||
|
integrity sha512-YkMnMUk+4//wPtiSTMfsxST/F9Gh9sPWX0LVxHuOidGjojHtMdpep2cYvQgfiDMnj34orXyZI+QJCQMZDlafKA==
|
||||||
|
dependencies:
|
||||||
|
redux-persist "*"
|
||||||
|
|
||||||
"@types/resolve@1.17.1":
|
"@types/resolve@1.17.1":
|
||||||
version "1.17.1"
|
version "1.17.1"
|
||||||
resolved "https://registry.npmmirror.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
|
resolved "https://registry.npmmirror.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
|
||||||
@ -7592,6 +7599,11 @@ redent@^3.0.0:
|
|||||||
indent-string "^4.0.0"
|
indent-string "^4.0.0"
|
||||||
strip-indent "^3.0.0"
|
strip-indent "^3.0.0"
|
||||||
|
|
||||||
|
redux-persist@*, redux-persist@^6.0.0:
|
||||||
|
version "6.0.0"
|
||||||
|
resolved "https://registry.npmmirror.com/redux-persist/-/redux-persist-6.0.0.tgz#b4d2972f9859597c130d40d4b146fecdab51b3a8"
|
||||||
|
integrity sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==
|
||||||
|
|
||||||
redux-thunk@^2.4.1:
|
redux-thunk@^2.4.1:
|
||||||
version "2.4.1"
|
version "2.4.1"
|
||||||
resolved "https://registry.npmmirror.com/redux-thunk/-/redux-thunk-2.4.1.tgz#0dd8042cf47868f4b29699941de03c9301a75714"
|
resolved "https://registry.npmmirror.com/redux-thunk/-/redux-thunk-2.4.1.tgz#0dd8042cf47868f4b29699941de03c9301a75714"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user