-
-
Notifications
You must be signed in to change notification settings - Fork 2
UndoManager save the 'recorder.undo()' as one history when action throws error #15
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
Comments
I search the mobx-state-tree issues and find this:mobxjs/mobx-state-tree#2010, maybe the same problem. |
Hey @songzhenqi - thanks for the detailed bug report and diagnosis. I can't say for sure if this is by design. I inherited this project and didn't write the original code. However, the purpose of spinning out a new project here was so we could make bigger changes without needing to move in lockstep with MST. So here's my proposal to fix this:
Let me know what you think. Thanks again! |
Both proposal are fine for me . |
Sounds good! Let me know if you need any help. If you don't end up having time or interest, just let me know and I'll grab it eventually. I'll assign this to you. |
@coolsoftwaretyler Thanks for trusting a github newbie! :-) Before I start the PR, I'd like to discuss two ways to solve the problem. Both I had try and could pass tests
Result (add some log to show what happened)
Code : onFinish(call, error) {
const recorder = call.env!.recorder
// call.env = undefined // used be here
recorder.stop()
if (error === undefined) {
call.env = undefined // if no errors, clean the env immediately
if (groupRecorders.length > 0) {
const groupRecorder = groupRecorders[groupRecorders.length - 1]
groupRecorder.patches = groupRecorder.patches.concat(recorder.patches)
groupRecorder.inversePatches = groupRecorder.inversePatches.concat(
recorder.inversePatches
)
} else {
; (self as any).addUndoState(recorder)
}
} else {
recorder.undo()
call.env = undefined // if has errors, clean the env after rollback, so applyPatch will be filtered
} Let me know what you think. Thanks again. |
Hey @songzhenqi - I think I prefer the second approach. I agree it's more complex, but if you leave in some comments and write tests exercising both code paths, that will make this intention clear and maintainable overall. Tag me in any PR you make. No rush, I'll give it a review as soon as I can. Thanks! |
fix #15 - rollback by recorder.undo() should not be an UndoState
as the title mentioned. I'm not sure if this is a bug or a deliberate design.
code :
result:

and I dig into UndoManager's source code, I think the problem is
call.env = undefined
calls too early.The text was updated successfully, but these errors were encountered: