Skip to content

Commit 672bf5e

Browse files
committedMar 20, 2024·
perf: add virtual-scroller for timeline component
1 parent ac59853 commit 672bf5e

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed
 

‎packages/applet/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"@vue/devtools-shared": "workspace:^",
3333
"@vue/devtools-ui": "workspace:^",
3434
"perfect-debounce": "^1.0.0",
35-
"splitpanes": "^3.1.5"
35+
"splitpanes": "^3.1.5",
36+
"vue-virtual-scroller": "2.0.0-beta.8"
3637
},
3738
"devDependencies": {
3839
"unplugin-vue": "^5.0.5",
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
22
import type { TimelineEvent } from '@vue/devtools-kit'
33
import { computed } from 'vue'
4+
import { RecycleScroller } from 'vue-virtual-scroller'
45
import { formatTime } from '~/utils'
6+
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
57
68
const props = defineProps<{
7-
data: Array<TimelineEvent['event'] & { color?: string }>
9+
data: Array<TimelineEvent['event'] & { color?: string, id?: number }>
810
}>()
911
1012
const selected = defineModel()
@@ -13,12 +15,13 @@ const colors = ['#3e5770', '#42b983', '#0098c4']
1315
const normalizedData = computed(() => {
1416
let currentColorIndex = -1
1517
let currentGroupId = 0
16-
props.data.forEach((item) => {
18+
props.data.forEach((item, index) => {
1719
if (item.groupId !== currentGroupId || currentColorIndex === -1)
1820
currentColorIndex = (currentColorIndex + 1) % colors.length
1921
2022
currentGroupId = item.groupId ?? currentGroupId
2123
24+
item.id = index
2225
item.color = colors[currentColorIndex]
2326
})
2427
return props.data
@@ -27,19 +30,28 @@ const normalizedData = computed(() => {
2730

2831
<template>
2932
<div class="p3">
30-
<ul>
31-
<li v-for="(item, index) in normalizedData" :key="index" class="relative mb7 h6 cursor-pointer" :style="{ color: selected === index ? item.color : '' }" @click="selected = index">
33+
<RecycleScroller
34+
v-slot="{ item }"
35+
:items="normalizedData"
36+
:min-item-size="52"
37+
key-field="id"
38+
page-mode
39+
item-tag="li"
40+
list-tag="ul"
41+
:buffer="20"
42+
>
43+
<div class="relative mb7 h6 cursor-pointer" :style="{ color: selected === item.id ? item.color : '' }" @click="selected = item.id">
3244
<!-- head -->
3345
<span class="absolute top-1.5 inline-block h3 w3 b rounded-50%" :style="{ border: `3px solid ${item.color}` }" />
3446
<!-- line -->
35-
<span v-if="index < data.length - 1" class="absolute left-5px top-4.5 h10 w0 border-l-2" border="solid gray2" />
47+
<span v-if="item.id < data.length - 1" class="absolute left-5px top-4.5 h10 w0 border-l-2" border="solid gray2" />
3648
<!-- content -->
3749
<p class="h-full flex items-center truncate pl5">
3850
<span absolute top-5 pr2 text-3 op40>[{{ formatTime(item.time) }}]</span>
3951
{{ item.title }}
4052
<span pl2 op30>{{ item.subtitle }}</span>
4153
</p>
42-
</li>
43-
</ul>
54+
</div>
55+
</RecycleScroller>
4456
</div>
4557
</template>

‎pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.