-
Notifications
You must be signed in to change notification settings - Fork 716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bugfix] Events should be undoable #942
[Bugfix] Events should be undoable #942
Conversation
348e169
to
bc0311f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this. I don’t think this is actually the logic we want. It should be possible to undo just the endStage
event in your test and not the event and the move. (An endStage
called by a move via the ctx.events
API won’t end up in the undo/redo stack, so you only have to account for the case where an event was explicitly called.)
My suggestion is to wrap this reducer check in if (last.moveType)
:
boardgame.io/src/core/reducer.ts
Lines 317 to 325 in dc6cd45
// Only allow undoable moves to be undone. | |
const lastMove: Move = game.flow.getMove( | |
restore.ctx, | |
last.moveType, | |
last.playerID | |
); | |
if (!CanUndoMove(state.G, state.ctx, lastMove)) { | |
return state; | |
} |
i.e. we only check for move undoability if the thing to be undone is actually a move.
The undo/redo stacks are reset at the start of each turn/phase, so this only enables event undos for stages anyway. (And we already made sure we’re not undoing another player’s action, so this only allows a player to undo their own stage event.)
The main reason I didn't want to go the route of actually supporting undo of endStage is that changes existing behavior and smells more like a feature than a bugfix. Remember the cause for tackling this was this stack trace where the last thing on the stack wasn't a move:
|
Well, whether it’s a feature or a bug fix, I still think it’s what we want :-D I guess it’s just an argument as to whether the bug was the thing without a |
SGTM about that being the more reasonable behavior. Main concern is that it's bigger scope to test that "new" functionality because of the current test setup. I guess I can fix the tests accordingly to cover! 🚀
|
Thanks! I guess it shouldn’t be too different from the existing tests, just with the |
bc0311f
to
65b8b0d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @shaoster! Thank you.
See #940 (comment)
Checklist
master
).