Skip to content

Commit f7ce8c7

Browse files
treetipsusername
andauthored
refactor: remove IInitialState and generate it automatically from combinedReducers. (#28)
Co-authored-by: username <username@users.noreply.github.com>
1 parent c9d717c commit f7ce8c7

File tree

8 files changed

+18
-34
lines changed

8 files changed

+18
-34
lines changed

store/configureStore.development.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { applyMiddleware, createStore } from "redux"
22
import { composeWithDevTools } from "redux-devtools-extension"
33
import createSagaMiddleware from "redux-saga"
4-
import { combinedReducers } from "./reducers"
4+
import { combinedReducers, RootState } from "./reducers"
55
import { rootSaga } from "./sagas"
6-
import { IInitialState } from "./states"
76

87
const sagaMiddleware = createSagaMiddleware()
98

10-
export function configureStore(initialState?: IInitialState) {
9+
export function configureStore(initialState?: RootState) {
1110
const store = createStore(
1211
combinedReducers,
1312
initialState,

store/configureStore.production.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { applyMiddleware, createStore } from "redux"
22
import createSagaMiddleware from "redux-saga"
3-
import { combinedReducers } from "./reducers"
3+
import { combinedReducers, RootState } from "./reducers"
44
import { rootSaga } from "./sagas"
5-
import { IInitialState } from "./states"
65

76
const sagaMiddleware = createSagaMiddleware()
87

9-
export function configureStore(initialState?: IInitialState) {
8+
export function configureStore(initialState?: RootState) {
109
const store = createStore(
1110
combinedReducers,
1211
initialState,

store/configureStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Env } from "../constants"
2-
import { IInitialState } from "../store/states"
2+
import { RootState } from "./reducers"
33

44
const configureStoreComponent = (() => {
55
if (Env.NODE_ENV === "production") {
@@ -8,5 +8,5 @@ const configureStoreComponent = (() => {
88
return require("./configureStore.development")
99
})()
1010

11-
export const configureStore = (initialState?: IInitialState) =>
11+
export const configureStore = (initialState?: RootState) =>
1212
configureStoreComponent.configureStore(initialState)

store/counter/selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { IInitialState } from "../states"
1+
import { RootState } from "../reducers"
22

3-
export const countSelector = (state: IInitialState) => state.counter.count
3+
export const countSelector = (state: RootState) => state.counter.count

store/page/selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IInitialState } from "../states"
1+
import { RootState } from "../reducers"
22

3-
export const selectedPageSelector = (state: IInitialState) =>
3+
export const selectedPageSelector = (state: RootState) =>
44
state.page.selectedPage

store/reducers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import {
55
reduxSagaDebounceReducer,
66
reduxSagaThrottleReducer,
77
} from "./redux-saga/reducers"
8-
import { IInitialState } from "./states"
98

10-
export const combinedReducers = combineReducers<IInitialState>({
9+
export const combinedReducers = combineReducers({
1110
counter: countReducer,
1211
page: pageReducer,
1312
reduxSagaDebounce: reduxSagaDebounceReducer,
1413
reduxSagaThrottle: reduxSagaThrottleReducer,
1514
})
15+
16+
export type RootState = ReturnType<typeof combinedReducers>

store/redux-saga/selectors.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { IInitialState } from "../states"
1+
import { RootState } from "../reducers"
22
import { IReduxSagaState } from "./states"
33

4-
export const reduxSagaDebounceSelector = (
5-
state: IInitialState
6-
): IReduxSagaState => state.reduxSagaDebounce
4+
export const reduxSagaDebounceSelector = (state: RootState): IReduxSagaState =>
5+
state.reduxSagaDebounce
76

8-
export const reduxSagaThrottleSelector = (
9-
state: IInitialState
10-
): IReduxSagaState => state.reduxSagaThrottle
7+
export const reduxSagaThrottleSelector = (state: RootState): IReduxSagaState =>
8+
state.reduxSagaThrottle

store/states.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)