github.com/grafana/pyroscope@v1.18.0/public/app/redux/store.ts (about)

     1  import {
     2    persistStore,
     3    persistReducer,
     4    FLUSH,
     5    REHYDRATE,
     6    PAUSE,
     7    PERSIST,
     8    PURGE,
     9    REGISTER,
    10  } from 'redux-persist';
    11  
    12  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    13  // @ts-ignore: Until we rewrite FlamegraphRenderer in typescript this will do
    14  import { configureStore, combineReducers, Middleware } from '@reduxjs/toolkit';
    15  
    16  import { continuousReducer } from './reducers/continuous';
    17  import uiStore, { persistConfig as uiPersistConfig } from './reducers/ui';
    18  import tenantReducer, {
    19    persistConfig as tenantPersistConfig,
    20  } from '@pyroscope/redux/reducers/tenant';
    21  import { setStore } from '@pyroscope/services/storage';
    22  
    23  const reducer = combineReducers({
    24    ui: persistReducer(uiPersistConfig, uiStore),
    25    continuous: continuousReducer,
    26    tenant: persistReducer(tenantPersistConfig, tenantReducer),
    27  });
    28  
    29  // Most times we will display a (somewhat) user friendly message toast
    30  // But it's still useful to have the actual error logged to the console
    31  export const logErrorMiddleware: Middleware = () => (next) => (action) => {
    32    next(action);
    33    if (action?.error) {
    34      console.error(action.error);
    35    }
    36  };
    37  
    38  const store = configureStore({
    39    reducer,
    40    // https://github.com/reduxjs/redux-toolkit/issues/587#issuecomment-824927971
    41    middleware: (getDefaultMiddleware) =>
    42      getDefaultMiddleware({
    43        serializableCheck: {
    44          ignoredActionPaths: ['error'],
    45  
    46          // Based on this issue: https://github.com/rt2zz/redux-persist/issues/988
    47          // and this guide https://redux-toolkit.js.org/usage/usage-guide#use-with-redux-persist
    48          ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
    49        },
    50      }).concat([logErrorMiddleware]),
    51  });
    52  
    53  export const persistor = persistStore(store);
    54  
    55  export default store;
    56  
    57  // Infer the `RootState` and `AppDispatch` types from the store itself
    58  export type RootState = ReturnType<typeof store.getState>;
    59  // Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
    60  export type AppDispatch = typeof store.dispatch;
    61  
    62  export type StoreType = typeof store;
    63  
    64  setStore(store);