From 0a75205309e8a70860123ffaa4f0e446028a6341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 10 Jan 2023 01:43:28 +0800 Subject: [PATCH] fix: paginator state lost after HMR --- composables/paginator.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/composables/paginator.ts b/composables/paginator.ts index 3b6c4e84..5c4300a0 100644 --- a/composables/paginator.ts +++ b/composables/paginator.ts @@ -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( - paginator: Paginator, + _paginator: Paginator, stream?: Promise, 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 = new Paginator(_paginator.http, _paginator.nextPath, _paginator.nextParams) + const state = ref(isMastoInitialised.value ? 'idle' : 'loading') const items = ref([]) const nextItems = ref([])