import type { Dispatch } from 'react'; import type { BaseAction, PersistentStateReducerHook, StateReducerHook } from './usePersistentStateReducer'; declare const UNDO_ACTION_TYPE: "undo"; declare const REDO_ACTION_TYPE: "redo"; declare const RESET_ACTION_TYPE: "reset"; export interface UndoAction extends BaseAction { type: typeof UNDO_ACTION_TYPE; } export interface RedoAction extends BaseAction { type: typeof REDO_ACTION_TYPE; } export interface ResetAction extends BaseAction { type: typeof RESET_ACTION_TYPE; } export declare type TimeTravelAction = UndoAction | RedoAction | ResetAction; interface Timeline { present: S; /** States that led to present state. */ past: S[]; /** * Undoing a state makes present state first future state, * and last past state the present. */ future: S[]; } declare type TimeTravelingPersistentStateReducerHookParams = [ /** How far back to allow the state to be rewound. */ maxHistorySteps: number, /** Persistent reducer hook iplementation to delegate to. */ usePersistentReducer: PersistentStateReducerHook, A | TimeTravelAction>, /** Each component should specify a unique storage key. */ storageKey: string, /** * Calls to store state will be debounced according to this delay * in case state change too often. */ storageDebounceMS?: number, validateLoadedState?: (loadedValue: any) => loadedValue is S, ...stateReducerHookArgs: Parameters> ]; export declare type TimeTravelingPersistentStateReducerHook = (...args: TimeTravelingPersistentStateReducerHookParams) => TimeTravelingPersistentStateReducerInterface; interface TimeTravelingPersistentStateReducerInterface { /** Present state. */ state: S; /** Supports actions by wrapped reduce, and time-traveling actions below. */ dispatch: Dispatch; /** * Go to previous state in the timeline; * present state will become next “future” state. */ undo: () => void; /** Makes next (if any) “future” state in the timeline present. */ redo: () => void; /** * Resetting rewinds the timeline back to the beginning. * All states are future states. * Redoing is still possible (in that sense it’s not a proper reset). */ reset: () => void; /** State change history. */ timeline: Timeline; /** Proxied from persistent reducer. */ initialized: boolean; } /** * Supports persistent state reducer features, * but also offers time travel through undo/redo/reset actions. */ export declare function useTimeTravelingPersistentStateReducer(...args: TimeTravelingPersistentStateReducerHookParams): TimeTravelingPersistentStateReducerInterface; export default useTimeTravelingPersistentStateReducer; export declare const initialHook: TimeTravelingPersistentStateReducerHook;