compute rather than watch shells list

This commit is contained in:
Branden J Brown 2024-02-03 13:39:34 -06:00
parent 76195d21cb
commit aa95695a11
1 changed files with 6 additions and 8 deletions

View File

@ -20,7 +20,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, watch } from 'vue'; import { computed } from 'vue';
import type { Game } from '@/lib/game'; import type { Game } from '@/lib/game';
export interface Props { export interface Props {
@ -69,15 +69,13 @@ const revealed = computed(() => {
return null; return null;
}) })
const shellList = ref<string[]>([]); const shellList = computed(() => {
watch(props.game, (game) => { if (props.game.live == null || props.game.blank == null) {
if (game.live == null || game.blank == null) { return [];
shellList.value = [];
return;
} }
const l = [...Array(game.live).fill('🟥'), ...Array(game.blank).fill('🟦')]; const l = [...Array(props.game.live).fill('🟥'), ...Array(props.game.blank).fill('🟦')];
shuffle(l); shuffle(l);
shellList.value = [...l, ...Array(8 - game.live - game.blank).fill('⬛')]; return [...l, ...Array(8 - props.game.live - props.game.blank).fill('⬛')];
}); });
function shuffle<Elem>(l: Elem[]) { function shuffle<Elem>(l: Elem[]) {