Skip to content
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

Use an append-only log to store "commands" #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lpan
Copy link
Owner

@lpan lpan commented Sep 26, 2018

Motivation

I never got redo working because the previous method was hard to test and reason about. This seems like a reasonable size refactor. See if it can help me to get redo out 🙂

#34

Context

Currently, I am trying to implement undo and redo using two mutable stacks. One stack keeps track of all the applied "commands", the other is used as a temp buffer.

When an user action is committed, we would "push" it to the first stack. When the user undoes, we would "pop" the first stack (history stack), re-apply what is now on the first stack, and push the popped "command" onto the temp stack (redo stack).

For redo, we simply pop the redo stack, then apply the command and push it back to the history stack.

In my opinion, Mutating two logs is hard to reason about than just keeping track of the offsets of an append-only log.

What this PR does

This PR attempts to get rid of the two mutable stacks, and just use a single append-only log to store "commands" instead. We will use "offsets" of the log to implement the undo/redo logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant