diff --git a/composables/paginator.ts b/composables/paginator.ts index 3e78f0b9..2b85bb16 100644 --- a/composables/paginator.ts +++ b/composables/paginator.ts @@ -1,16 +1,16 @@ -import type { Paginator, WsEvents } from 'masto' +import type { Paginator, WsEvents, mastodon } from 'masto' import type { PaginatorState } from '~/types' export function usePaginator( paginator: Paginator, stream?: Promise, eventType: 'notification' | 'update' = 'update', - preprocess: (items: T[]) => U[] = (items: T[]) => items as unknown as U[], + preprocess: (items: T[]) => U[] = items => items as unknown as U[], buffer = 10, ) { const state = ref(isMastoInitialised.value ? 'idle' : 'loading') - const items = ref([]) - const nextItems = ref([]) + const items = ref([]) + const nextItems = ref([]) const prevItems = ref([]) const endAnchor = ref() @@ -20,7 +20,7 @@ export function usePaginator( const deactivated = useDeactivated() async function update() { - items.value.unshift(...preprocess(prevItems.value as any) as any) + (items.value as U[]).unshift(...preprocess(prevItems.value as T[])) prevItems.value = [] } @@ -40,17 +40,19 @@ export function usePaginator( s.on('status.update', (status) => { cacheStatus(status, undefined, true) - const index = items.value.findIndex((s: any) => s.id === status.id) + const data = items.value as mastodon.v1.Status[] + const index = data.findIndex(s => s.id === status.id) if (index >= 0) - items.value[index] = status as any + data[index] = status }) s.on('delete', (id) => { removeCachedStatus(id) - const index = items.value.findIndex((s: any) => s.id === id) + const data = items.value as mastodon.v1.Status[] + const index = data.findIndex(s => s.id === id) if (index >= 0) - items.value.splice(index, 1) + data.splice(index, 1) }) })