2023-02-18 13:11:01 +03:00
|
|
|
import { configureStore } from '@reduxjs/toolkit';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { IContainer } from 'bottlejs';
|
|
|
|
import type { RLSOptions } from 'redux-localstorage-simple';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { load, save } from 'redux-localstorage-simple';
|
2023-02-18 13:37:49 +03:00
|
|
|
import { initReducers } from '../reducers';
|
2021-12-23 19:53:06 +03:00
|
|
|
import { migrateDeprecatedSettings } from '../settings/helpers';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { 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';
|
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
|
|
|
|
2022-11-02 22:40:14 +03:00
|
|
|
export const setUpStore = (container: IContainer) => configureStore({
|
2022-11-01 14:52:27 +03:00
|
|
|
devTools: !isProduction,
|
2023-02-18 13:37:49 +03:00
|
|
|
reducer: initReducers(container),
|
2022-11-01 14:52:27 +03:00
|
|
|
preloadedState,
|
2022-11-11 21:31:05 +03:00
|
|
|
middleware: (defaultMiddlewaresIncludingReduxThunk) =>
|
2022-11-12 19:51:37 +03:00
|
|
|
defaultMiddlewaresIncludingReduxThunk({ immutableCheck: false, serializableCheck: false }) // State is too big for these
|
2022-11-11 21:31:05 +03:00
|
|
|
.concat(save(localStorageConfig)),
|
2022-11-01 14:52:27 +03:00
|
|
|
});
|