-
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.
Merge pull request #9 from zoopi-palette/feat/redux
Feat/redux
- Loading branch information
Showing
8 changed files
with
16,464 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {configureStore, Store} from "@reduxjs/toolkit"; | ||
import {createWrapper} from "next-redux-wrapper"; | ||
import {logger} from "redux-logger"; | ||
import createSagaMiddleware, {Task} from "redux-saga"; | ||
import userReducer from "./user/user"; | ||
|
||
// ref: https://github.com/vercel/next.js/tree/canary/examples/with-redux-saga | ||
// ref: https://github.com/kirill-konshin/next-redux-wrapper#usage-with-redux-saga | ||
// ref: https://github.com/Tinkerbell-Green/need-compliments/pull/6/files | ||
export interface SagaStore extends Store { | ||
sagaTask?: Task; | ||
} | ||
|
||
function* rootSaga() { | ||
// yield all([사가()]); | ||
} | ||
|
||
const makeStore = () => { | ||
const sagaMiddleware = createSagaMiddleware(); | ||
const store: SagaStore = configureStore({ | ||
reducer: { | ||
user: userReducer, | ||
}, | ||
devTools: process.env.NODE_ENV !== "production", | ||
middleware: [sagaMiddleware, logger], | ||
}); | ||
store.sagaTask = sagaMiddleware.run(rootSaga); | ||
return store | ||
} | ||
|
||
export type RootStore = ReturnType<typeof makeStore>; | ||
export type RootState = ReturnType<RootStore["getState"]>; | ||
export const wrapper = createWrapper<RootStore>(makeStore, {debug: true}); |
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,34 @@ | ||
import {createSlice, PayloadAction} from "@reduxjs/toolkit"; | ||
import {HYDRATE} from "next-redux-wrapper"; | ||
|
||
export type State = { | ||
loggedInUserId: string | null, | ||
initialized: boolean, | ||
} | ||
|
||
export const initialState: State = { | ||
loggedInUserId: null, | ||
initialized: false, | ||
} | ||
|
||
export const userSlice = createSlice({ | ||
name: "user", | ||
initialState, | ||
reducers: { | ||
SET_USER_ID: (state: State, {payload}: PayloadAction<{ id: string }>) => { | ||
state.loggedInUserId = payload.id; | ||
}, | ||
SET_INITIALIZED: (state: State, {payload}: PayloadAction<{ isInitialized: boolean }>) => { | ||
state.initialized = payload.isInitialized; | ||
}, | ||
}, | ||
extraReducers: { | ||
[HYDRATE]: (state: State, {payload}: PayloadAction) => payload, | ||
} | ||
}) | ||
|
||
export const { | ||
SET_USER_ID, SET_INITIALIZED | ||
} = userSlice.actions; | ||
|
||
export default userSlice.reducer; |
Oops, something went wrong.