2018-12-17 22:03:36 +03:00
|
|
|
import ReduxThunk from 'redux-thunk';
|
|
|
|
import { applyMiddleware, compose, createStore } from 'redux';
|
2020-08-22 09:47:19 +03:00
|
|
|
import { save, load, RLSOptions } from 'redux-localstorage-simple';
|
2018-12-17 22:03:36 +03:00
|
|
|
import reducers from '../reducers';
|
2021-12-23 19:53:06 +03:00
|
|
|
import { migrateDeprecatedSettings } from '../settings/helpers';
|
|
|
|
import { ShlinkState } from './types';
|
2018-12-17 22:03:36 +03:00
|
|
|
|
2022-04-02 09:31:15 +03:00
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
|
|
// eslint-disable-next-line no-mixed-operators
|
|
|
|
const composeEnhancers: Function = !isProduction && (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
2018-12-17 22:03:36 +03:00
|
|
|
|
2020-08-22 09:47:19 +03:00
|
|
|
const localStorageConfig: RLSOptions = {
|
2022-03-26 14:17:42 +03:00
|
|
|
states: ['settings', 'servers'],
|
2020-04-26 20:04:17 +03:00
|
|
|
namespace: 'shlink',
|
|
|
|
namespaceSeparator: '.',
|
2020-05-03 21:16:21 +03:00
|
|
|
debounce: 300,
|
2020-04-26 20:04:17 +03:00
|
|
|
};
|
2021-12-23 19:53:06 +03:00
|
|
|
const preloadedState = migrateDeprecatedSettings(load(localStorageConfig) as ShlinkState);
|
2020-04-26 20:04:17 +03:00
|
|
|
|
2021-12-23 19:53:06 +03:00
|
|
|
export const store = createStore(reducers, preloadedState, composeEnhancers(
|
2020-08-22 09:10:31 +03:00
|
|
|
applyMiddleware(save(localStorageConfig), ReduxThunk),
|
2018-12-17 22:03:36 +03:00
|
|
|
));
|