Created
November 20, 2017 14:45
-
-
Save azz0r/bbc206d5304369c321604bc03bc21617 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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