The post discusses a simple yet effective approach to implementing an undo stack for user interfaces, especially in drawing applications. It explains the difference between undo stacks and version histories, highlights issues with traditional pointer-based implementations, and offers a solution using two stacks (undoStack and redoStack) without indexing. The implementation includes making actions idempotent using JavaScript's structuredClone() to avoid issues with closures and references.
Table of contents
Undo histories and managersThe perils of stack pointersCould we not index?The pass-by-reference problemSort: