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 onScrollOffsetChange argument from store #136

Merged
merged 1 commit into from
Jul 28, 2023
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
18 changes: 8 additions & 10 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ type Actions =

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

export const UPDATE_SCROLL = 0b001;
export const UPDATE_SIZE = 0b010;
export const UPDATE_JUMP = 0b100;
export const UPDATE_SCROLL = 0b0001;
export const UPDATE_SIZE = 0b0010;
export const UPDATE_JUMP = 0b0100;
export const UPDATE_SCROLL_WITH_EVENT = 0b1000;

export type VirtualStore = {
_getCache(): CacheSnapshot;
Expand Down Expand Up @@ -88,8 +89,7 @@ export const createVirtualStore = (
initialItemCount: number = 0,
isReverse: boolean,
onScrollStateChange: (scrolling: boolean) => void,
cacheSnapshot?: CacheSnapshot,
onScrollOffsetChange?: (offset: number) => void
cacheSnapshot?: CacheSnapshot
): VirtualStore => {
const shouldAutoEstimateItemSize = !itemSize;
const initialItemSize = itemSize || 40;
Expand Down Expand Up @@ -301,11 +301,13 @@ export const createVirtualStore = (
//
// Update synchronously if scrolled a lot
shouldSync = abs(scrollOffset - payload) > viewportSize;

mutated += UPDATE_SCROLL_WITH_EVENT;
}

// Scroll offset may exceed min or max especially in Safari's elastic scrolling.
scrollOffset = max(0, min(getScrollOffsetMax(), payload));
mutated = UPDATE_SCROLL;
mutated += UPDATE_SCROLL;
break;
}
case ACTION_SCROLL_END: {
Expand All @@ -327,10 +329,6 @@ export const createVirtualStore = (
}
cb(shouldSync);
});

if (type === ACTION_SCROLL) {
onScrollOffsetChange && onScrollOffsetChange(scrollOffset);
}
}
if (exists(updatedScrollState)) {
onScrollStateChange(updatedScrollState);
Expand Down
10 changes: 5 additions & 5 deletions src/react/VList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
useEffect,
useState,
} from "react";
import { createVirtualStore } from "../core/store";
import { UPDATE_SCROLL_WITH_EVENT, createVirtualStore } from "../core/store";
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
import { useSelector } from "./useSelector";
import { exists, max, min, values } from "../core/utils";
Expand Down Expand Up @@ -190,11 +190,11 @@
onScrollStop[refKey] && onScrollStop[refKey]();
}
},
cache,
(offset) => {
onScroll[refKey] && onScroll[refKey](offset);
}
cache
);
_store._subscribe(UPDATE_SCROLL_WITH_EVENT, () => {
onScroll[refKey] && onScroll[refKey](store._getScrollOffset());
});

return [
_store,
Expand Down Expand Up @@ -237,7 +237,7 @@
end: endIndex,
count,
});
}, [startIndex, endIndex]);

Check warning on line 240 in src/react/VList.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useEffect has missing dependencies: 'count' and 'onRangeChangeProp'. Either include them or remove the dependency array. If 'onRangeChangeProp' changes too often, find the parent component that defines it and wrap that definition in useCallback

useImperativeHandle(
ref,
Expand All @@ -262,7 +262,7 @@
},
};
},
[]

Check warning on line 265 in src/react/VList.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useImperativeHandle has missing dependencies: 'scroller' and 'store'. Either include them or remove the dependency array
);

const startIndexWithMargin = max(startIndex - overscan, 0);
Expand All @@ -288,7 +288,7 @@
}
}
return res;
}, [elements, startIndexWithMargin, endIndexWithMargin]);

Check warning on line 291 in src/react/VList.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useMemo has missing dependencies: 'isHorizontal', 'isRtl', 'itemElement', 'resizer', and 'store'. Either include them or remove the dependency array

return (
<Window
Expand All @@ -315,7 +315,7 @@
...windowAttrs.style,
},
}),
values(windowAttrs)

Check warning on line 318 in src/react/VList.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useMemo was passed a dependency list that is not an array literal. This means we can't statically verify whether you've passed the correct dependencies
)}
>
{items}
Expand Down
Loading