Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Jul 27, 2023
1 parent c26d845 commit a368d28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
SCROLL_IDLE,
ACTION_SCROLL_END,
UPDATE_SIZE,
ACTION_MANUAL_SCROLL_END,
} from "./store";
import { debounce, throttle, max, min, timeout } from "./utils";

Expand Down Expand Up @@ -131,7 +132,7 @@ export const createScroller = (

// Scroll with the updated value
rootElement[scrollToKey] = normalizeOffset(getOffset());
store._update(ACTION_SCROLL_END, true);
store._update(ACTION_MANUAL_SCROLL_END);
};

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

const onScroll = () => {
Expand Down Expand Up @@ -220,7 +221,7 @@ export const createWindowScroller = (
const onScrollStopped = debounce(() => {
// Check scroll position once just after scrolling stopped
syncViewportToScrollPosition();
store._update(ACTION_SCROLL_END, false);
store._update(ACTION_SCROLL_END);
}, 150);

const onScroll = () => {
Expand Down
12 changes: 8 additions & 4 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ export const ACTION_WINDOW_RESIZE = 2;
export const ACTION_SCROLL = 3;
export const ACTION_MANUAL_SCROLL = 4;
export const ACTION_SCROLL_END = 5;
export const ACTION_MANUAL_SCROLL_END = 6;

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_END, isManual: boolean];
| [type: typeof ACTION_SCROLL_END, dummy?: void]
| [type: typeof ACTION_MANUAL_SCROLL_END, dummy?: void];

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

Expand Down Expand Up @@ -310,9 +312,11 @@ export const createVirtualStore = (
break;
}
case ACTION_SCROLL_END: {
updatedScrollState = updateScrollDirection(
payload ? SCROLL_MANUAL : SCROLL_IDLE
);
updatedScrollState = updateScrollDirection(SCROLL_IDLE);
break;
}
case ACTION_MANUAL_SCROLL_END: {
updatedScrollState = updateScrollDirection(SCROLL_MANUAL);
break;
}
}
Expand Down

0 comments on commit a368d28

Please sign in to comment.