redux-devtools/packages/redux-devtools-log-monitor/src/reducers.ts
Nathan Bierema 65205f9078
Replace Action<unknown> with Action<string> (#1525)
* Replace Action<unknown> with Action<string>

In anticipation of Redux 5 type changes

* Fix lint errors

* Create yellow-steaks-marry.md
2023-11-04 21:04:23 +00:00

48 lines
1.2 KiB
TypeScript

import { Action } from 'redux';
import {
UPDATE_SCROLL_TOP,
START_CONSECUTIVE_TOGGLE,
LogMonitorAction,
} from './actions';
import { LogMonitorProps } from './LogMonitor';
function initialScrollTop<S, A extends Action<string>>(
props: LogMonitorProps<S, A>,
state = 0,
action: LogMonitorAction,
) {
if (!props.preserveScrollTop) {
return 0;
}
return action.type === UPDATE_SCROLL_TOP ? action.scrollTop : state;
}
function startConsecutiveToggle<S, A extends Action<string>>(
props: LogMonitorProps<S, A>,
state: number | null | undefined,
action: LogMonitorAction,
) {
return action.type === START_CONSECUTIVE_TOGGLE ? action.id : state;
}
export interface LogMonitorState {
initialScrollTop: number;
consecutiveToggleStartId: number | null | undefined;
}
export default function reducer<S, A extends Action<string>>(
props: LogMonitorProps<S, A>,
state: Partial<LogMonitorState> = {},
action: LogMonitorAction,
): LogMonitorState {
return {
initialScrollTop: initialScrollTop(props, state.initialScrollTop, action),
consecutiveToggleStartId: startConsecutiveToggle(
props,
state.consecutiveToggleStartId,
action,
),
};
}