mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-27 08:30:02 +03:00
Fix redux-devtools-app build
This commit is contained in:
parent
e0d25d4087
commit
1b29f90cf2
|
@ -1,7 +1,7 @@
|
||||||
import { stringifyJSON } from '../utils/stringifyJSON';
|
import { stringifyJSON } from '../utils/stringifyJSON';
|
||||||
import { UPDATE_STATE, LIFTED_ACTION, EXPORT } from '../constants/actionTypes';
|
import { UPDATE_STATE, LIFTED_ACTION, EXPORT } from '../constants/actionTypes';
|
||||||
import { getActiveInstance } from '../reducers/instances';
|
import { getActiveInstance } from '../reducers/instances';
|
||||||
import { Dispatch, MiddlewareAPI } from 'redux';
|
import { Dispatch, Middleware } from 'redux';
|
||||||
import { CoreStoreAction } from '../actions';
|
import { CoreStoreAction } from '../actions';
|
||||||
import { CoreStoreState } from '../reducers';
|
import { CoreStoreState } from '../reducers';
|
||||||
|
|
||||||
|
@ -22,12 +22,15 @@ function download(state: string) {
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const exportStateMiddleware =
|
export const exportStateMiddleware: Middleware<
|
||||||
(store: MiddlewareAPI<Dispatch<CoreStoreAction>, CoreStoreState>) =>
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||||
(next: Dispatch<CoreStoreAction>) =>
|
{},
|
||||||
(action: CoreStoreAction) => {
|
CoreStoreState,
|
||||||
const result = next(action);
|
Dispatch<CoreStoreAction>
|
||||||
|
> = (store) => (next) => (untypedAction) => {
|
||||||
|
const result = next(untypedAction);
|
||||||
|
|
||||||
|
const action = untypedAction as CoreStoreAction;
|
||||||
if (
|
if (
|
||||||
toExport &&
|
toExport &&
|
||||||
action.type === UPDATE_STATE &&
|
action.type === UPDATE_STATE &&
|
||||||
|
@ -53,13 +56,11 @@ export const exportStateMiddleware =
|
||||||
const instanceId = getActiveInstance(instances);
|
const instanceId = getActiveInstance(instances);
|
||||||
const options = instances.options[instanceId];
|
const options = instances.options[instanceId];
|
||||||
if (options.features.export === true) {
|
if (options.features.export === true) {
|
||||||
download(
|
download(stringifyJSON(instances.states[instanceId], options.serialize));
|
||||||
stringifyJSON(instances.states[instanceId], options.serialize),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
toExport = instanceId;
|
toExport = instanceId;
|
||||||
next({ type: LIFTED_ACTION, message: 'EXPORT', toExport: true });
|
next({ type: LIFTED_ACTION, message: 'EXPORT', toExport: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
} from '@redux-devtools/app-core';
|
} from '@redux-devtools/app-core';
|
||||||
import socketClusterClient, { AGClientSocket } from 'socketcluster-client';
|
import socketClusterClient, { AGClientSocket } from 'socketcluster-client';
|
||||||
import { stringify } from 'jsan';
|
import { stringify } from 'jsan';
|
||||||
import { Dispatch, MiddlewareAPI } from 'redux';
|
import { Dispatch, Middleware, MiddlewareAPI } from 'redux';
|
||||||
import * as actions from '../constants/socketActionTypes';
|
import * as actions from '../constants/socketActionTypes';
|
||||||
import { nonReduxDispatch } from '../utils/monitorActions';
|
import { nonReduxDispatch } from '../utils/monitorActions';
|
||||||
import { EmitAction, StoreAction } from '../actions';
|
import { EmitAction, StoreAction } from '../actions';
|
||||||
|
@ -266,10 +266,15 @@ function getReport(reportId: unknown) {
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function api(inStore: MiddlewareAPI<Dispatch<StoreAction>, StoreState>) {
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||||
|
export const api: Middleware<{}, StoreState, Dispatch<StoreAction>> = (
|
||||||
|
inStore,
|
||||||
|
) => {
|
||||||
store = inStore;
|
store = inStore;
|
||||||
return (next: Dispatch<StoreAction>) => (action: StoreAction) => {
|
return (next) => (untypedAction) => {
|
||||||
const result = next(action);
|
const result = next(untypedAction);
|
||||||
|
|
||||||
|
const action = untypedAction as StoreAction;
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actions.CONNECT_REQUEST:
|
case actions.CONNECT_REQUEST:
|
||||||
connect();
|
connect();
|
||||||
|
@ -299,4 +304,4 @@ export function api(inStore: MiddlewareAPI<Dispatch<StoreAction>, StoreState>) {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
|
@ -2,15 +2,13 @@ import { CoreStoreState, coreReducers } from '@redux-devtools/app-core';
|
||||||
import { combineReducers } from 'redux';
|
import { combineReducers } from 'redux';
|
||||||
import { connection, ConnectionState } from './connection';
|
import { connection, ConnectionState } from './connection';
|
||||||
import { socket, SocketState } from './socket';
|
import { socket, SocketState } from './socket';
|
||||||
import { StoreAction } from '../actions';
|
|
||||||
|
|
||||||
export interface StoreState extends CoreStoreState {
|
export interface StoreState extends CoreStoreState {
|
||||||
readonly connection: ConnectionState;
|
readonly connection: ConnectionState;
|
||||||
readonly socket: SocketState;
|
readonly socket: SocketState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @ts-expect-error An error happens due to TypeScript not being able to reconcile a clash between CoreStoreAction and StoreAction in the core reducers, but this is correct as they're a superset
|
export const rootReducer = combineReducers({
|
||||||
export const rootReducer = combineReducers<StoreState, StoreAction>({
|
|
||||||
...coreReducers,
|
...coreReducers,
|
||||||
connection,
|
connection,
|
||||||
socket,
|
socket,
|
||||||
|
|
|
@ -14,7 +14,7 @@ const persistConfig = {
|
||||||
|
|
||||||
const persistedReducer: Reducer<StoreState, StoreAction> = persistReducer(
|
const persistedReducer: Reducer<StoreState, StoreAction> = persistReducer(
|
||||||
persistConfig,
|
persistConfig,
|
||||||
rootReducer,
|
rootReducer as unknown as Reducer<StoreState, StoreAction>,
|
||||||
) as any;
|
) as any;
|
||||||
|
|
||||||
export default function configureStore(
|
export default function configureStore(
|
||||||
|
@ -41,7 +41,7 @@ export default function configureStore(
|
||||||
persistedReducer,
|
persistedReducer,
|
||||||
composeEnhancers(applyMiddleware(...middlewares, api)),
|
composeEnhancers(applyMiddleware(...middlewares, api)),
|
||||||
);
|
);
|
||||||
const persistor = persistStore(store, null, () => {
|
const persistor = persistStore(store as Store, null, () => {
|
||||||
callback(store);
|
callback(store);
|
||||||
});
|
});
|
||||||
return { store, persistor };
|
return { store, persistor };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user