compute rather than watch shells list
This commit is contained in:
parent
76195d21cb
commit
aa95695a11
@ -20,7 +20,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { computed } from 'vue';
|
||||
import type { Game } from '@/lib/game';
|
||||
|
||||
export interface Props {
|
||||
@ -69,15 +69,13 @@ const revealed = computed(() => {
|
||||
return null;
|
||||
})
|
||||
|
||||
const shellList = ref<string[]>([]);
|
||||
watch(props.game, (game) => {
|
||||
if (game.live == null || game.blank == null) {
|
||||
shellList.value = [];
|
||||
return;
|
||||
const shellList = computed(() => {
|
||||
if (props.game.live == null || props.game.blank == null) {
|
||||
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);
|
||||
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[]) {
|
||||
|
Loading…
Reference in New Issue
Block a user