Skip to content

Commit

Permalink
revert perf suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Nov 13, 2024
1 parent 930746f commit a070ed6
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions packages/x-charts/src/hooks/useAxisEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,24 @@ export const useAxisEvents = (disableAxisListener: boolean) => {
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);

store.update((prev) => {
const newState = structuredClone(prev);

if (
prev.interaction.axis.x?.index !== newStateX?.index ||
prev.interaction.axis.x?.value !== newStateX?.value
) {
newState.interaction.axis.x = newStateX;
}
if (
prev.interaction.axis.y?.index !== newStateY?.index ||
prev.interaction.axis.y?.value !== newStateY?.value
) {
newState.interaction.axis.y = newStateY;
}
return newState;
});
store.update((prev) => ({
...prev,
interaction: {
...prev.interaction,
axis: {
// A bit verbose, but prevent losing the x value if only y got modified.
...prev.interaction.axis,
...(prev.interaction.axis.x?.index !== newStateX?.index ||
prev.interaction.axis.x?.value !== newStateX?.value
? { x: newStateX }
: {}),
...(prev.interaction.axis.y?.index !== newStateY?.index ||
prev.interaction.axis.y?.value !== newStateY?.value
? { y: newStateY }
: {}),
},
},
}));
};

const handleDown = (event: PointerEvent) => {
Expand Down

0 comments on commit a070ed6

Please sign in to comment.