Skip to content

Commit 6e2d9bb

Browse files
committed
Calculate unique id for each rows
This improves performance on inserting new lines as lines below will not need to all revalidate.
1 parent 13c8587 commit 6e2d9bb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/components/BSMap.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div :class="$style.map" :style="style">
3-
<BSRow v-for="(row, index) in rows" :key="index" :src="row" :row="index" />
3+
<BSRow v-for="({ row, id }, index) in rows" :key="id" :src="row" :row="index" />
44
</div>
55
</template>
66

@@ -20,8 +20,16 @@ const props = defineProps<{
2020
size: number;
2121
}>();
2222
23-
const rows = computed(() => props.content.split('\n'));
24-
const cols = computed(() => max(rows.value.map((row) => row.split('\\').length)) || 1);
23+
const rows = computed(() => {
24+
const appears: Record<string, number> = {};
25+
return props.content.split('\n').map((row) => {
26+
const id = (appears[row] ?? -1) + 1;
27+
appears[row] = id;
28+
return { row, id: `${row}#${id}` };
29+
});
30+
});
31+
32+
const cols = computed(() => max(rows.value.map(({ row }) => row.split('\\').length)) || 1);
2533
2634
const style = computed(() => ({
2735
'--bs-map-size': props.size,

0 commit comments

Comments
 (0)