mark-p-thomas : History Library

This library contains various ways of recording history/states of an object or app. This is most commonly used for undo/redo operations.

Comparisons

Below is a table comparing the main differences between using a State History vs. Command History object:

State History

Command History

Command agnostic. Can be one-way state changes where no method can reverse the state.

The only commands that can be undone are ones that have an associated command that perfectly reverses the changes to the object.

Faster than Command History, since all that is needed is changing reference pointers in memory.

Slower than State History, since an object must be transformed back to an earlier state.

Requires more memory than Command History

Requires very little memory. Just enough to record information of the commands used such that an associated reversing command can be called.

If space complexity/memory for storing the state object is large, the memory for State History can be limited by limiting the # of states saved.

Best for when time complexity is large for changing state compared to space complexity of storing state objects.

Best for when space complexity for storing objects is large, or when you want an unlimited # of saved states.

Note that the deficiencies in one history strategy is a strength of the other. With both methodologies implemented, users can adopt a hybrid strategy using both states, such as Command History for many small undoable changes, and State History as major saving points to skip many reversals, or to handle cases where actions cannot be reversed by an associated method.

Diagrams

Diagrams are made in Figma.

Child Pages