diff --git a/store/configureStore.development.ts b/store/configureStore.development.ts index c28a81d..2b4fce9 100644 --- a/store/configureStore.development.ts +++ b/store/configureStore.development.ts @@ -1,13 +1,12 @@ import { applyMiddleware, createStore } from "redux" import { composeWithDevTools } from "redux-devtools-extension" import createSagaMiddleware from "redux-saga" -import { combinedReducers } from "./reducers" +import { combinedReducers, RootState } from "./reducers" import { rootSaga } from "./sagas" -import { IInitialState } from "./states" const sagaMiddleware = createSagaMiddleware() -export function configureStore(initialState?: IInitialState) { +export function configureStore(initialState?: RootState) { const store = createStore( combinedReducers, initialState, diff --git a/store/configureStore.production.ts b/store/configureStore.production.ts index 6add60f..7f16422 100644 --- a/store/configureStore.production.ts +++ b/store/configureStore.production.ts @@ -1,12 +1,11 @@ import { applyMiddleware, createStore } from "redux" import createSagaMiddleware from "redux-saga" -import { combinedReducers } from "./reducers" +import { combinedReducers, RootState } from "./reducers" import { rootSaga } from "./sagas" -import { IInitialState } from "./states" const sagaMiddleware = createSagaMiddleware() -export function configureStore(initialState?: IInitialState) { +export function configureStore(initialState?: RootState) { const store = createStore( combinedReducers, initialState, diff --git a/store/configureStore.ts b/store/configureStore.ts index 0d460fc..3cceb31 100644 --- a/store/configureStore.ts +++ b/store/configureStore.ts @@ -1,5 +1,5 @@ import { Env } from "../constants" -import { IInitialState } from "../store/states" +import { RootState } from "./reducers" const configureStoreComponent = (() => { if (Env.NODE_ENV === "production") { @@ -8,5 +8,5 @@ const configureStoreComponent = (() => { return require("./configureStore.development") })() -export const configureStore = (initialState?: IInitialState) => +export const configureStore = (initialState?: RootState) => configureStoreComponent.configureStore(initialState) diff --git a/store/counter/selectors.ts b/store/counter/selectors.ts index f10059e..d82e040 100644 --- a/store/counter/selectors.ts +++ b/store/counter/selectors.ts @@ -1,3 +1,3 @@ -import { IInitialState } from "../states" +import { RootState } from "../reducers" -export const countSelector = (state: IInitialState) => state.counter.count +export const countSelector = (state: RootState) => state.counter.count diff --git a/store/page/selectors.ts b/store/page/selectors.ts index 4e1bf39..e45c2b8 100644 --- a/store/page/selectors.ts +++ b/store/page/selectors.ts @@ -1,4 +1,4 @@ -import { IInitialState } from "../states" +import { RootState } from "../reducers" -export const selectedPageSelector = (state: IInitialState) => +export const selectedPageSelector = (state: RootState) => state.page.selectedPage diff --git a/store/reducers.ts b/store/reducers.ts index 821c2e3..641125a 100644 --- a/store/reducers.ts +++ b/store/reducers.ts @@ -5,11 +5,12 @@ import { reduxSagaDebounceReducer, reduxSagaThrottleReducer, } from "./redux-saga/reducers" -import { IInitialState } from "./states" -export const combinedReducers = combineReducers({ +export const combinedReducers = combineReducers({ counter: countReducer, page: pageReducer, reduxSagaDebounce: reduxSagaDebounceReducer, reduxSagaThrottle: reduxSagaThrottleReducer, }) + +export type RootState = ReturnType diff --git a/store/redux-saga/selectors.ts b/store/redux-saga/selectors.ts index 87118d0..326bb23 100644 --- a/store/redux-saga/selectors.ts +++ b/store/redux-saga/selectors.ts @@ -1,10 +1,8 @@ -import { IInitialState } from "../states" +import { RootState } from "../reducers" import { IReduxSagaState } from "./states" -export const reduxSagaDebounceSelector = ( - state: IInitialState -): IReduxSagaState => state.reduxSagaDebounce +export const reduxSagaDebounceSelector = (state: RootState): IReduxSagaState => + state.reduxSagaDebounce -export const reduxSagaThrottleSelector = ( - state: IInitialState -): IReduxSagaState => state.reduxSagaThrottle +export const reduxSagaThrottleSelector = (state: RootState): IReduxSagaState => + state.reduxSagaThrottle diff --git a/store/states.ts b/store/states.ts deleted file mode 100644 index 8decd04..0000000 --- a/store/states.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { ICounterState } from "./counter" -import { IPageState } from "./page" -import { IReduxSagaState } from "./redux-saga" - -/** - * Initial state tree interface - */ -export interface IInitialState { - counter: Readonly - page: Readonly - reduxSagaDebounce: Readonly - reduxSagaThrottle: Readonly -}