mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
refactor: improve internal type definitions of <NuxtLink>
(#9869)
This commit is contained in:
parent
6c32a6087b
commit
9de94c21cf
@ -180,7 +180,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
if (shouldPrefetch) {
|
if (shouldPrefetch) {
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
let idleId: number
|
let idleId: number
|
||||||
let unobserve: Function | null = null
|
let unobserve: (() => void)| null = null
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const observer = useObserver()
|
const observer = useObserver()
|
||||||
onNuxtReady(() => {
|
onNuxtReady(() => {
|
||||||
@ -268,8 +268,10 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
|||||||
export default defineNuxtLink({ componentName: 'NuxtLink' })
|
export default defineNuxtLink({ componentName: 'NuxtLink' })
|
||||||
|
|
||||||
// --- Prefetching utils ---
|
// --- Prefetching utils ---
|
||||||
|
type CallbackFn = () => void
|
||||||
|
type ObserveFn = (element: Element, callback: CallbackFn) => () => void
|
||||||
|
|
||||||
function useObserver () {
|
function useObserver (): { observe: ObserveFn } | undefined {
|
||||||
if (process.server) { return }
|
if (process.server) { return }
|
||||||
|
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
@ -278,10 +280,10 @@ function useObserver () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let observer: IntersectionObserver | null = null
|
let observer: IntersectionObserver | null = null
|
||||||
type CallbackFn = () => void
|
|
||||||
const callbacks = new Map<Element, CallbackFn>()
|
const callbacks = new Map<Element, CallbackFn>()
|
||||||
|
|
||||||
const observe = (element: Element, callback: CallbackFn) => {
|
const observe: ObserveFn = (element, callback) => {
|
||||||
if (!observer) {
|
if (!observer) {
|
||||||
observer = new IntersectionObserver((entries) => {
|
observer = new IntersectionObserver((entries) => {
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
|
Loading…
Reference in New Issue
Block a user