/** * Memo Utilities * * Comparison helper functions for React.memo optimization. * These functions enable efficient memoization of components * by comparing props at the appropriate depth. * * @since v1.10.0 * @since v1.10.1 - Added tabsEqual, listItemsEqual, notificationsEqual * @since v1.10.2 - Added shortcutsEqual */ import type { UsageStat } from '../../core/tier/usage-service.js'; interface Tab { id: string; label: string; shortcut?: string; } interface Shortcut { key: string; description: string; category?: string; } type NotificationType = 'success' | 'error' | 'warning' | 'info'; interface ListItem { id: string; label: string; description?: string; icon?: string; disabled?: boolean; badge?: string; badgeColor?: string; } /** * Shallow comparison of two objects. * Returns true if all own enumerable properties are strictly equal. * * Use this as the default comparator for components with primitive props. * For components with object/array props, use custom comparators. * * @param prev - Previous props object * @param next - Next props object * @returns true if objects are shallowly equal * * @example * ```typescript * const MemoizedComponent = React.memo(MyComponent, shallowPropsEqual); * ``` */ export declare function shallowPropsEqual>(prev: T, next: T): boolean; /** * Compare two UsageStat objects for equality. * Performs value comparison of used, limit, and remaining properties. * * @param prev - Previous UsageStat * @param next - Next UsageStat * @returns true if stats are equal * * @example * ```typescript * const MemoizedUsageBar = React.memo(UsageBar, (prev, next) => * prev.label === next.label && * prev.width === next.width && * usageStatEqual(prev.stat, next.stat) * ); * ``` */ export declare function usageStatEqual(prev: UsageStat, next: UsageStat): boolean; /** * Shallow comparison of two arrays. * Returns true if arrays have the same length and all elements * are strictly equal (===). * * For arrays of objects, this compares references, not deep equality. * * @param prev - Previous array * @param next - Next array * @returns true if arrays are shallowly equal * * @example * ```typescript * const itemsEqual = areArraysShallowEqual(prev.items, next.items); * ``` */ export declare function areArraysShallowEqual(prev: T[], next: T[]): boolean; /** * Create a comparator for components with a specific object prop. * Compares all primitive props shallowly and uses the provided * comparator for the object prop. * * @param objectPropKey - Key of the object prop * @param objectComparator - Comparator function for the object prop * @returns A comparator function for React.memo * * @example * ```typescript * const usageBarPropsEqual = createObjectPropComparator( * 'stat', * usageStatEqual * ); * const MemoizedUsageBar = React.memo(UsageBar, usageBarPropsEqual); * ``` */ export declare function createObjectPropComparator(objectPropKey: keyof T, objectComparator: (prev: unknown, next: unknown) => boolean): (prev: T, next: T) => boolean; /** * Compare two Tab arrays for equality. * Compares id, label, and shortcut of each tab. * * @param prev - Previous tabs array * @param next - Next tabs array * @returns true if tabs are equal * * @since v1.10.1 * * @example * ```typescript * const MemoizedHeader = React.memo(Header, (prev, next) => * prev.activeTab === next.activeTab && * prev.showHelp === next.showHelp && * tabsEqual(prev.tabs, next.tabs) * ); * ``` */ export declare function tabsEqual(prev: Tab[], next: Tab[]): boolean; /** * Compare two ListItem arrays for equality. * Compares all properties of each item: id, label, description, icon, * disabled, badge, badgeColor. * * @param prev - Previous items array * @param next - Next items array * @returns true if items are equal * * @since v1.10.1 * * @example * ```typescript * const MemoizedList = React.memo(SelectableList, (prev, next) => * prev.selectedIndex === next.selectedIndex && * listItemsEqual(prev.items, next.items) * ); * ``` */ export declare function listItemsEqual(prev: ListItem[], next: ListItem[]): boolean; /** * Notification item for comparison. * Used by NotificationList component. */ export interface NotificationItem { id: string; type: NotificationType; message: string; title?: string; } /** * Compare two notification arrays for equality. * Compares id, type, message, and title of each notification. * * @param prev - Previous notifications array * @param next - Next notifications array * @returns true if notifications are equal * * @since v1.10.1 * * @example * ```typescript * const MemoizedNotificationList = React.memo(NotificationList, (prev, next) => * prev.maxVisible === next.maxVisible && * notificationsEqual(prev.notifications, next.notifications) * ); * ``` */ export declare function notificationsEqual(prev: NotificationItem[], next: NotificationItem[]): boolean; /** * Compare two Shortcut arrays for equality. * Compares key, description, and category of each shortcut. * * @param prev - Previous shortcuts array * @param next - Next shortcuts array * @returns true if shortcuts are equal * * @since v1.10.2 * * @example * ```typescript * const MemoizedHelpOverlay = React.memo(HelpOverlay, (prev, next) => * prev.title === next.title && * prev.onClose === next.onClose && * shortcutsEqual(prev.shortcuts, next.shortcuts) * ); * ``` */ export declare function shortcutsEqual(prev: Shortcut[], next: Shortcut[]): boolean; /** * Compare two table column arrays for equality. * Compares key, header, width, and align of each column. * Note: render functions are compared by reference. * * @param prev - Previous columns array * @param next - Next columns array * @returns true if columns are equal * * @since v1.36.0 */ export declare function tableColumnsEqual(prev: Array<{ key: keyof T | string; header: string; width?: number; align?: string; render?: unknown; }>, next: Array<{ key: keyof T | string; header: string; width?: number; align?: string; render?: unknown; }>): boolean; /** * Compare two data arrays by checking if all row references are the same. * For large datasets, this is more efficient than deep comparison. * * @param prev - Previous data array * @param next - Next data array * @returns true if data arrays have same row references * * @since v1.36.0 */ export declare function tableDataEqual(prev: T[], next: T[]): boolean; export {}; //# sourceMappingURL=memo-utils.d.ts.map