Skip to content

Commit

Permalink
refactor(types): remove unnecessary type generics
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed May 30, 2021
1 parent 89cc49c commit 8defe38
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-shrimps-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-virtual": patch
---

refactor(types): remove unnecessary type generics
14 changes: 7 additions & 7 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ export interface Measure {
// External
export type SsrItemCount = number | [number, number];

export type UseIsScrolling = boolean | ((speed: number) => boolean);
type UseIsScrolling = boolean | ((speed: number) => boolean);

export type ItemSize = number | ((index: number, width: number) => number);
type ItemSize = number | ((index: number, width: number) => number);

export interface ScrollEasingFunction {
interface ScrollEasingFunction {
(time: number): number;
}

export interface KeyExtractor {
(index: number): string;
}

export interface IsItemLoaded {
interface IsItemLoaded {
(index: number): boolean;
}

export interface LoadMore {
interface LoadMore {
(event: {
startIndex: number;
stopIndex: number;
Expand All @@ -38,7 +38,7 @@ export interface LoadMore {
}): void;
}

export interface OnScroll {
interface OnScroll {
(event: {
overscanStartIndex: number;
overscanStopIndex: number;
Expand All @@ -50,7 +50,7 @@ export interface OnScroll {
}): void;
}

export interface OnResize {
interface OnResize {
(event: { width: number; height: number }): void;
}

Expand Down
24 changes: 8 additions & 16 deletions src/useVirtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@ import { useCallback, useRef, useState } from "react";
import {
Align,
Item,
IsItemLoaded,
ItemSize,
KeyExtractor,
LoadMore,
Measure,
OnScroll,
OnResize,
Options,
Return,
ScrollEasingFunction,
ScrollTo,
ScrollToOptions,
ScrollToItem,
ScrollToItemOptions,
SsrItemCount,
UseIsScrolling,
} from "./types";
import {
easeInOutCubic,
Expand Down Expand Up @@ -97,15 +90,14 @@ export default <
const msDataRef = useRef<Measure[]>([]);
const userScrollRef = useRef(true);
const scrollToRafRef = useRef<number>();
const isItemLoadedRef = useRef<IsItemLoaded | undefined>(isItemLoaded);
const loadMoreRef = useLatest<LoadMore | undefined>(loadMore);
const easingFnRef = useLatest<ScrollEasingFunction>(scrollEasingFunction);
const keyExtractorRef = useLatest<KeyExtractor | undefined>(keyExtractor);
const itemSizeRef = useLatest<ItemSize>(itemSize);
const useIsScrollingRef =
useLatest<UseIsScrolling | undefined>(useIsScrolling);
const onScrollRef = useLatest<OnScroll | undefined>(onScroll);
const onResizeRef = useLatest<OnResize | undefined>(onResize);
const isItemLoadedRef = useRef(isItemLoaded);
const loadMoreRef = useLatest(loadMore);
const easingFnRef = useLatest(scrollEasingFunction);
const keyExtractorRef = useLatest(keyExtractor);
const itemSizeRef = useLatest(itemSize);
const useIsScrollingRef = useLatest(useIsScrolling);
const onScrollRef = useLatest(onScroll);
const onResizeRef = useLatest(onResize);
const sizeKey = !horizontal ? "height" : "width";
const itemSizeKey = !horizontal ? "blockSize" : "inlineSize";
const marginKey = !horizontal ? "marginTop" : "marginLeft";
Expand Down

0 comments on commit 8defe38

Please sign in to comment.