New source found from dndbeyond.com
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import { applyMiddleware, createStore, Reducer, Store } from "redux";
|
||||
import { composeWithDevTools } from "redux-devtools-extension";
|
||||
import {
|
||||
applyMiddleware,
|
||||
Reducer,
|
||||
Store,
|
||||
PreloadedState,
|
||||
AnyAction,
|
||||
legacy_createStore,
|
||||
compose,
|
||||
} from "redux";
|
||||
import createSagaMiddleware from "redux-saga";
|
||||
|
||||
import {
|
||||
defaultSaga,
|
||||
ApiAdapterException,
|
||||
OverrideApiException,
|
||||
} from "@dndbeyond/character-rules-engine/es";
|
||||
|
||||
import { rollResultSaga } from "../sagas";
|
||||
@@ -17,12 +23,13 @@ export function getAppStore(): Store | null {
|
||||
return store;
|
||||
}
|
||||
|
||||
export function configureStore(
|
||||
initialState: any,
|
||||
rootReducer: Reducer,
|
||||
// Generic store configurator with improved typing; defaults preserve previous 'any' behavior
|
||||
export function configureStore<S = any, A extends AnyAction = AnyAction>(
|
||||
initialState: PreloadedState<S>,
|
||||
rootReducer: Reducer<S, A>,
|
||||
sagaMiddleware: Array<any> = [],
|
||||
middleware: Array<any> = []
|
||||
): Store {
|
||||
): Store<S, A> {
|
||||
const storeSagaMiddleware = createSagaMiddleware({
|
||||
onError: (error, errorInfo) => {
|
||||
// ApiAdapterException errors are handled by the AppApiAdapter
|
||||
@@ -36,10 +43,19 @@ export function configureStore(
|
||||
storeMiddleware.push(...middleware);
|
||||
storeMiddleware.push(storeSagaMiddleware);
|
||||
|
||||
store = createStore(
|
||||
rootReducer,
|
||||
initialState,
|
||||
composeWithDevTools(applyMiddleware(...storeMiddleware))
|
||||
// Use conditional DevTools setup for better compatibility
|
||||
const composeEnhancers =
|
||||
(typeof window !== "undefined" &&
|
||||
(window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
|
||||
compose;
|
||||
|
||||
const appliedMiddleware = applyMiddleware(...storeMiddleware);
|
||||
const enhancer = composeEnhancers(appliedMiddleware);
|
||||
|
||||
store = legacy_createStore<S, A, {}, {}>(
|
||||
rootReducer as Reducer<S, A>,
|
||||
initialState as PreloadedState<S>,
|
||||
enhancer
|
||||
);
|
||||
|
||||
storeSagaMiddleware.run(defaultSaga);
|
||||
@@ -48,5 +64,5 @@ export function configureStore(
|
||||
storeSagaMiddleware.run(sagaMiddleware[i]);
|
||||
}
|
||||
|
||||
return store;
|
||||
return store as Store<S, A>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user