Skip to content

Commit

Permalink
Calculate unique id for each rows
Browse files Browse the repository at this point in the history
This improves performance on inserting new lines as lines below will not
need to all revalidate.
  • Loading branch information
xingrz committed Apr 6, 2024
1 parent 13c8587 commit 6e2d9bb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/components/BSMap.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div :class="$style.map" :style="style">
<BSRow v-for="(row, index) in rows" :key="index" :src="row" :row="index" />
<BSRow v-for="({ row, id }, index) in rows" :key="id" :src="row" :row="index" />
</div>
</template>

Expand All @@ -20,8 +20,16 @@ const props = defineProps<{
size: number;
}>();
const rows = computed(() => props.content.split('\n'));
const cols = computed(() => max(rows.value.map((row) => row.split('\\').length)) || 1);
const rows = computed(() => {
const appears: Record<string, number> = {};
return props.content.split('\n').map((row) => {
const id = (appears[row] ?? -1) + 1;
appears[row] = id;
return { row, id: `${row}#${id}` };
});
});
const cols = computed(() => max(rows.value.map(({ row }) => row.split('\\').length)) || 1);
const style = computed(() => ({
'--bs-map-size': props.size,
Expand Down

0 comments on commit 6e2d9bb

Please sign in to comment.