UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

65 lines (64 loc) 1.79 kB
/** * List reconciler helpers */ /** * Base interface for items that can be reconciled * The actual items don't need to implement this - you provide getId function */ export interface IReconcilableItem { [key: string]: any; } /** * Result of list reconciliation */ export interface IReconcileResult<T> { toCreate: T[]; toUpdate: Array<{ oldItem: T; newItem: T; index: number; }>; toRemove: T[]; unchanged: T[]; } /** * Options for reconciliation */ export interface IReconcileOptions<T> { /** * Custom ID extractor */ getId: (item: T) => unknown; /** * Custom equality check */ isEqual?: (a: T, b: T) => boolean; /** * Preserve order of new items */ preserveOrder?: boolean; } /** * Generic list reconciliation utility * Efficiently compares two lists and determines what items need to be created, updated, or removed */ export declare class ListReconciler { /** * Reconcile two lists by comparing items * @param oldItems - Current items * @param newItems - New items to reconcile with * @param options - Reconciliation options */ static reconcile<T = any>(oldItems: Readonly<T[]>, newItems: Readonly<T[]>, options: IReconcileOptions<T>): IReconcileResult<T>; /** * Apply reconciliation result to a mutable array * @param array - Array to mutate * @param result - Reconciliation result * @param callbacks - Callbacks for each operation */ static applyResult<T = any>(array: T[], result: IReconcileResult<T>, callbacks?: { onCreate?: (item: T, index: number) => void; onUpdate?: (oldItem: T, newItem: T, index: number) => void; onRemove?: (item: T, index: number) => void; }): void; }