-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented redux for state management
- Loading branch information
1 parent
6cce4b8
commit 35312a5
Showing
6 changed files
with
145 additions
and
42 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// src/redux/connectionSlice.ts | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { ConnectionSliceState, ConnectionState } from '../types'; | ||
|
||
const initialState: ConnectionSliceState = { | ||
connectionState: 'disconnected', | ||
}; | ||
|
||
export const connectionSlice = createSlice({ | ||
name: 'connection', | ||
initialState, | ||
reducers: { | ||
setConnectionState: (state, action: PayloadAction<ConnectionState>) => { | ||
state.connectionState = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setConnectionState } = connectionSlice.actions; | ||
export default connectionSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// src/redux/store.ts | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import connectionReducer from './connectionSlice'; | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
connection: connectionReducer, | ||
}, | ||
}); | ||
|
||
// Infer the `RootState` and `AppDispatch` types from the store itself | ||
export type RootState = ReturnType<typeof store.getState>; | ||
export type AppDispatch = typeof store.dispatch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// src/types/index.ts | ||
export type ConnectionState = | ||
| 'disconnected' | ||
| 'connecting' | ||
| 'connected' | ||
| 'error' | ||
| 'retrying'; | ||
|
||
export interface ConnectionSliceState { | ||
connectionState: ConnectionState; | ||
} |