-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix(usePagination): fix not using initialPage as a baseline when watc… #41
base: main
Are you sure you want to change the base?
Conversation
…h changes and changing isLastPage status
在自定义initialPage的值时,会导致isLastPage的值变化不正确;在状监听筛选条件时也会导致类似的问题。 |
预加载缓存时也会有同样的问题。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
还是非常感谢你的贡献🤞😁,可以对代码review里的问题稍微解释一下吗?
如果能加上对应的单元测试用例就更好了,usePagination
的单元测试分别在packages\scene-vue\test\usePagination.spec.js
和packages\scene-react\test\functions.spec.tsx
都有,可以同步添加一下
@@ -162,7 +162,7 @@ export default function ( | |||
|
|||
const pageCountVal = _$(pageCount); | |||
const exceedPageCount = pageCountVal | |||
? preloadPage > pageCountVal | |||
? preloadPage - initialPage + 1 > pageCountVal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没看懂为什么需要preloadPage - initialPage + 1
,我的理解是preloadPage
就是预加载的页数了,应该不再需要通过initialPage
换算了
@@ -196,7 +196,8 @@ export default function ( | |||
const pageVal = _$(page); | |||
const pageCountVal = _$(pageCount); | |||
const dataLen = isArray(statesDataVal) ? len(statesDataVal) : 0; | |||
return pageCountVal ? pageVal >= pageCountVal : dataLen < _$(pageSize); | |||
//Calculate length:currentIndex - startIndex + 1 | |||
return pageCountVal ? pageVal - initialPage + 1 >= pageCountVal : dataLen < _$(pageSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边也没看懂,pageVal
也是当前页的页码了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两个地方这样写的原因是一样的,统一回复一下:我们可以把它看成一个数组,pageVal代表当前数组的下标,现在已知的是数组的第一个下标为initialPage,则计算当前数组的实际位置(以0为基准)的公式为:pageVal- initialPage+ 1。
这里求的是当前下标是否是最后一位,所以如果通过当前数组下标和元素总个数对比,无法获得其实际是否已经到达最后一个元素,需要获得其当前实际位置,并与总个数-1进行对比才能得到当前下标是否实际到数组末尾。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可能这边的理解是不正确的,是否预加载下一页的判断标准就是基于当前页码+1的,而initialPage
其实只是用来初始化page变量的,之后的计算直接使用page
就可以了,例如当initialPage
为2,那么pageVal
的初始值也是2,此时我们只需要判断第3页是否可预加载就可以了,如果按你的公式3-2+1 = 2
去判断第2页是否有数据错误的。你可以再理下看看是这样的吗
我没有学习过JS领域的单元测试框架,如果有时间我之后会尝试学习并编写一些单元测试,在这之前还需要协助。 @JOU-amjs |
…h changes and changing isLastPage status