Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

refactor: improve internal type definitions of <NuxtLink> #9869

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/nuxt/src/app/components/nuxt-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
if (shouldPrefetch) {
const nuxtApp = useNuxtApp()
let idleId: number
let unobserve: Function | null = null
let unobserve: (() => void)| null = null
onMounted(() => {
const observer = useObserver()
onNuxtReady(() => {
Expand Down Expand Up @@ -268,8 +268,10 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
export default defineNuxtLink({ componentName: 'NuxtLink' })

// --- Prefetching utils ---
type CallbackFn = () => void
type ObserveFn = (element: Element, callback: CallbackFn) => () => void

function useObserver () {
function useObserver (): { observe: ObserveFn } | undefined {
if (process.server) { return }

const nuxtApp = useNuxtApp()
Expand All @@ -278,10 +280,10 @@ function useObserver () {
}

let observer: IntersectionObserver | null = null
type CallbackFn = () => void

const callbacks = new Map<Element, CallbackFn>()

const observe = (element: Element, callback: CallbackFn) => {
const observe: ObserveFn = (element, callback) => {
if (!observer) {
observer = new IntersectionObserver((entries) => {
for (const entry of entries) {
Expand Down