Live video on the AT Protocol
1import type { Action, ThunkAction } from "@reduxjs/toolkit";
2import { combineSlices, configureStore } from "@reduxjs/toolkit";
3import { setupListeners } from "@reduxjs/toolkit/query";
4import { baseSlice } from "features/base/baseSlice";
5import { sidebarSlice } from "features/base/sidebarSlice";
6import { blueskySlice } from "features/bluesky/blueskySlice";
7import { platformSlice } from "features/platform/platformSlice";
8import { streamplaceSlice } from "features/streamplace/streamplaceSlice";
9
10import { listenerMiddleware } from "./listener";
11
12const rootReducer = combineSlices(
13 blueskySlice,
14 streamplaceSlice,
15 platformSlice,
16 sidebarSlice,
17 baseSlice,
18);
19
20export type RootState = ReturnType<typeof rootReducer>;
21
22export const makeStore = (preloadedState?: Partial<RootState>) => {
23 const store = configureStore({
24 reducer: rootReducer,
25 // Adding the api middleware enables caching, invalidation, polling,
26 // and other useful features of `rtk-query`.
27 middleware: (getDefaultMiddleware) => {
28 return getDefaultMiddleware({
29 serializableCheck: {
30 // Ignore these action types
31 ignoredActions: [],
32 // Ignore these field paths in all actions
33 ignoredActionPaths: ["payload"],
34 // Ignore these paths in the state
35 ignoredPaths: [/^bluesky\..*/, /^streamplace\..*/],
36 },
37 }).prepend(listenerMiddleware.middleware);
38 },
39 preloadedState,
40 });
41 // configure listeners using the provided defaults
42 // optional, but required for `refetchOnFocus`/`refetchOnReconnect` behaviors
43 setupListeners(store.dispatch);
44 return store;
45};
46
47export const store = makeStore();
48
49// Infer the type of `store`
50export type AppStore = typeof store;
51// Infer the `AppDispatch` type from the store itself
52export type AppDispatch = AppStore["dispatch"];
53export type AppThunk<ThunkReturnType = void> = ThunkAction<
54 ThunkReturnType,
55 RootState,
56 unknown,
57 Action
58>;