-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
233 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { UserSchema } from '@/entities/User'; | ||
|
||
export interface StateSchema { | ||
users: UserSchema; | ||
} |
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,7 @@ | ||
import type { TypedUseSelectorHook } from 'react-redux'; | ||
import type { RootState, AppDispatch } from './store'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
// Use throughout your app instead of plain `useDispatch` and `useSelector` | ||
export const useAppDispatch: () => AppDispatch = useDispatch; | ||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector; |
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,16 @@ | ||
import { combineReducers, configureStore } from '@reduxjs/toolkit'; | ||
|
||
import { userReducer } from '@/entities/User'; | ||
|
||
export type AppDispatch = typeof store.dispatch; | ||
export type RootState = ReturnType<typeof rootReducer>; | ||
|
||
const rootReducer = combineReducers({ | ||
users: userReducer, | ||
}); | ||
|
||
export const store = configureStore({ | ||
reducer: rootReducer, | ||
devTools: __IS_DEV__, | ||
// middleware: () => new Tuple(/* place middleware here */), | ||
}); |
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,3 @@ | ||
export { StoreProvider } from './ui/StoreProvider'; | ||
export { store, type RootState, type AppDispatch } from './config/store'; | ||
export { useAppDispatch, useAppSelector } from './config/hooks'; |
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,16 @@ | ||
import type { ReactNode, FC } from 'react'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import { store } from '../config/store'; | ||
import type { StateSchema } from '../config/StateSchema'; | ||
|
||
interface IProps { | ||
children: ReactNode; | ||
initialState?: StateSchema; | ||
} | ||
|
||
export const StoreProvider: FC<IProps> = ({ children }) => { | ||
return ( | ||
<Provider store={store}>{children}</Provider> | ||
); | ||
}; |
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,3 @@ | ||
export { default as userReducer, changeName } from './model/slice/userSlice'; | ||
export { type UserSchema } from './model/types/userSchema'; | ||
export { getUserName } from './model/selectors/getUserName/getUserName'; |
Empty file.
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,6 @@ | ||
import type { RootState } from '@/app/providers/StoreProvider'; | ||
// import { createSelector } from '@reduxjs/toolkit'; | ||
|
||
export const getUserName = (state: RootState) => state.users.name; | ||
|
||
// createSelector(getUserName, (name) => name); |
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,22 @@ | ||
import type { PayloadAction } from '@reduxjs/toolkit'; | ||
import { type UserSchema } from '../types/userSchema'; | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
// Define the initial state using that type | ||
const initialState: UserSchema = { | ||
name: 'Stas', | ||
}; | ||
|
||
export const usersSlice = createSlice({ | ||
name: 'users', | ||
initialState, | ||
reducers: { | ||
changeName: (state, action: PayloadAction<string>) => { | ||
state.name = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { changeName } = usersSlice.actions; | ||
|
||
export default usersSlice.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,3 @@ | ||
export interface UserSchema { | ||
name: string; | ||
} |
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
Oops, something went wrong.