Skip to content

Instantly share code, notes, and snippets.

@azz0r
Created November 20, 2017 14:45
Show Gist options
  • Save azz0r/bbc206d5304369c321604bc03bc21617 to your computer and use it in GitHub Desktop.
Save azz0r/bbc206d5304369c321604bc03bc21617 to your computer and use it in GitHub Desktop.
case "STORE_MATCH_DATA":
{
let bouts = Object.assign([], action.payload.matches)
bouts = bouts.filter(item => !item.resultStored && item.simulated)
bouts.forEach(bout => {
const winningTeamId = bouts.wrestlers.find(item => item.winner)
const losingTeamId = bouts.wrestlers.find(item => item.loser)
if (winningTeamId && losingTeamId) {
let updateIndexes
updateIndexes = bouts.wrestlers.reduce((prev, curr) => {
return prev.concat({winner: state.findIndex(item => item.id === curr.id))
}, [])
updateIndexes = updateIndexes.concat(
bouts.wrestlers.reduce((prev, curr) => {
return prev.concat({ winner: false, state.findIndex(item => item.id === curr.id)})
}, [])
)
winnersIndex.forEach(index => {
state.updateIn([index], item => new Model(item))
})
}
})
}
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment