1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-19 23:40:07 +00:00

fix: paginator state lost after HMR

This commit is contained in:
三咲智子 2023-01-10 01:43:28 +08:00
parent 56ab163369
commit 0a75205309
No known key found for this signature in database
GPG key ID: 69992F2250DFD93E

View file

@ -1,13 +1,20 @@
import type { Paginator, WsEvents, mastodon } from 'masto'
import { Paginator } from 'masto'
import type { WsEvents, mastodon } from 'masto'
import type { PaginatorState } from '~/types'
export function usePaginator<T, P, U = T>(
paginator: Paginator<T[], P>,
_paginator: Paginator<T[], P>,
stream?: Promise<WsEvents>,
eventType: 'notification' | 'update' = 'update',
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
// so clone it
// @ts-expect-error clone it
const paginator: Paginator<T[], P> = new Paginator(_paginator.http, _paginator.nextPath, _paginator.nextParams)
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
const items = ref<U[]>([])
const nextItems = ref<U[]>([])