2018-01-30 17:38:14 +00:00
|
|
|
<div class="pseudo-virtual-list-item"
|
2018-05-02 00:05:36 +00:00
|
|
|
aria-hidden={hide}
|
|
|
|
pseudo-virtual-list-key={key}
|
|
|
|
style="height: {shouldHide ? `${height}px` : ''};"
|
2018-01-30 17:38:14 +00:00
|
|
|
ref:node>
|
2018-05-02 00:05:36 +00:00
|
|
|
{#if !shouldHide}
|
|
|
|
<svelte:component this={component}
|
|
|
|
virtualProps={props}
|
|
|
|
virtualIndex={index}
|
|
|
|
virtualLength={length}
|
2018-01-30 17:38:14 +00:00
|
|
|
/>
|
2018-05-02 00:05:36 +00:00
|
|
|
{/if}
|
2018-01-30 03:22:28 +00:00
|
|
|
</div>
|
|
|
|
<script>
|
2018-01-31 05:17:01 +00:00
|
|
|
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
|
|
|
|
import { mark, stop } from '../../_utils/marks'
|
2018-04-30 15:29:04 +00:00
|
|
|
import { observe } from 'svelte-extras'
|
2018-01-31 05:17:01 +00:00
|
|
|
|
2018-01-30 03:22:28 +00:00
|
|
|
export default {
|
2018-04-20 04:38:01 +00:00
|
|
|
oncreate () {
|
2018-01-31 05:17:01 +00:00
|
|
|
this.observe('isIntersecting', isIntersecting => {
|
|
|
|
if (isIntersecting) {
|
|
|
|
mark('render')
|
|
|
|
this.set({hide: false})
|
|
|
|
stop('render')
|
|
|
|
} else {
|
|
|
|
// unrender lazily; it's not a critical UI task
|
|
|
|
scheduleIdleTask(() => {
|
|
|
|
mark('unrender')
|
2018-05-05 03:09:20 +00:00
|
|
|
let { isIntersecting } = this.get()
|
2018-04-19 16:37:05 +00:00
|
|
|
if (!isIntersecting) {
|
2018-01-31 05:17:01 +00:00
|
|
|
this.set({hide: true})
|
|
|
|
}
|
|
|
|
stop('unrender')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-19 16:37:05 +00:00
|
|
|
let { intersectionObserver } = this.get()
|
2018-01-30 17:38:14 +00:00
|
|
|
intersectionObserver.observe(this.refs.node)
|
2018-01-31 05:17:01 +00:00
|
|
|
},
|
2018-04-30 05:13:41 +00:00
|
|
|
data: () => ({
|
|
|
|
hide: false
|
|
|
|
}),
|
2018-01-31 05:17:01 +00:00
|
|
|
computed: {
|
2018-05-02 00:05:36 +00:00
|
|
|
shouldHide: ({ isIntersecting, isCached, hide }) => {
|
2018-01-31 05:17:01 +00:00
|
|
|
if (isCached) {
|
|
|
|
return true // if it's cached, always unrender immediately until proven it's intersecting
|
|
|
|
}
|
|
|
|
return !isIntersecting && hide
|
|
|
|
}
|
2018-04-30 15:29:04 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
observe
|
2018-01-30 03:22:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|