2021-01-14 12:07:05 -06:00
|
|
|
// Copyright 2019-2021 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-09-14 14:56:35 -07:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { DeepPartial, Store } from 'redux';
|
|
|
|
import { applyMiddleware, createStore as reduxCreateStore } from 'redux';
|
2019-01-14 13:49:58 -08:00
|
|
|
|
|
|
|
import promise from 'redux-promise-middleware';
|
2020-10-30 13:00:01 -05:00
|
|
|
import thunk from 'redux-thunk';
|
2019-01-14 13:49:58 -08:00
|
|
|
import { createLogger } from 'redux-logger';
|
|
|
|
|
2021-10-26 14:15:33 -05:00
|
|
|
import type { StateType } from './reducer';
|
|
|
|
import { reducer } from './reducer';
|
2021-08-18 16:08:14 -04:00
|
|
|
import { dispatchItemsMiddleware } from '../shims/dispatchItemsMiddleware';
|
2020-09-14 14:56:35 -07:00
|
|
|
|
|
|
|
declare global {
|
2021-01-14 12:07:05 -06:00
|
|
|
// We want to extend `window`'s properties, so we need an interface.
|
|
|
|
// eslint-disable-next-line no-restricted-syntax, @typescript-eslint/no-unused-vars
|
2020-09-14 14:56:35 -07:00
|
|
|
interface Console {
|
|
|
|
_log: Console['log'];
|
|
|
|
}
|
|
|
|
}
|
2019-01-14 13:49:58 -08:00
|
|
|
|
|
|
|
const env = window.getEnvironment();
|
|
|
|
|
|
|
|
// So Redux logging doesn't go to disk, and so we can get colors/styles
|
|
|
|
const directConsole = {
|
|
|
|
log: console._log,
|
|
|
|
groupCollapsed: console.groupCollapsed,
|
|
|
|
group: console.group,
|
|
|
|
groupEnd: console.groupEnd,
|
|
|
|
warn: console.warn,
|
|
|
|
error: console.error,
|
|
|
|
};
|
|
|
|
|
|
|
|
const logger = createLogger({
|
|
|
|
logger: directConsole,
|
2020-12-18 11:27:43 -08:00
|
|
|
predicate: (_getState, action) => {
|
|
|
|
if (action.type === 'network/CHECK_NETWORK_STATUS') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
2019-01-14 13:49:58 -08:00
|
|
|
});
|
|
|
|
|
2020-10-30 13:00:01 -05:00
|
|
|
const middlewareList = [
|
|
|
|
promise,
|
|
|
|
thunk,
|
2021-08-18 16:08:14 -04:00
|
|
|
dispatchItemsMiddleware,
|
2020-10-30 13:00:01 -05:00
|
|
|
...(env === 'production' ? [] : [logger]),
|
|
|
|
];
|
2019-01-14 13:49:58 -08:00
|
|
|
|
2020-09-14 14:56:35 -07:00
|
|
|
const enhancer = applyMiddleware(...middlewareList);
|
2019-01-14 13:49:58 -08:00
|
|
|
|
2021-01-26 17:12:23 -06:00
|
|
|
export const createStore = (
|
|
|
|
initialState: DeepPartial<StateType>
|
|
|
|
): Store<StateType> => reduxCreateStore(reducer, initialState, enhancer);
|