2018-01-30 18:38:14 +01:00
|
|
|
<div class="pseudo-virtual-list-item"
|
2018-01-31 06:02:07 +01:00
|
|
|
aria-hidden="{{hide}}"
|
2018-01-30 18:38:14 +01:00
|
|
|
pseudo-virtual-list-key="{{key}}"
|
2018-01-31 06:17:01 +01:00
|
|
|
style="height: {{shouldHide ? `${height}px` : ''}};"
|
2018-01-30 18:38:14 +01:00
|
|
|
ref:node>
|
2018-01-31 06:17:01 +01:00
|
|
|
{{#if !shouldHide}}
|
2018-01-30 18:38:14 +01:00
|
|
|
<:Component {component}
|
|
|
|
virtualProps="{{props}}"
|
|
|
|
virtualIndex="{{index}}"
|
2018-02-04 19:05:01 +01:00
|
|
|
virtualLength="{{length}}"
|
2018-01-30 18:38:14 +01:00
|
|
|
/>
|
|
|
|
{{/if}}
|
2018-01-30 04:22:28 +01:00
|
|
|
</div>
|
|
|
|
<script>
|
2018-01-31 06:17:01 +01:00
|
|
|
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
|
|
|
|
import { mark, stop } from '../../_utils/marks'
|
|
|
|
|
2018-01-30 04:22:28 +01:00
|
|
|
export default {
|
2018-04-20 06:38:01 +02:00
|
|
|
oncreate () {
|
2018-01-31 06:17:01 +01: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-04-21 18:56:45 +02:00
|
|
|
let { isIntersecting } = this.get() || {} // https://github.com/sveltejs/svelte/issues/1354
|
2018-04-19 18:37:05 +02:00
|
|
|
if (!isIntersecting) {
|
2018-01-31 06:17:01 +01:00
|
|
|
this.set({hide: true})
|
|
|
|
}
|
|
|
|
stop('unrender')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-04-19 18:37:05 +02:00
|
|
|
let { intersectionObserver } = this.get()
|
2018-01-30 18:38:14 +01:00
|
|
|
intersectionObserver.observe(this.refs.node)
|
2018-01-31 06:17:01 +01:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
shouldHide: (isIntersecting, isCached, hide) => {
|
|
|
|
if (isCached) {
|
|
|
|
return true // if it's cached, always unrender immediately until proven it's intersecting
|
|
|
|
}
|
|
|
|
return !isIntersecting && hide
|
|
|
|
}
|
2018-01-30 04:22:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|