chore: rename variable

This commit is contained in:
Michael Brevard 2024-06-20 09:37:55 +03:00 committed by GitHub
parent 0919a82a75
commit f47b0d6c4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,20 +26,20 @@ export const createLazyIOComponent = (componentLoader: Component) => {
const nuxt = useNuxtApp() const nuxt = useNuxtApp()
const instance = getCurrentInstance()! const instance = getCurrentInstance()!
const isIntersecting = ref(false) const hasIntersected = ref(false)
const el: Ref<Element | null> = ref(null) const el: Ref<Element | null> = ref(null)
let unobserve: (() => void) | null = null let unobserve: (() => void) | null = null
// todo can be refactored // todo can be refactored
if (instance.vnode.el && nuxt.isHydrating) { if (instance.vnode.el && nuxt.isHydrating) {
isIntersecting.value = elementIsVisibleInViewport(instance.vnode.el as Element) hasIntersected.value = elementIsVisibleInViewport(instance.vnode.el as Element)
} }
if (!isIntersecting.value) { if (!hasIntersected.value) {
onMounted(() => { onMounted(() => {
const observer = useIntersectionObserver(attrs.loader as Partial<IntersectionObserverInit> | undefined) const observer = useIntersectionObserver(attrs.loader as Partial<IntersectionObserverInit> | undefined)
unobserve = observer!.observe(el.value as Element, () => { unobserve = observer!.observe(el.value as Element, () => {
isIntersecting.value = true hasIntersected.value = true
unobserve?.() unobserve?.()
unobserve = null unobserve = null
}) })
@ -51,7 +51,7 @@ export const createLazyIOComponent = (componentLoader: Component) => {
}) })
return () => { return () => {
return h('div', { ref: el }, [ return h('div', { ref: el }, [
isIntersecting.value ? h(componentLoader, attrs) : (instance.vnode.el && nuxt.isHydrating) ? createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1) : null, hasIntersected.value ? h(componentLoader, attrs) : (instance.vnode.el && nuxt.isHydrating) ? createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1) : null,
]) ])
} }
}, },