Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Jul 1, 2023
1 parent 05b7e56 commit 57416e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
ScrollJump,
VirtualStore,
SCROLL_STOP,
ACTION_SCROLL_DIRECTION_CHANGE,
SCROLL_MANUAL,
ACTION_SCROLL_END,
} from "./store";
import { debounce, throttle, max, min } from "./utils";

Expand Down Expand Up @@ -87,7 +86,7 @@ export const createScroller = (

// Scroll with the updated value
scrollTo(getOffset());
store._update(ACTION_SCROLL_DIRECTION_CHANGE, SCROLL_MANUAL);
store._update(ACTION_SCROLL_END, true);
};

return {
Expand All @@ -105,7 +104,7 @@ export const createScroller = (
const onScrollStopped = debounce(() => {
// Check scroll position once just after scrolling stopped
syncViewportToScrollPosition();
store._update(ACTION_SCROLL_DIRECTION_CHANGE, SCROLL_STOP);
store._update(ACTION_SCROLL_END, false);
}, 150);

const onScroll = () => {
Expand Down
12 changes: 7 additions & 5 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export const ACTION_ITEM_RESIZE = 1;
export const ACTION_WINDOW_RESIZE = 2;
export const ACTION_SCROLL = 3;
export const ACTION_MANUAL_SCROLL = 4;
export const ACTION_SCROLL_DIRECTION_CHANGE = 5;
export const ACTION_SCROLL_END = 5;

type Actions =
| [type: typeof ACTION_ITEM_RESIZE, entries: ItemResize[]]
| [type: typeof ACTION_WINDOW_RESIZE, size: number]
| [type: typeof ACTION_SCROLL, offset: number]
| [type: typeof ACTION_MANUAL_SCROLL, offset: number]
| [type: typeof ACTION_SCROLL_DIRECTION_CHANGE, direction: ScrollDirection];
| [type: typeof ACTION_SCROLL_END, isManual: boolean];

type Subscriber = (sync?: boolean) => void;

Expand Down Expand Up @@ -194,7 +194,7 @@ export const createVirtualStore = (
};
_scrollToQueue = [resolveQueue, reject];

// In some specific situation with VGrid, the promise never resolved so we cancel it if timed out.
// In some specific situation with VGrid, the promise never resolved so we cancel it if timed out.
timeout(resolveQueue, 250);
});
},
Expand Down Expand Up @@ -305,8 +305,10 @@ export const createVirtualStore = (
mutated = true;
break;
}
case ACTION_SCROLL_DIRECTION_CHANGE: {
updatedScrollState = updateScrollDirection(payload);
case ACTION_SCROLL_END: {
updatedScrollState = updateScrollDirection(
payload ? SCROLL_MANUAL : SCROLL_STOP
);
break;
}
}
Expand Down

0 comments on commit 57416e5

Please sign in to comment.