Skip to content

Commit

Permalink
Add debounce for NAD mutations observer (#118)
Browse files Browse the repository at this point in the history
* Add debounce for NAD mutations observer
* add comment

Signed-off-by: Seddik Yengui <seddik.yengui_externe@rte-france.com>
  • Loading branch information
YenguiSeddik authored Dec 6, 2024
1 parent 404922e commit d22a72b
Showing 1 changed file with 6 additions and 1 deletion.
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

0 comments on commit d22a72b

Please sign in to comment.