ligo/tools/webide/packages/client/src/configure-store.ts
Jev Björsell c119c44c13
Import webide into main ligo monorepo
When this is merged https://gitlab.com/ligolang/ligo-web-ide/ will be
marked as deprecated.

This MR does not hook up the webide build to the main CI. The CI
integration will come in a subsequent MR for the sake of making review
easier.
2020-02-06 19:04:18 -08:00

32 lines
813 B
TypeScript

import { applyMiddleware, createStore, Middleware } from 'redux';
import ReduxThunk from 'redux-thunk';
import rootReducer, { AppState } from './redux/app';
declare var defaultServerState: AppState | undefined;
export default function configureStore() {
const store = createStore(
rootReducer,
{
...(typeof defaultServerState === 'undefined' ? {} : defaultServerState)
},
applyMiddleware(ReduxThunk, cleanRouteOnAction)
);
return store;
}
const cleanRouteOnAction: Middleware = store => next => action => {
const { share } = store.getState();
next(action);
const state = store.getState();
if (
share.link !== undefined &&
state.share.link === undefined &&
window.location.pathname !== '/'
) {
window.history.replaceState({}, document.title, '/');
}
};