forked from Wolox/wolmo-bootstrap-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.ejs
90 lines (74 loc) · 2.59 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
87
88
89
90
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import Reactotron from 'reactotron-react-native';
import thunk from 'redux-thunk';
import {
createReactNavigationReduxMiddleware,
createNavigationReducer
} from 'react-navigation-redux-helpers';
import { fetchMiddleware, configureMergeState } from 'redux-recompose';
<%_ if(features.reduxpersist) { _%>
import AsyncStorage from '@react-native-community/async-storage';
import { persistReducer } from 'redux-persist';
import {
seamlessImmutableReconciler,
seamlessImmutableTransformCreator
} from 'redux-persist-seamless-immutable';
<%_ } _%>
<%_ if(features.googleanalytics) { _%>
import AnalyticsMiddleware from './middlewares/analyticsMiddleware';
<%_ } _%>
<%_ if(features.login) { _%>
import auth from './auth/reducer';
<%_ } _%>
<%_ if(features.pushnotifications) { _%>
import pushNotifications from './pushNotifications/reducer';
<%_ } _%>
import Navigator from '@screens';
<%_ if(features.reduxpersist) { _%>
const transformerConfig = {
whitelistPerReducer: {
<%_ if(features.login) { _%>auth: ['currentUser']<%_ } _%>
}
};
const persistConfig = {
key: 'root',
storage: AsyncStorage,
whitelist: [<%_ if(features.login) { _%>'auth'<%_ } _%>],
stateReconciler: seamlessImmutableReconciler,
transforms: [seamlessImmutableTransformCreator(transformerConfig)]
};
<%_ } _%>
const nav = createNavigationReducer(Navigator);
configureMergeState((state, diff) => state.merge(diff));
const reducers = combineReducers({
<%_ if(features.pushnotifications) { _%>
pushNotifications,
<%_ } _%>
<%_ if(features.login) { _%>
auth,
<%_ } _%>
nav
});
<%_ if(features.reduxpersist) { _%>
const persistedReducer = persistReducer(persistConfig, reducers);
<%_ } _%>
const middlewares = [];
const enhancers = [];
/* ------------- React Navigation Middleware ------------- */
middlewares.push(createReactNavigationReduxMiddleware(state => state.nav));
/* ------------- Thunk Middleware ------------- */
middlewares.push(thunk);
/* ------------- Redux-Recompose Middleware ------------- */
middlewares.push(fetchMiddleware);
<%_ if(features.googleanalytics) { _%>
/* ------------- Analytics Middleware ------------- */
middlewares.push(AnalyticsMiddleware);
<%_ } _%>
/* ------------- Assemble Middleware ------------- */
enhancers.push(applyMiddleware(...middlewares));
if (__DEV__) enhancers.push(Reactotron.createEnhancer());
// in dev mode, we'll create the store through Reactotron
const store = createStore(<%_ if(features.reduxpersist) { _%>persistedReducer
<%_ } else{ _%>
reducers<%_ } _%>, compose(...enhancers));
export default store;