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

25 lines
1,018 B
TypeScript
Raw Normal View History

import { IContainer } from 'bottlejs';
2020-08-22 09:47:19 +03:00
import { save, load, RLSOptions } from 'redux-localstorage-simple';
import { configureStore } from '@reduxjs/toolkit';
import reducer from '../reducers';
import { migrateDeprecatedSettings } from '../settings/helpers';
import { ShlinkState } from './types';
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'],
namespace: 'shlink',
namespaceSeparator: '.',
2020-05-03 21:16:21 +03:00
debounce: 300,
};
const preloadedState = migrateDeprecatedSettings(load(localStorageConfig) as ShlinkState);
export const setUpStore = (container: IContainer) => configureStore({
devTools: !isProduction,
reducer: reducer(container),
preloadedState,
middleware: (defaultMiddlewaresIncludingReduxThunk) => defaultMiddlewaresIncludingReduxThunk(
{ immutableCheck: false, serializableCheck: false }, // State is too big for these
).prepend(container.selectServerListener.middleware).concat(save(localStorageConfig)),
});