useDividerResizeSync.tsx 907 B

123456789101112131415161718192021222324
  1. import {useLayoutEffect} from 'react';
  2. import type {TraceScheduler} from './traceRenderers/traceScheduler';
  3. import {useTraceStateDispatch} from './traceState/traceStateProvider';
  4. // Observer around the divider resize event. This exists because we dont want to
  5. // dispatch a trace action for every single divider resize event (mousemove), and
  6. // instead only want to dispatch it when the resizing is done.
  7. export function useDividerResizeSync(traceScheduler: TraceScheduler) {
  8. const traceDispatch = useTraceStateDispatch();
  9. useLayoutEffect(() => {
  10. function onDividerResizeEnd(list_width: number) {
  11. traceDispatch({
  12. type: 'set list width',
  13. payload: list_width,
  14. });
  15. }
  16. traceScheduler.on('divider resize end', onDividerResizeEnd);
  17. return () => {
  18. traceScheduler.off('divider resize end', onDividerResizeEnd);
  19. };
  20. }, [traceScheduler, traceDispatch]);
  21. }