refactor: upgrade masto

This commit is contained in:
三咲智子 2023-01-10 14:10:20 +08:00
parent e1332345ad
commit caa02446c7
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E
6 changed files with 34 additions and 25 deletions

View file

@ -1,5 +1,4 @@
import { Paginator } from 'masto'
import type { WsEvents, mastodon } from 'masto'
import type { Paginator, WsEvents, mastodon } from 'masto'
import type { PaginatorState } from '~/types'
export function usePaginator<T, P, U = T>(
@ -9,11 +8,10 @@ export function usePaginator<T, P, U = T>(
preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[],
buffer = 10,
) {
// TODO: wait PR https://github.com/neet/masto.js/pull/801
// called `next` method will mutate the internal state of the variable, and we need its initial state after HMR
// called `next` method will mutate the internal state of the variable,
// and we need its initial state after HMR
// so clone it
// @ts-expect-error clone it
const paginator: Paginator<T[], P> = new Paginator(_paginator.http, _paginator.nextPath, _paginator.nextParams)
const paginator = _paginator.clone()
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
const items = ref<U[]>([])