优化
This commit is contained in:
33
client/shared/redux/slices/global.ts
Normal file
33
client/shared/redux/slices/global.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
export interface GlobalState {
|
||||
/**
|
||||
* 网络状态
|
||||
*/
|
||||
networkStatus: 'initial' | 'connected' | 'reconnecting' | 'disconnected';
|
||||
reconnectNum: number;
|
||||
}
|
||||
|
||||
const initialState: GlobalState = {
|
||||
networkStatus: 'initial',
|
||||
reconnectNum: 0,
|
||||
};
|
||||
|
||||
const globalSlice = createSlice({
|
||||
name: 'global',
|
||||
initialState,
|
||||
reducers: {
|
||||
setNetworkStatus(
|
||||
state,
|
||||
action: PayloadAction<GlobalState['networkStatus']>
|
||||
) {
|
||||
state.networkStatus = action.payload;
|
||||
},
|
||||
incReconnectNum(state) {
|
||||
state.reconnectNum += 1;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const globalActions = globalSlice.actions;
|
||||
export const globalReducer = globalSlice.reducer;
|
||||
Reference in New Issue
Block a user