pagraphcontrol/store/index.js
2019-08-11 00:39:28 +03:00

45 lines
1.0 KiB
JavaScript

const { createStore, applyMiddleware } = require('redux');
const { composeWithDevTools } = require('remote-redux-devtools');
const { default: thunkMiddleware } = require('redux-thunk');
const { default: promiseMiddleware } = require('redux-promise-middleware');
const { persistStore, persistReducer } = require('redux-persist');
const createElectronStorage = require('redux-persist-electron-storage');
const { reducer, initialState } = require('../reducers');
const pulseMiddleware = require('./pulse-middleware');
const persistConfig = {
key: 'redux-persist',
whitelist: [ 'preferences' ],
storage: createElectronStorage(),
};
const dev = process.env.NODE_ENV !== 'production';
module.exports = (state = initialState) => {
const middlewares = [
thunkMiddleware,
promiseMiddleware,
pulseMiddleware,
].filter(Boolean);
const reducer_ = persistReducer(persistConfig, reducer);
const store = createStore(
reducer_,
state,
composeWithDevTools({
realtime: dev,
})(applyMiddleware(...middlewares)),
);
persistStore(store);
return store;
};