mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-24 18:26:17 +03: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'
|
import type { PaginatorState } from '~/types'
|
||||||
|
|
||||||
export function usePaginator<T, P, U = T>(
|
export function usePaginator<T, P, U = T>(
|
||||||
paginator: Paginator<T[], P>,
|
_paginator: Paginator<T[], P>,
|
||||||
stream?: Promise<WsEvents>,
|
stream?: Promise<WsEvents>,
|
||||||
eventType: 'notification' | 'update' = 'update',
|
eventType: 'notification' | 'update' = 'update',
|
||||||
preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[],
|
preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[],
|
||||||
buffer = 10,
|
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 state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
|
||||||
const items = ref<U[]>([])
|
const items = ref<U[]>([])
|
||||||
const nextItems = ref<U[]>([])
|
const nextItems = ref<U[]>([])
|
||||||
|
|
Loading…
Reference in a new issue