UNPKG

tracked-instance

Version:
26 lines (25 loc) 1.12 kB
import { ComputedRef, Ref } from 'vue'; import { DeepPartial } from './utils'; export interface CreateTrackedDataOptions { /** * Custom equality function for comparing primitive values. * When provided, replaces the default strict equality (===) check at leaf comparisons. */ equals?: (a: unknown, b: unknown) => boolean; } export interface TrackedData<Data extends Record<string, any>> { dataRef: Ref<Data>; isDirty: ComputedRef<boolean>; changedData: ComputedRef<DeepPartial<Data>>; loadData: (newValue: Data) => void; reset: () => void; } /** * Builds the full tracking machinery for a single object shape: the deeply-proxied * data ref, the Ledger, and the reactive isDirty / changedData projections. * * Owns the Vue reactivity wiring (shallowRef + triggerRef) for the Ledger so that * every recorded mutation invalidates dependent computeds exactly once. Callers * never see the Ledger or the Proxy directly. */ export declare const createTrackedData: <Data extends Record<string, any>>(initialValue: Data, options?: CreateTrackedDataOptions) => TrackedData<Data>;