chore: rename loader to hydrate

This commit is contained in:
tbitw2549 2024-06-22 00:20:01 +03:00
parent 9456f3f12e
commit 70789a0631
7 changed files with 17 additions and 17 deletions

View File

@ -167,14 +167,14 @@ If you would like the component to load after certain events occur, like a click
### Custom hydration triggers
If you would like to override the default hydration triggers when dealing with delayed hydration, like changing the timeout, the options for the intersection observer, or the events to trigger the hydration, you can do so by supplying a `loader` prop to your lazy components.
If you would like to override the default hydration triggers when dealing with delayed hydration, like changing the timeout, the options for the intersection observer, or the events to trigger the hydration, you can do so by supplying a `hydrate` prop to your lazy components.
```vue [pages/index.vue]
<template>
<div>
<LazyIdleMyComponent :loader="createIdleLoader({timeout: 3000})"/>
<LazyVisibleMyComponent :loader="createVisibleLoader({threshold: 0.2})"/>
<LazyEventMyComponent :loader="createEventLoader(['click','mouseover'])"/>
<LazyIdleMyComponent :hydrate="createIdleLoader({timeout: 3000})"/>
<LazyVisibleMyComponent :hydrate="createVisibleLoader({threshold: 0.2})"/>
<LazyEventMyComponent :hydrate="createEventLoader(['click','mouseover'])"/>
</div>
</template>
```

View File

@ -21,7 +21,7 @@ If you would like to trigger hydration when the element is either clicked or has
```vue [pages/index.vue]
<template>
<div>
<LazyEventMyComponent :loader="createEventLoader(['click','mouseover'])"/>
<LazyEventMyComponent :hydrate="createEventLoader(['click','mouseover'])"/>
</div>
<template>
```

View File

@ -21,7 +21,7 @@ If you would like to give a timeout of 5 seconds for the components:
```vue [pages/index.vue]
<template>
<div>
<LazyIdleMyComponent :loader="createIdleLoader({timeout: 3000})"/>
<LazyIdleMyComponent :hydrate="createIdleLoader({timeout: 3000})"/>
</div>
<template>
```

View File

@ -21,7 +21,7 @@ If you would like to change the threshold of the element:
```vue [pages/index.vue]
<template>
<div>
<LazyVisibleMyComponent :loader="createVisibleLoader({threshold: 0.2})"/>
<LazyVisibleMyComponent :hydrate="createVisibleLoader({threshold: 0.2})"/>
</div>
<template>
```

View File

@ -37,7 +37,7 @@ export const createLazyIOComponent = (componentLoader: Component) => {
if (!hasIntersected.value) {
onMounted(() => {
const observer = useIntersectionObserver(attrs.loader as Partial<IntersectionObserverInit> | undefined)
const observer = useIntersectionObserver(attrs.hydrate as Partial<IntersectionObserverInit> | undefined)
unobserve = observer!.observe(el.value as Element, () => {
hasIntersected.value = true
unobserve?.()
@ -76,7 +76,7 @@ export const createLazyNetworkComponent = (componentLoader: Component) => {
isIdle.value = true
cancelIdleCallback(idleHandle as unknown as number)
idleHandle = null
}, attrs.loader ?? { timeout: 10000 })
}, attrs.hydrate ?? { timeout: 10000 })
})
})
onBeforeUnmount(() => {
@ -102,7 +102,7 @@ export const createLazyEventComponent = (componentLoader: Component) => {
const nuxt = useNuxtApp()
const instance = getCurrentInstance()!
const isTriggered = ref(false)
const events: string[] = attrs.loader as string[] ?? ['mouseover']
const events: string[] = attrs.hydrate as string[] ?? ['mouseover']
const registeredEvents: (() => void)[] = []
if (!eventsMapper.has(instance)) {

View File

@ -119,9 +119,9 @@ ${nuxt.options.experimental.componentIslands ? islandType : ''}
interface _GlobalComponents {
${componentTypes.map(([pascalName, type]) => ` '${pascalName}': ${type}`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'Lazy${pascalName}': ${type}`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'LazyIdle${pascalName}': ${type} & DefineComponent<{loader?: IdleRequestOptions}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'LazyVisible${pascalName}': ${type} & DefineComponent<{loader?: Partial<IntersectionObserverInit>}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'LazyEvent${pascalName}': ${type} & DefineComponent<{loader?: Array<keyof HTMLElementEventMap>}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'LazyIdle${pascalName}': ${type} & DefineComponent<{hydrate?: IdleRequestOptions}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'LazyVisible${pascalName}': ${type} & DefineComponent<{hydrate?: Partial<IntersectionObserverInit>}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => ` 'LazyEvent${pascalName}': ${type} & DefineComponent<{hydrate?: Array<keyof HTMLElementEventMap>}>`).join('\n')}
}
declare module '@vue/runtime-core' {
@ -138,9 +138,9 @@ declare module 'vue' {
${componentTypes.map(([pascalName, type]) => `export const ${pascalName}: ${type}`).join('\n')}
${componentTypes.map(([pascalName, type]) => `export const Lazy${pascalName}: ${type}`).join('\n')}
${componentTypes.map(([pascalName, type]) => `export const LazyIdle${pascalName}: ${type} & DefineComponent<{loader?: IdleRequestOptions}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => `export const LazyVisible${pascalName}: ${type} & DefineComponent<{loader?: Partial<IntersectionObserverInit>}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => `export const LazyEvent${pascalName}: ${type} & DefineComponent<{loader?: Array<keyof HTMLElementEventMap>}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => `export const LazyIdle${pascalName}: ${type} & DefineComponent<{hydrate?: IdleRequestOptions}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => `export const LazyVisible${pascalName}: ${type} & DefineComponent<{hydrate?: Partial<IntersectionObserverInit>}>`).join('\n')}
${componentTypes.map(([pascalName, type]) => `export const LazyEvent${pascalName}: ${type} & DefineComponent<{hydrate?: Array<keyof HTMLElementEventMap>}>`).join('\n')}
export const componentNames: string[]
`

View File

@ -7,7 +7,7 @@
<LazyEventView />
<LazyEventDelayedEvent
id="lazyevent2"
:loader="createEventLoader(['click'])"
:hydrate="createEventLoader(['click'])"
/>
<LazyIdleDelayedNetwork />
<div style="height:3000px">