2017-04-07 07:15:22 +02:00
|
|
|
const redux = require('redux');
|
|
|
|
const thunk = require("redux-thunk").default;
|
2017-05-23 09:41:26 +02:00
|
|
|
const env = ENV;
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
createLogger
|
|
|
|
} from 'redux-logger'
|
|
|
|
import appReducer from 'reducers/app';
|
2017-04-29 11:50:29 +02:00
|
|
|
import availabilityReducer from 'reducers/availability'
|
2017-04-28 17:14:44 +02:00
|
|
|
import claimsReducer from 'reducers/claims'
|
2017-04-23 11:56:50 +02:00
|
|
|
import contentReducer from 'reducers/content';
|
2017-04-28 17:14:44 +02:00
|
|
|
import costInfoReducer from 'reducers/cost_info'
|
|
|
|
import fileInfoReducer from 'reducers/file_info'
|
2017-04-24 09:25:27 +02:00
|
|
|
import rewardsReducer from 'reducers/rewards'
|
2017-04-24 16:17:36 +02:00
|
|
|
import searchReducer from 'reducers/search'
|
2017-05-17 23:52:45 +02:00
|
|
|
import settingsReducer from 'reducers/settings'
|
2017-04-22 15:17:01 +02:00
|
|
|
import walletReducer from 'reducers/wallet'
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
function isFunction(object) {
|
|
|
|
return typeof object === 'function';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isNotFunction(object) {
|
|
|
|
return !isFunction(object);
|
|
|
|
}
|
|
|
|
|
2017-04-26 19:08:26 +02:00
|
|
|
function createBulkThunkMiddleware() {
|
|
|
|
return ({ dispatch, getState }) => next => (action) => {
|
|
|
|
if (action.type === 'BATCH_ACTIONS') {
|
|
|
|
action.actions.filter(isFunction).map(actionFn =>
|
|
|
|
actionFn(dispatch, getState)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return next(action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableBatching(reducer) {
|
|
|
|
return function batchingReducer(state, action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'BATCH_ACTIONS':
|
|
|
|
return action.actions.filter(isNotFunction).reduce(batchingReducer, state)
|
|
|
|
default:
|
|
|
|
return reducer(state, action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-07 07:15:22 +02:00
|
|
|
const reducers = redux.combineReducers({
|
|
|
|
app: appReducer,
|
2017-04-29 11:50:29 +02:00
|
|
|
availability: availabilityReducer,
|
2017-04-28 17:14:44 +02:00
|
|
|
claims: claimsReducer,
|
|
|
|
fileInfo: fileInfoReducer,
|
2017-04-23 11:56:50 +02:00
|
|
|
content: contentReducer,
|
2017-04-28 17:14:44 +02:00
|
|
|
costInfo: costInfoReducer,
|
2017-04-24 09:25:27 +02:00
|
|
|
rewards: rewardsReducer,
|
2017-04-24 16:17:36 +02:00
|
|
|
search: searchReducer,
|
2017-05-17 23:52:45 +02:00
|
|
|
settings: settingsReducer,
|
2017-04-22 15:17:01 +02:00
|
|
|
wallet: walletReducer,
|
2017-04-07 07:15:22 +02:00
|
|
|
});
|
|
|
|
|
2017-04-26 19:08:26 +02:00
|
|
|
const bulkThunk = createBulkThunkMiddleware()
|
|
|
|
const middleware = [thunk, bulkThunk]
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-05-12 01:28:43 +02:00
|
|
|
if (env === 'development') {
|
|
|
|
const logger = createLogger({
|
|
|
|
collapsed: true
|
|
|
|
});
|
|
|
|
middleware.push(logger)
|
|
|
|
}
|
2017-04-07 07:15:22 +02:00
|
|
|
|
2017-04-24 09:25:27 +02:00
|
|
|
const createStoreWithMiddleware = redux.compose(
|
2017-04-07 07:15:22 +02:00
|
|
|
redux.applyMiddleware(...middleware)
|
|
|
|
)(redux.createStore);
|
|
|
|
|
2017-04-26 19:08:26 +02:00
|
|
|
const reduxStore = createStoreWithMiddleware(enableBatching(reducers));
|
2017-04-07 07:15:22 +02:00
|
|
|
|
|
|
|
export default reduxStore;
|