Closed kkoch986 closed 6 years ago
I think this is already implemented here: https://github.com/google/boardgame.io/blob/master/src/both/reducer.js#L54
Which means that if one of your moves is 'END_TURN', this move will be executed before doing the rest of the end turn calculations...
yea sorry i should have picked through the code a bit more.
Looking at it more though its already provided and they dont expose a way to easily set it (https://github.com/google/boardgame.io/blob/master/src/both/game.js#L43-L58)
what i did realize though after looking at that code is implementing the following move would accomplish what i want:
END_TURN(G, ctx, id) {
return {
...G,
currentDice: null
}
}
its not super pretty because it still shows up as an extra move. but it does get called automatically when the normal endTurn is called so i no longer need to call both.
happy to close this though since that does work better than what i started with. thanks for the quick response!
would be cool to be able to define a hook for when endTurn is called to clean up some state in between turns.
maybe im not approaching it correctly so feel free to tell if thats the case. A simple example would be having dice. if i store the current value of the dice in the game state, when the turn is over id like to be able to null out the current dice numbers so the UI knows its time to re-roll.
for now a workaround is to define my own move called endturn which updates the state and in the UI code calling both simultaneously