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

27 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-02-18 10:40:37 +01:00
import type { IContainer } from 'bottlejs';
import type { RLSOptions } from 'redux-localstorage-simple';
import { save, load } from 'redux-localstorage-simple';
import { configureStore } from '@reduxjs/toolkit';
import reducer from '../reducers';
import { migrateDeprecatedSettings } from '../settings/helpers';
2023-02-18 10:40:37 +01:00
import type { ShlinkState } from './types';
const isProduction = process.env.NODE_ENV === 'production';
2020-08-22 08:47:19 +02:00
const localStorageConfig: RLSOptions = {
2022-03-26 12:17:42 +01:00
states: ['settings', 'servers'],
namespace: 'shlink',
namespaceSeparator: '.',
2020-05-03 20:16:21 +02:00
debounce: 300,
};
const preloadedState = migrateDeprecatedSettings(load(localStorageConfig) as ShlinkState);
export const setUpStore = (container: IContainer) => configureStore({
devTools: !isProduction,
reducer: reducer(container),
preloadedState,
2022-11-11 19:31:05 +01:00
middleware: (defaultMiddlewaresIncludingReduxThunk) =>
2022-11-12 17:51:37 +01:00
defaultMiddlewaresIncludingReduxThunk({ immutableCheck: false, serializableCheck: false }) // State is too big for these
2022-11-11 19:31:05 +01:00
.prepend(container.selectServerListener.middleware)
.concat(save(localStorageConfig)),
});