2020-04-13 08:24:13 +00:00
|
|
|
import { reduxBatch } from "@manaflair/redux-batch";
|
2022-07-11 04:06:29 +00:00
|
|
|
import { createStore, applyMiddleware, compose } from "redux";
|
2022-08-24 12:16:32 +00:00
|
|
|
import appReducer, { AppState } from "@appsmith/reducers";
|
2019-12-23 12:16:33 +00:00
|
|
|
import createSagaMiddleware from "redux-saga";
|
2022-08-24 12:16:32 +00:00
|
|
|
import { rootSaga } from "@appsmith/sagas";
|
2019-12-23 12:16:33 +00:00
|
|
|
import { composeWithDevTools } from "redux-devtools-extension/logOnlyInProduction";
|
2020-08-28 11:31:07 +00:00
|
|
|
import * as Sentry from "@sentry/react";
|
2022-07-11 04:06:29 +00:00
|
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
|
|
|
|
import routeParamsMiddleware from "RouteParamsMiddleware";
|
2019-12-23 12:16:33 +00:00
|
|
|
|
|
|
|
|
const sagaMiddleware = createSagaMiddleware();
|
2022-11-03 09:23:15 +00:00
|
|
|
const ignoredSentryActionTypes = [
|
|
|
|
|
ReduxActionTypes.SET_EVALUATED_TREE,
|
|
|
|
|
ReduxActionTypes.EXECUTE_PLUGIN_ACTION_SUCCESS,
|
|
|
|
|
ReduxActionTypes.SET_LINT_ERRORS,
|
|
|
|
|
];
|
2020-08-28 11:31:07 +00:00
|
|
|
const sentryReduxEnhancer = Sentry.createReduxEnhancer({
|
2020-12-24 04:32:25 +00:00
|
|
|
actionTransformer: (action) => {
|
2022-11-03 09:23:15 +00:00
|
|
|
if (ignoredSentryActionTypes.includes(action.type)) {
|
2020-12-09 09:12:12 +00:00
|
|
|
// Return null to not log the action to Sentry
|
|
|
|
|
action.payload = null;
|
|
|
|
|
}
|
|
|
|
|
return action;
|
|
|
|
|
},
|
2020-08-28 11:31:07 +00:00
|
|
|
});
|
|
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
export default createStore(
|
|
|
|
|
appReducer,
|
2020-08-28 11:31:07 +00:00
|
|
|
composeWithDevTools(
|
|
|
|
|
reduxBatch,
|
2022-03-25 10:43:26 +00:00
|
|
|
applyMiddleware(sagaMiddleware, routeParamsMiddleware),
|
2020-08-28 11:31:07 +00:00
|
|
|
reduxBatch,
|
|
|
|
|
sentryReduxEnhancer,
|
|
|
|
|
),
|
2019-12-23 12:16:33 +00:00
|
|
|
);
|
2021-04-22 03:30:09 +00:00
|
|
|
|
|
|
|
|
export const testStore = (initialState: Partial<AppState>) =>
|
|
|
|
|
createStore(
|
|
|
|
|
appReducer,
|
|
|
|
|
initialState,
|
2022-03-25 10:43:26 +00:00
|
|
|
compose(
|
|
|
|
|
reduxBatch,
|
|
|
|
|
applyMiddleware(sagaMiddleware, routeParamsMiddleware),
|
|
|
|
|
reduxBatch,
|
|
|
|
|
),
|
2021-04-22 03:30:09 +00:00
|
|
|
);
|
|
|
|
|
|
2022-11-30 10:38:15 +00:00
|
|
|
// We don't want to run the saga middleware in tests, so exporting it from here
|
|
|
|
|
// And running it only when the app runs
|
|
|
|
|
export const runSagaMiddleware = () => sagaMiddleware.run(rootSaga);
|