redux-devtools/packages/redux-devtools-inspector-monitor/src/redux.ts
Nathan Bierema ee52c29a8d
chore(core): convert to TypeScript (#655)
* Get started

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash

* stash
2020-10-25 19:32:04 -04:00

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<unknown>>(
props: DevtoolsInspectorProps<S, A>,
state = DEFAULT_STATE,
action: DevtoolsInspectorAction
) {
return {
...reduceUpdateState(state, action),
};
}