Skip to content

Commit

Permalink
Fix data not cloning over
Browse files Browse the repository at this point in the history
  • Loading branch information
EwanLyon committed Jan 21, 2021
1 parent d40aadb commit 5bc7815
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/extension/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,31 @@ nodecg.listenFor('createNewMatch', (newMatch: NewMatch) => {
});

nodecg.listenFor('updateScore', (data: Match['maps']) => {
if (!currentMatchRep.value) return;

const matchIndex = matchesRep.value.findIndex(match => match.id === currentMatchRep.value?.id);

if (matchIndex === -1) {
nodecg.log.error('Can\'t find match id in matches. Cannot update score.');
return;
}

matchesRep.value[matchIndex].maps = data;
currentMatchRep.value.maps = data;
matchesRep.value[matchIndex].maps = _.cloneDeep(data);
});

nodecg.listenFor('updateStatus', (status: string) => {
if (!currentMatchRep.value) return;

const matchIndex = matchesRep.value.findIndex(match => match.id === currentMatchRep.value?.id);

if (matchIndex === -1) {
nodecg.log.error('Can\'t find match id in matches. Cannot update status.');
return;
}

matchesRep.value[matchIndex].status = status;
currentMatchRep.value.status = status;
matchesRep.value[matchIndex].status = _.clone(status);
});

nodecg.listenFor('updateMatchOrder', (newOrder: Matches) => {
Expand All @@ -105,6 +111,10 @@ nodecg.listenFor('removeMatch', (id: string) => {
}

matchesRep.value.splice(matchIndex, 1);

if (id === currentMatchRep.value?.id) {
currentMatchRep.value = getFirstMatch();
}
});

nodecg.listenFor('addMap', (data: MapInfo) => {
Expand Down

0 comments on commit 5bc7815

Please sign in to comment.