forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.ts
77 lines (67 loc) · 2.32 KB
/
store.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { combineReducers, configureStore } from '@reduxjs/toolkit'
import { persistStore, persistReducer, PersistorOptions } from 'redux-persist'
import createMigrate from 'redux-persist/lib/createMigrate'
import { reduxPersistMigrations } from './migrations'
import persistStorage from './persistStorage'
import chatInputsRootReducer, {
sliceName as chatInputsSliceName,
} from './reducers/chatInputs.reducer'
import chatInputsVolatileRootReducer from './reducers/chatInputsVolatile.reducer'
import newGroupRootReducer, {
sliceName as newGroupSliceName,
} from './reducers/groupCreationForm.reducer'
import messengerRootReducer from './reducers/messenger.reducer'
import networkConfigReducer, {
sliceName as networkConfigSliceName,
} from './reducers/networkConfig.reducer'
import persistentOptionsReducer, {
sliceName as persistentOptionsSliceName,
} from './reducers/persistentOptions.reducer'
import themeReducer, { sliceName as themeSliceName } from './reducers/theme.reducer'
import uiReducer from './reducers/ui.reducer'
const persistConfig = {
key: 'persistStore',
storage: persistStorage,
version: 0,
whitelist: [
newGroupSliceName,
chatInputsSliceName,
themeSliceName,
networkConfigSliceName,
persistentOptionsSliceName,
],
migrate: createMigrate(reduxPersistMigrations, { debug: true }),
}
const rootReducer = combineReducers({
...newGroupRootReducer,
...chatInputsRootReducer,
...chatInputsVolatileRootReducer,
...messengerRootReducer,
...themeReducer,
...uiReducer,
...networkConfigReducer,
...persistentOptionsReducer,
})
const persistedReducer = persistReducer(persistConfig, rootReducer)
export const resetAccountStore = () => ({ type: 'RESET' })
const resettableReducer: typeof persistedReducer = (state, action, ...other) => {
if (action.type === 'RESET') {
return persistedReducer(undefined, action)
} else if (action.type === 'FULL_RESET') {
return persistedReducer(undefined, action)
}
return persistedReducer(state, action, ...other)
}
const store = configureStore({
reducer: resettableReducer,
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
serializableCheck: false,
}),
})
export const persistor = persistStore(store, {
manualPersist: true,
} as PersistorOptions)
export type RootState = ReturnType<typeof rootReducer>
export type AppDispatch = typeof store.dispatch
export default store