mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-04 16:09:59 +00:00
fix: paginator state lost after HMR
This commit is contained in:
parent
56ab163369
commit
0a75205309
1 changed files with 9 additions and 2 deletions
|
@ -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[]>([])
|
||||
|
|
Loading…
Reference in a new issue