shlink-web-client/src/container/store.ts

22 lines
862 B
TypeScript
Raw Normal View History

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';
import reducers from '../reducers';
import { migrateDeprecatedSettings } from '../settings/helpers';
import { ShlinkState } from './types';
2020-08-22 09:47:19 +03:00
const isProduction = process.env.NODE_ENV !== 'production';
2022-03-26 14:17:42 +03:00
const composeEnhancers: Function = !isProduction ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose;
2020-08-22 09:47:19 +03:00
const localStorageConfig: RLSOptions = {
2022-03-26 14:17:42 +03:00
states: ['settings', 'servers'],
namespace: 'shlink',
namespaceSeparator: '.',
2020-05-03 21:16:21 +03:00
debounce: 300,
};
const preloadedState = migrateDeprecatedSettings(load(localStorageConfig) as ShlinkState);
export const store = createStore(reducers, preloadedState, composeEnhancers(
2020-08-22 09:10:31 +03:00
applyMiddleware(save(localStorageConfig), ReduxThunk),
));