-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,9 +83,9 @@ export default function ( | |
return handlerMethod; | ||
}; | ||
|
||
// 监听状态变化时,重置page为1 | ||
// 监听状态变化时,重置page为${initialPage} | ||
watch$(watchingStates, () => { | ||
upd$(page, 1); | ||
upd$(page, initialPage); | ||
isReset.current = trueValue; | ||
}); | ||
|
||
|
@@ -162,7 +162,7 @@ export default function ( | |
|
||
const pageCountVal = _$(pageCount); | ||
const exceedPageCount = pageCountVal | ||
? preloadPage > pageCountVal | ||
? preloadPage - initialPage + 1 > pageCountVal | ||
: isNextPage // 如果是判断预加载下一页数据且没有pageCount的情况下,通过最后一页数据量是否达到pageSize来判断 | ||
? len(listDataGetter(rawData)) < _$(pageSize) | ||
: falseValue; | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 这边也没看懂, There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 可能这边的理解是不正确的,是否预加载下一页的判断标准就是基于当前页码+1的,而 |
||
}, | ||
_expBatch$(page, pageCount, states.data, pageSize), | ||
trueValue | ||
|
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
换算了