This repository was archived by the owner on Dec 14, 2022. It is now read-only.
forked from maisieccino/ucl-assistant-app
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfigureStore.ts
57 lines (44 loc) · 1.5 KB
/
configureStore.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import AsyncStorage from '@react-native-async-storage/async-storage'
import { applyMiddleware, combineReducers, createStore } from "redux"
import { persistReducer, persistStore } from "redux-persist"
import createSecureStore from "redux-persist-expo-securestore"
import thunk from "redux-thunk"
import debounce from "./lib/debounce"
import { SIGN_OUT_USER } from "./redux/constants/userConstants"
import reducer, { initialState } from "./redux/reducers"
const { user, ...otherReducers } = reducer
const secureStorage = createSecureStore()
const middleware = [debounce.middleware(), thunk]
if (process.env.NODE_ENV === `development`) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { logger } = require(`redux-logger`)
middleware.push(logger)
}
const config = {
blacklist: [`user`],
debug: __DEV__,
key: `root`,
storage: AsyncStorage,
}
const userPersistConfig = {
blacklist: [`signIn`],
debug: __DEV__,
key: `user`,
storage: secureStorage,
}
const appReducer = combineReducers({
user: persistReducer(userPersistConfig, user),
...otherReducers,
})
const rootReducer = (state, action) => appReducer(
action.type === SIGN_OUT_USER ? undefined : state, action,
)
const persistRootReducer = persistReducer(config, rootReducer)
const store = createStore(
persistRootReducer,
initialState as unknown,
applyMiddleware(...middleware),
)
export type AppStateType = ReturnType<typeof store.getState>
const persistor = persistStore(store)
export default { persistor, store }