UNPKG

@infinite-canvas-tutorial/webcomponents

Version:
49 lines (48 loc) 2.31 kB
/** * Borrow from https://github.com/excalidraw/excalidraw/blob/master/packages/excalidraw/change.ts#L62 */ /** * Represents the difference between two objects of the same type. * * Both `deleted` and `inserted` partials represent the same set of added, removed or updated properties, where: * - `deleted` is a set of all the deleted values * - `inserted` is a set of all the inserted (added, updated) values * * Keeping it as pure object (without transient state, side-effects, etc.), so we won't have to instantiate it on load. */ export declare class Delta<T> { readonly deleted: Partial<T>; readonly inserted: Partial<T>; private constructor(); static create<T>(deleted: Partial<T>, inserted: Partial<T>, modifier?: (delta: Partial<T>) => Partial<T>, modifierOptions?: 'deleted' | 'inserted'): Delta<T>; /** * Calculates the delta between two objects. * * @param prevObject - The previous state of the object. * @param nextObject - The next state of the object. * * @returns new delta instance. */ static calculate<T extends { [key: string]: any; }>(prevObject: T, nextObject: T, modifier?: (partial: Partial<T>) => Partial<T>, postProcess?: (deleted: Partial<T>, inserted: Partial<T>) => [Partial<T>, Partial<T>]): Delta<T>; static empty(): Delta<unknown>; static isEmpty<T>(delta: Delta<T>): boolean; /** * Iterator comparing values of object properties based on the passed joining strategy. * * @yields keys of properties with different values * * WARN: it's based on shallow compare performed only on the first level and doesn't go deeper than that. */ private static distinctKeysIterator; } /** * Returns whether object/array is shallow equal. * Considers empty object/arrays as equal (whether top-level or second-level). */ export declare const isShallowEqual: <T extends Record<string, any>, K extends readonly unknown[]>(objA: T, objB: T, comparators?: { [key in keyof T]?: (a: T[key], b: T[key]) => boolean; } | (keyof T extends K[number] ? K extends readonly (keyof T)[] ? K : { _error: "keys are either missing or include keys not in compared obj"; } : { _error: "keys are either missing or include keys not in compared obj"; }), debug?: boolean) => boolean;