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'
|
2020-04-28 17:48:25 -07:00
|
|
|
import { store } from '../../_store/store'
|
2020-04-26 16:54:00 -07:00
|
|
|
|
|
|
|
// 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()
|
2020-04-28 17:48:25 -07:00
|
|
|
const { reduceMotion } = this.store.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')
|
|
|
|
}
|
2020-04-28 17:48:25 -07:00
|
|
|
// On desktop, if prefers-reduced-motion is enabled, avoid using scheduleIdleTask
|
|
|
|
// here because it causes the scrollbar to grow in a way that may sicken
|
|
|
|
// people with vestibular disorders.
|
2020-04-26 16:54:00 -07:00
|
|
|
// TODO: someday we can use isInputPending as a better way to break up work
|
|
|
|
// https://www.chromestatus.com/feature/5719830432841728
|
2020-04-28 17:48:25 -07:00
|
|
|
if (!isMobile() && reduceMotion) {
|
2020-04-26 16:54:00 -07:00
|
|
|
setProps()
|
2020-04-28 17:48:25 -07:00
|
|
|
} else {
|
|
|
|
scheduleIdleTask(setProps)
|
2020-04-26 16:54:00 -07:00
|
|
|
}
|
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
|
|
|
}),
|
2020-04-28 17:48:25 -07:00
|
|
|
store: () => store,
|
2018-01-23 18:15:14 -08:00
|
|
|
components: {
|
|
|
|
VirtualListItem
|
|
|
|
}
|
|
|
|
}
|
2019-08-19 19:08:59 -07:00
|
|
|
</script>
|