feat: following (#22)

This commit is contained in:
patak 2022-11-21 23:59:51 +01:00 committed by GitHub
parent f97920d9d2
commit 9aa7243d43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 5 deletions

View file

@ -4,6 +4,7 @@ import type { PaginatorState } from '~/types'
export function usePaginator<T>(paginator: Paginator<any, T[]>) {
const state = ref<PaginatorState>('idle')
const items = ref<T[]>([])
const newItems = ref<T[]>([])
const endAnchor = ref<HTMLDivElement>()
const bound = reactive(useElementBounding(endAnchor))
@ -19,7 +20,8 @@ export function usePaginator<T>(paginator: Paginator<any, T[]>) {
const result = await paginator.next()
if (result.value?.length) {
items.value.push(...result.value)
newItems.value = result.value
items.value.push(...newItems.value)
state.value = 'idle'
}
else {
@ -50,6 +52,7 @@ export function usePaginator<T>(paginator: Paginator<any, T[]>) {
return {
items,
newItems,
state,
error,
endAnchor,