@datorama/akita
Version:
State Management Tailored-Made for JS Applications
49 lines (48 loc) • 1.41 kB
TypeScript
import { AkitaPlugin, Queries } from '../plugin';
export interface StateHistoryParams {
maxAge?: number;
comparator?: (prevState: any, currentState: any) => boolean;
}
export declare type History<State> = {
past: State[];
present: State | null;
future: State[];
};
export declare class StateHistoryPlugin<State = any> extends AkitaPlugin<State> {
protected query: Queries<State>;
private params;
private _entityId?;
/** Allow skipping an update from outside */
private skip;
private history;
/** Skip the update when redo/undo */
private skipUpdate;
private subscription;
constructor(query: Queries<State>, params?: StateHistoryParams, _entityId?: any);
readonly hasPast: boolean;
readonly hasFuture: boolean;
activate(): void;
undo(): void;
redo(): void;
jumpToPast(index: number): void;
jumpToFuture(index: number): void;
/**
* Clear the history
*
* @param customUpdateFn Callback function for only clearing part of the history
*
* @example
*
* stateHistory.clear((history) => {
* return {
* past: history.past,
* present: history.present,
* future: []
* };
* });
*/
clear(customUpdateFn?: (history: History<State>) => History<State>): void;
destroy(clearHistory?: boolean): void;
ignoreNext(): void;
private update;
}