mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-11-19 17:25:59 +03:00
* Replace Action<unknown> with Action<string> In anticipation of Redux 5 type changes * Fix lint errors * Create yellow-steaks-marry.md
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { Action } from 'redux';
|
|
import { DevtoolsInspectorProps } from './DevtoolsInspector';
|
|
|
|
const UPDATE_MONITOR_STATE =
|
|
'@@redux-devtools-inspector-monitor/UPDATE_MONITOR_STATE';
|
|
|
|
export interface UpdateMonitorStateAction {
|
|
type: typeof UPDATE_MONITOR_STATE;
|
|
monitorState: Partial<DevtoolsInspectorState>;
|
|
}
|
|
export function updateMonitorState(
|
|
monitorState: Partial<DevtoolsInspectorState>,
|
|
): UpdateMonitorStateAction {
|
|
return { type: UPDATE_MONITOR_STATE, monitorState };
|
|
}
|
|
|
|
export type DevtoolsInspectorAction = UpdateMonitorStateAction;
|
|
|
|
export interface DevtoolsInspectorState {
|
|
selectedActionId: number | null;
|
|
startActionId: number | null;
|
|
inspectedActionPath: (string | number)[];
|
|
inspectedStatePath: (string | number)[];
|
|
tabName: string;
|
|
searchValue?: string;
|
|
}
|
|
|
|
export const DEFAULT_STATE: DevtoolsInspectorState = {
|
|
selectedActionId: null,
|
|
startActionId: null,
|
|
inspectedActionPath: [],
|
|
inspectedStatePath: [],
|
|
tabName: 'Diff',
|
|
};
|
|
|
|
function reduceUpdateState(
|
|
state: DevtoolsInspectorState,
|
|
action: DevtoolsInspectorAction,
|
|
) {
|
|
return action.type === UPDATE_MONITOR_STATE
|
|
? {
|
|
...state,
|
|
...action.monitorState,
|
|
}
|
|
: state;
|
|
}
|
|
|
|
export function reducer<S, A extends Action<string>>(
|
|
props: DevtoolsInspectorProps<S, A>,
|
|
state = DEFAULT_STATE,
|
|
action: DevtoolsInspectorAction,
|
|
) {
|
|
return {
|
|
...reduceUpdateState(state, action),
|
|
};
|
|
}
|