insomnia/packages/insomnia-app/app/ui/redux/create.ts

29 lines
933 B
TypeScript
Raw Normal View History

/// <reference types="webpack-env" />
import { applyMiddleware, compose, createStore, Store } from 'redux';
import thunkMiddleware from 'redux-thunk';
2021-07-22 23:04:56 +00:00
2018-06-25 17:42:50 +00:00
import { reducer } from './modules';
2016-04-29 05:58:37 +00:00
// TODO there's a circular dependency between this file and /redux/create
2018-06-25 17:42:50 +00:00
export default function() {
const composeEnhancers =
2018-06-25 17:42:50 +00:00
typeof window === 'object' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// Specify extensions options like name, actionsBlacklist, actionsCreators, serialize...
})
2018-06-25 17:42:50 +00:00
: compose;
const middleware = [thunkMiddleware];
const enhancer = composeEnhancers(
applyMiddleware(...middleware), // other store enhancers if any
);
const store = createStore(reducer, enhancer);
if (__DEV__ && module.hot) {
module.hot.accept('./modules/index', () => {
store.replaceReducer(reducer);
});
2016-03-20 04:00:40 +00:00
}
2016-03-16 05:49:42 +00:00
return store as Store;
2016-03-20 04:00:40 +00:00
}