Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debounce for NAD mutations observer #118

Merged
merged 8 commits into from
Dec 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SvgParameters } from './svg-parameters';
import { LayoutParameters } from './layout-parameters';
import { DiagramMetadata, EdgeMetadata, BusNodeMetadata, NodeMetadata, TextNodeMetadata } from './diagram-metadata';
import { CSS_DECLARATION, CSS_RULE, THRESHOLD_STATUS, DEFAULT_DYNAMIC_CSS_RULES } from './dynamic-css-utils';
import { debounce } from '@mui/material';

type DIMENSIONS = { width: number; height: number; viewbox: VIEWBOX };
type VIEWBOX = { x: number; y: number; width: number; height: number };
Expand Down Expand Up @@ -293,7 +294,11 @@ export class NetworkAreaDiagramViewer {
}
}
};
const observer = new MutationObserver(observerCallback);

// Create a debounced version of the observer callback to limit the frequency of calls when the 'viewBox' attribute changes,
// particularly during zooming operations, improving performance and avoiding redundant updates.
const debouncedObserverCallback = debounce(observerCallback, 50);
const observer = new MutationObserver(debouncedObserverCallback);
observer.observe(targetNode, { attributeFilter: ['viewBox'] });
}

Expand Down
Loading