Closed nwpointer closed 3 years ago
Hi @nwpointer, it depends a bit what operations you need to support. For example, if you only need to undo assignment of a key in a map, then you could record the old value of the key before you assign it, and then the undo resets the key to its previous value. If you need to undo the insertion of an element into a list, you can remember the index at which you inserted, and undo the insertion by deleting the element at that index. However, things get more complicated if other users may also be generating changes, and in that case you probably want to only undo the local user's changes, not changes made by other users (also you would have to account for list indexes changing due to other users' insertions/deletions).
The real solution is of course to add undo support to Automerge itself, but I'm afraid we don't have a timeline for doing that right now.
I was considering manually creating an map of inverse operations for each valid operation in my app and then when the user requests undo, use the change message to look up and apply the corresponding inverse function. Kinda hacky and limited but pretty simple.
if anybody else has ideas / solutions that have worked for them would love to discuss