UNPKG

mobx-keystone-mindreframer

Version:

A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more

71 lines (70 loc) 1.92 kB
import { OnPatchesListener } from "./emitPatch"; import type { Patch } from "./Patch"; /** * Patch recorder event. */ export interface PatchRecorderEvent { /** * Target object. */ readonly target: object; /** * Recorded patches. */ readonly patches: Patch[]; /** * Recorded inverse patches. */ readonly inversePatches: Patch[]; } /** * Patch recorder interface. */ export interface PatchRecorder { /** * Gets/sets if the patch recorder is currently recording. */ recording: boolean; /** * Observable array of patching events. */ readonly events: PatchRecorderEvent[]; /** * Dispose of the patch recorder. */ dispose(): void; } /** * Patch recorder options. */ export interface PatchRecorderOptions { /** * If the patch recorder is initially recording when created. */ recording?: boolean; /** * An optional callback filter to select wich patches to record/skip. * It will be executed before the event is added to the events list. * * @param patches Patches about to be recorded. * @param inversePatches Inverse patches about to be recorded. * @returns `true` to record the patch, `false` to skip it. */ filter?(patches: Patch[], inversePatches: Patch[]): boolean; /** * An optional callback run once a patch is recorded. * It will be executed after the event is added to the events list. * * @param patches Patches just recorded. * @param inversePatches Inverse patches just recorded. */ onPatches?: OnPatchesListener; } /** * Creates a patch recorder. * * @param subtreeRoot * @param [opts] * @returns The patch recorder. */ export declare function patchRecorder(subtreeRoot: object, opts?: PatchRecorderOptions): PatchRecorder;