-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigureStore.js
33 lines (30 loc) · 934 Bytes
/
configureStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { createStore, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import logger from "redux-logger";
import rootReducer from "./reducers/rootReducer";
import { createWrapper, HYDRATE } from "next-redux-wrapper";
import { loadState, saveState } from "./localstorage";
import throttle from "lodash/throttle";
const configureStore = () => {
const middlewares = [thunk];
const persistedState = loadState();
// if (process.env.NODE_ENV) {
// middlewares.push(logger);
// }
const store = createStore(
rootReducer,
persistedState,
applyMiddleware(...middlewares)
);
store.subscribe(
throttle(() => {
saveState(store.getState());
}, 1000)
);
return store;
};
// create a makeStore function
const makeStore = (context) => configureStore();
// export an assembled wrapper
export const wrapper = createWrapper(makeStore, { debug: true });
// export default configureStore;