2018-05-01 17:05:36 -07:00
|
|
|
{#if props}
|
|
|
|
<VirtualListItem {component}
|
|
|
|
{offset}
|
|
|
|
{props}
|
|
|
|
{key}
|
|
|
|
{index}
|
2018-03-01 09:19:45 -08:00
|
|
|
/>
|
2018-05-01 17:05:36 -07:00
|
|
|
{/if}
|
2018-01-23 18:15:14 -08:00
|
|
|
<script>
|
|
|
|
import VirtualListItem from './VirtualListItem'
|
2018-03-14 18:24:16 -07:00
|
|
|
import { mark, stop } from '../../_utils/marks'
|
2020-04-26 16:54:00 -07:00
|
|
|
import { scheduleIdleTask } from '../../_utils/scheduleIdleTask'
|
|
|
|
import { createPriorityQueue } from '../../_utils/createPriorityQueue'
|
|
|
|
import { isMobile } from '../../_utils/userAgent/isMobile'
|
|
|
|
|
|
|
|
// In Svelte's implementation of lists, these VirtualListLazyItems can be
|
|
|
|
// created in any order. By default in fact it seems to do it in reverse
|
|
|
|
// order, which we don't really want, because then items render in a janky
|
|
|
|
// way, with the last ones first and then replaced by the first ones,
|
|
|
|
// resulting in a UI that looks like a deck of cards being shuffled.
|
|
|
|
// This functions waits a microtask and then ensures that the callbacks
|
|
|
|
// are called by index, in ascending order.
|
|
|
|
const priorityQueue = createPriorityQueue()
|
2018-03-14 18:24:16 -07:00
|
|
|
|
2018-01-23 18:15:14 -08:00
|
|
|
export default {
|
2018-04-19 21:38:01 -07:00
|
|
|
async oncreate () {
|
2020-04-26 16:54:00 -07:00
|
|
|
const { makeProps, key, index } = this.get()
|
2018-03-01 09:19:45 -08:00
|
|
|
if (makeProps) {
|
2020-04-26 16:54:00 -07:00
|
|
|
await priorityQueue(index)
|
2019-08-03 13:49:37 -07:00
|
|
|
const props = await makeProps(key)
|
2020-04-26 16:54:00 -07:00
|
|
|
const setProps = () => {
|
|
|
|
mark('VirtualListLazyItem set props')
|
|
|
|
this.set({ props: props })
|
|
|
|
stop('VirtualListLazyItem set props')
|
|
|
|
}
|
|
|
|
// On mobile, render in rIC for maximum input responsiveness. The reason we do
|
|
|
|
// different behavior for desktop versus mobile is:
|
|
|
|
// 1. On desktop, the scrollbar is really distracting as it changes size. It may
|
|
|
|
// even cause issues for people with vestibular disorders (see also prefers-reduced-motion).
|
|
|
|
// 2. On mobile, the CPU is generally slower, so we want better input responsiveness.
|
|
|
|
// TODO: someday we can use isInputPending as a better way to break up work
|
|
|
|
// https://www.chromestatus.com/feature/5719830432841728
|
|
|
|
if (isMobile()) {
|
|
|
|
scheduleIdleTask(setProps)
|
|
|
|
} else {
|
|
|
|
setProps()
|
|
|
|
}
|
2018-03-01 09:19:45 -08:00
|
|
|
}
|
|
|
|
},
|
2018-04-29 22:13:41 -07:00
|
|
|
data: () => ({
|
2019-08-19 19:08:59 -07:00
|
|
|
props: undefined
|
2018-04-29 22:13:41 -07:00
|
|
|
}),
|
2018-01-23 18:15:14 -08:00
|
|
|
components: {
|
|
|
|
VirtualListItem
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 19:08:59 -07:00
|
|
|
</script>
|