mirror of
https://github.com/Pandipipas/scoreko-dev.git
synced 2026-06-06 03:32:06 +00:00
Fix replicant reactivity for scoreboard
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import type { Ref } from 'vue';
|
||||
import { playersReplicant } from '../../../browser_shared/replicants';
|
||||
import type { Schemas } from '../../../types';
|
||||
|
||||
@@ -67,7 +66,6 @@ const writeStorage = (value: PlayersMap) => {
|
||||
export const usePlayersStore = defineStore('players', () => {
|
||||
const players = ref<PlayersMap>({});
|
||||
const replicant = playersReplicant;
|
||||
const replicantRef = replicant?.data as unknown as Ref<PlayersMap | undefined> | undefined;
|
||||
const storageSnapshot = readStorage();
|
||||
if (storageSnapshot) {
|
||||
players.value = storageSnapshot;
|
||||
@@ -76,7 +74,7 @@ export const usePlayersStore = defineStore('players', () => {
|
||||
const isApplyingReplicant = ref(false);
|
||||
|
||||
watch(
|
||||
() => replicantRef?.value,
|
||||
() => replicant?.data,
|
||||
(value) => {
|
||||
if (!value) {
|
||||
return;
|
||||
@@ -93,11 +91,11 @@ export const usePlayersStore = defineStore('players', () => {
|
||||
players,
|
||||
(value) => {
|
||||
writeStorage(value);
|
||||
if (isApplyingReplicant.value || !replicantRef) {
|
||||
if (isApplyingReplicant.value || !replicant) {
|
||||
return;
|
||||
}
|
||||
replicantRef.value = normalizePlayers(value);
|
||||
replicant?.save();
|
||||
replicant.data = normalizePlayers(value);
|
||||
replicant.save();
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import type { Ref } from 'vue';
|
||||
import { scoreboardReplicant } from '../../../browser_shared/replicants';
|
||||
import type { Schemas } from '../../../types';
|
||||
|
||||
@@ -61,7 +60,6 @@ const writeStorage = (value: Scoreboard) => {
|
||||
export const useScoreboardStore = defineStore('scoreboard', () => {
|
||||
const scoreboard = ref<Scoreboard>({ ...defaultScoreboard });
|
||||
const replicant = scoreboardReplicant;
|
||||
const replicantRef = replicant?.data as unknown as Ref<Scoreboard | undefined> | undefined;
|
||||
const storageSnapshot = readStorage();
|
||||
if (storageSnapshot) {
|
||||
scoreboard.value = storageSnapshot;
|
||||
@@ -70,7 +68,7 @@ export const useScoreboardStore = defineStore('scoreboard', () => {
|
||||
const isApplyingReplicant = ref(false);
|
||||
|
||||
watch(
|
||||
() => replicantRef?.value,
|
||||
() => replicant?.data,
|
||||
(value) => {
|
||||
if (!value) {
|
||||
return;
|
||||
@@ -87,11 +85,11 @@ export const useScoreboardStore = defineStore('scoreboard', () => {
|
||||
scoreboard,
|
||||
(value) => {
|
||||
writeStorage(value);
|
||||
if (isApplyingReplicant.value || !replicantRef) {
|
||||
if (isApplyingReplicant.value || !replicant) {
|
||||
return;
|
||||
}
|
||||
replicantRef.value = normalizeScoreboard(value);
|
||||
replicant?.save();
|
||||
replicant.data = normalizeScoreboard(value);
|
||||
replicant.save();
|
||||
},
|
||||
{ deep: true, flush: 'sync' }
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@unhead/vue';
|
||||
import { computed } from 'vue';
|
||||
import type { Ref } from 'vue';
|
||||
import { playersReplicant, scoreboardReplicant } from '../../browser_shared/replicants';
|
||||
import type { Schemas } from '../../types';
|
||||
|
||||
@@ -17,11 +16,8 @@ const defaultScoreboard: Schemas.Scoreboard = {
|
||||
round: '',
|
||||
};
|
||||
|
||||
const playersData = playersReplicant?.data as unknown as Ref<Schemas.Players | undefined> | undefined;
|
||||
const scoreboardData = scoreboardReplicant?.data as unknown as Ref<Schemas.Scoreboard | undefined> | undefined;
|
||||
|
||||
const players = computed<Schemas.Players>(() => playersData?.value ?? {});
|
||||
const scoreboard = computed<Schemas.Scoreboard>(() => scoreboardData?.value ?? defaultScoreboard);
|
||||
const players = computed<Schemas.Players>(() => playersReplicant?.data ?? {});
|
||||
const scoreboard = computed<Schemas.Scoreboard>(() => scoreboardReplicant?.data ?? defaultScoreboard);
|
||||
|
||||
const leftName = computed(() => {
|
||||
if (scoreboard.value.leftNameOverride) {
|
||||
|
||||
Reference in New Issue
Block a user