-
Notifications
You must be signed in to change notification settings - Fork 14
/
store.ejs
86 lines (71 loc) · 2.58 KB
/
store.ejs
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
78
79
80
81
82
83
84
85
86
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import Reactotron from 'reactotron-react-native';
import thunk from 'redux-thunk';
import { fetchMiddleware, configureMergeState } from 'redux-recompose';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { persistReducer } from 'redux-persist';
import {
seamlessImmutableReconciler,
seamlessImmutableTransformCreator
} from 'redux-persist-seamless-immutable';
import { ImmutableObject } from 'seamless-immutable';
import { State } from '@interfaces/reduxInterfaces';
import auth from './auth/reducer';
<%_ if(features.firebaseanalytics) { _%>
import AnalyticsMiddleware from './middlewares/analyticsMiddleware';
<%_ } _%>
const transformerConfig = {
whitelistPerReducer: {
<%_ if(features.loginandsignup || features.onboarding) { _%>
auth: [
<%_ if(features.loginandsignup && features.onboarding) { _%>
'currentUser', 'hasAccessOnBoarding'
<%_ } else { _%>
<%_ if(features.loginandsignup) { _%>
'currentUser'
<%_ } else { _%>
'hasAccessOnBoarding'
<%_ } _%>
<%_ } _%>
]
<%_ } else { _%>
// TODO: Complete with reducers, for example
// auth: ['currentUser']
<%_ } _%>
}
};
const persistConfig = {
key: 'root',
storage: AsyncStorage,
<%_ if(features.loginandsignup || features.onboarding) { _%>
whitelist: ['auth'],
<%_ } else { _%>
// TODO: Complete with reducers, for example
// whitelist: ['auth']
whitelist: [],
<%_ } _%>
stateReconciler: seamlessImmutableReconciler,
transforms: [seamlessImmutableTransformCreator(transformerConfig)]
};
configureMergeState((state: ImmutableObject<State>, diff: State) => state.merge(diff));
const reducers = combineReducers({
auth
});
const persistedReducer = persistReducer(persistConfig, reducers);
const middlewares = [];
const enhancers = [];
/* ------------- Thunk Middleware ------------- */
middlewares.push(thunk);
/* ------------- Redux-Recompose Middleware ------------- */
middlewares.push(fetchMiddleware);
<%_ if(features.firebaseanalytics) { _%>
/* ------------- Analytics Middleware ------------- */
middlewares.push(AnalyticsMiddleware);
<%_ } _%>
/* ------------- Assemble Middleware ------------- */
enhancers.push(applyMiddleware(...middlewares));
if (__DEV__ && Reactotron.createEnhancer) enhancers.push(Reactotron.createEnhancer(true));
// In DEV mode, we'll create the store through Reactotron
const store = createStore(persistedReducer, compose(...enhancers));
if (__DEV__ && Reactotron.setReduxStore) Reactotron.setReduxStore(store);
export default store;