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

Remove debounce on dimension mapping state to reduce lag #1634

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
]);
}