Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import isElectron from "is-electron";
let storage: any;
// The only time IS_ELECTRON will be 1 is for the electron build.
if (isElectron()) {
const createElectronStore = require("electron-store-webpack-wrapper").default;
const createElectronStorage = require("redux-persist-electron-storage");
const electronStore = createElectronStore({
// your electron-store options here
});
storage = createElectronStorage({
electronStore
});
} else {
storage = require("redux-persist/lib/storage").default;
}
export default storage;
function getStorage(context) {
if (context.cookieJar) {
const { CookieStorage } = require('redux-persist-cookie-storage');
return new CookieStorage(context.cookieJar, {});
}
return require('redux-persist/lib/storage').default;
}
export function makeStore(initialState, { isServer }) {
initialState = initialState || reducer()
const middlewares = [thunk]
if (publicRuntimeConfig.logReduxAction) {
middlewares.push(logger)
}
const enhancer = composeWithDevTools(applyMiddleware(...middlewares))
if (isServer) {
return createStore(reducer, initialState, enhancer)
} else {
const { persistReducer, persistStore } = require('redux-persist')
const storage = require('redux-persist/lib/storage').default
const persistedReducer = persistReducer({
key: 'jwpay',
whitelist: ['common', 'form', 'account'],
storage,
migrate: state => {
if (state && compareVersion(state.common.version, process.env.version, 2) !== 0) {
state = initialState
}
return Promise.resolve(state)
},
}, reducer)
const store = createStore(persistedReducer, initialState, enhancer)
store.__persistor = persistStore(store)
function getStorage(context) {
if (context.cookieJar) {
const { CookieStorage } = require('redux-persist-cookie-storage');
return new CookieStorage(context.cookieJar, {});
}
return require('redux-persist/lib/storage').default;
}