-
Notifications
You must be signed in to change notification settings - Fork 3
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 #106 from tahmid-saj/dev-redux-init
initializing redux
- Loading branch information
Showing
7 changed files
with
163 additions
and
28 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,15 @@ | ||
// redux middlewares | ||
|
||
export const loggerMiddleware = (store) => (next) => (action) => { | ||
if (!action.type) { | ||
return next(action) | ||
} | ||
|
||
console.log("type ", action.type) | ||
console.log("payload ", action.payload) | ||
console.log("currentState ", store.getState()) | ||
|
||
next(action) | ||
|
||
console.log("next state ", store.getState()) | ||
} |
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 { combineReducers } from "redux" | ||
|
||
export const rootReducer = combineReducers({ | ||
|
||
}) |
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 { compose, createStore, applyMiddleware } from "redux" | ||
import logger from "redux-logger" | ||
import { persistStore, persistReducer } from "redux-persist" | ||
import storage from "redux-persist/lib/storage" | ||
import { rootReducer } from "./root-reducer" | ||
import { loggerMiddleware } from "./middleware/logger" | ||
|
||
// root-reducer | ||
const middlewares = [ | ||
process.env.NODE_ENV !== "production" && loggerMiddleware, | ||
process.env.NODE_ENV !== "production" && logger | ||
].filter(Boolean) | ||
|
||
const composeEnhancer = ( | ||
process.env.NODE_ENV !== "production" && window && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ | ||
) || compose | ||
|
||
// const composedEnhancers = composeEnhancer(applyMiddleware(...middleWares)) | ||
const composedEnhancers = compose(applyMiddleware(...middlewares)) | ||
|
||
// redux persist | ||
const persistConfig = { | ||
key: "root", | ||
storage: storage, | ||
blacklist: ["user"] | ||
} | ||
|
||
// const persistedReducer = persistReducer(persistConfig, rootReducer) | ||
|
||
// store | ||
export const store = createStore(rootReducer, undefined, composedEnhancers) | ||
|
||
// export const persistor = persistStore(store) |
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,4 @@ | ||
// reducer utils | ||
|
||
// creating reducer action | ||
export const createAction = (type, payload) => ({ type, payload }) |