/
createStore.js
39 lines (32 loc) · 932 Bytes
/
createStore.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
34
35
36
37
38
39
import { createStore, combineReducers, applyMiddleware } from 'redux';
import {
reducer as network,
createNetworkMiddleware,
} from 'react-native-offline';
import createSagaMiddleware from 'redux-saga';
import counter from './reducer';
import rootSaga from './sagas';
export default function createReduxStore({
withSaga = false,
queueReleaseThrottle = 1000,
} = {}) {
const networkMiddleware = createNetworkMiddleware({
regexActionType: /^OTHER/,
actionTypes: ['ADD_ONE', 'SUB_ONE'],
queueReleaseThrottle,
});
const sagaMiddleware = createSagaMiddleware();
const rootReducer = combineReducers({
counter,
network,
});
const middlewares = [networkMiddleware];
if (withSaga === true) {
middlewares.push(sagaMiddleware);
}
const store = createStore(rootReducer, applyMiddleware(...middlewares));
if (withSaga === true) {
sagaMiddleware.run(rootSaga);
}
return store;
}