mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 00:19:55 +03:00
counter-example
This commit is contained in:
parent
6ba4082b23
commit
ddd2aac69c
|
@ -1,9 +1,14 @@
|
|||
import { combineReducers } from 'redux';
|
||||
import { combineReducers, Reducer } from 'redux';
|
||||
import counter from './counter';
|
||||
import { CounterAction } from '../actions/CounterActions';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
const rootReducer: Reducer<
|
||||
CounterState,
|
||||
CounterAction,
|
||||
Partial<CounterState>
|
||||
> = combineReducers({
|
||||
counter,
|
||||
});
|
||||
}) as any;
|
||||
|
||||
export interface CounterState {
|
||||
counter: number;
|
||||
|
|
|
@ -2,34 +2,40 @@ import {
|
|||
createStore,
|
||||
applyMiddleware,
|
||||
compose,
|
||||
PreloadedState,
|
||||
Reducer,
|
||||
StoreEnhancer,
|
||||
Middleware,
|
||||
} from 'redux';
|
||||
import { persistState } from '@redux-devtools/core';
|
||||
import thunk from 'redux-thunk';
|
||||
import rootReducer, { CounterState } from '../reducers';
|
||||
import DevTools from '../containers/DevTools';
|
||||
import { CounterAction } from '../actions/CounterActions';
|
||||
|
||||
function getDebugSessionKey() {
|
||||
const matches = /[?&]debug_session=([^&#]+)\b/.exec(window.location.href);
|
||||
return matches && matches.length > 0 ? matches[1] : null;
|
||||
}
|
||||
|
||||
const enhancer = compose(
|
||||
applyMiddleware(thunk),
|
||||
const enhancer: StoreEnhancer = compose(
|
||||
applyMiddleware(thunk as unknown as Middleware),
|
||||
DevTools.instrument(),
|
||||
persistState(getDebugSessionKey()),
|
||||
);
|
||||
|
||||
export default function configureStore(
|
||||
initialState?: PreloadedState<CounterState>,
|
||||
) {
|
||||
export default function configureStore(initialState?: Partial<CounterState>) {
|
||||
const store = createStore(rootReducer, initialState, enhancer);
|
||||
|
||||
if (module.hot) {
|
||||
module.hot.accept('../reducers', () =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
store.replaceReducer(require('../reducers').default as Reducer),
|
||||
store.replaceReducer(
|
||||
require('../reducers').default as Reducer<
|
||||
CounterState,
|
||||
CounterAction,
|
||||
Partial<CounterState>
|
||||
>,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { createStore, applyMiddleware, PreloadedState } from 'redux';
|
||||
import { createStore, applyMiddleware, Middleware } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import rootReducer, { CounterState } from '../reducers';
|
||||
|
||||
const enhancer = applyMiddleware(thunk);
|
||||
const enhancer = applyMiddleware(thunk as unknown as Middleware);
|
||||
|
||||
export default function configureStore(
|
||||
initialState?: PreloadedState<CounterState>,
|
||||
) {
|
||||
export default function configureStore(initialState?: Partial<CounterState>) {
|
||||
return createStore(rootReducer, initialState, enhancer);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { PreloadedState, Store } from 'redux';
|
||||
import { Store } from 'redux';
|
||||
import { CounterState } from '../reducers';
|
||||
import { CounterAction } from '../actions/CounterActions';
|
||||
|
||||
const configureStore: (
|
||||
initialState?: PreloadedState<CounterState>,
|
||||
initialState?: Partial<CounterState>,
|
||||
) => Store<CounterState, CounterAction> =
|
||||
process.env.NODE_ENV === 'production'
|
||||
? // eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
|
|
Loading…
Reference in New Issue
Block a user