Skip to content

Commit

Permalink
Merge pull request #1634 from silx-kit/remove-deb
Browse files Browse the repository at this point in the history
Remove debounce on dimension mapping state to reduce lag
  • Loading branch information
axelboc authored May 6, 2024
2 parents 5e51b1d + 1837222 commit 78e1dda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/app/src/__tests__/DimensionMapper.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { screen, within } from '@testing-library/react';
import { expect, test, vi } from 'vitest';
import { expect, test } from 'vitest';

import { renderApp, waitForAllLoaders } from '../test-utils';
import { Vis } from '../vis-packs/core/visualizations';
Expand Down Expand Up @@ -30,7 +30,7 @@ test('control mapping for X axis when visualizing 2D dataset as Line', async ()

// Change mapping from [0, 'x'] to ['x', 0]
await user.click(xDimsButtons[0]);
await vi.waitFor(() => expect(xDimsButtons[0]).toBeChecked());
expect(xDimsButtons[0]).toBeChecked();
expect(xDimsButtons[1]).not.toBeChecked();

// Ensure that the dimension slider is now for D1
Expand Down Expand Up @@ -63,7 +63,7 @@ test('control mapping for X and Y axes when visualizing 2D dataset as Heatmap',

// Change mapping from ['y', 'x'] to ['x', 'y']
await user.click(xD0Button);
await vi.waitFor(() => expect(xD0Button).toBeChecked());
expect(xD0Button).toBeChecked();
expect(xD1Button).not.toBeChecked();
expect(yD0Button).not.toBeChecked();
expect(yD1Button).toBeChecked();
Expand Down
13 changes: 5 additions & 8 deletions packages/app/src/dimension-mapper/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { useDebouncedState } from '@react-hookz/web';
import { useState } from 'react';

import type { DimensionMapping } from './models';

export function useDimMappingState(dims: number[], axesCount: number) {
return useDebouncedState<DimensionMapping>(
[
...Array.from({ length: dims.length - axesCount }, () => 0),
...['y' as const, 'x' as const].slice(-axesCount),
],
100,
);
return useState<DimensionMapping>([
...Array.from({ length: dims.length - axesCount }, () => 0),
...['y' as const, 'x' as const].slice(-axesCount),
]);
}

0 comments on commit 78e1dda

Please sign in to comment.