UNPKG

@mui/x-data-grid-pro

Version:

The Pro plan edition of the MUI X Data Grid components.

34 lines 1.14 kB
import { fastArrayCompare } from '@mui/x-internals/fastArrayCompare'; /** * Holds the grid-level `+N` overflow chip metrics. Written by the single `GridMultiSelectMeasurer` * and read by every multiSelect chip cell via `useSyncExternalStore`. */ export class GridMultiSelectCache { overflowMetrics = null; metricsSubscribers = new Set(); notifyMetrics = metrics => { this.metricsSubscribers.forEach(cb => cb(metrics)); }; getOverflowMetrics = () => { return this.overflowMetrics; }; setOverflowMetrics = next => { // Skip no-op updates so subscribed cells don't re-render on every measurer ResizeObserver tick. const prev = this.overflowMetrics; if (prev && prev.gap === next.gap && fastArrayCompare(prev.overflowChipWidths, next.overflowChipWidths)) { return; } this.overflowMetrics = next; this.notifyMetrics(next); }; subscribeOverflowMetrics = callback => { this.metricsSubscribers.add(callback); return () => { this.metricsSubscribers.delete(callback); }; }; teardown = () => { this.metricsSubscribers.clear(); this.overflowMetrics = null; }; }