Undoing and redoing user actions in Redux
In this section, we’ll add undo and redo buttons at the top of the page, which allow the user to undo and redo statements that they’ve previously run. They’ll work like this:
- Initially, both buttons will be disabled.
- Once the user executes a statement, the Undo button will become enabled.
- When the user clicks the Undo button, the last statement will be undone.
- At that point, the Redo button becomes available, and the user can choose to redo the last statement.
- Multiple actions can be undone and then redone, in sequence.
- If the user performs a new action while Redo is available, the redo sequence is cleared, and the Redo button becomes unavailable again.
Aside from adding button elements, the work involved here is building a new reducer, withUndoRedo
, which will decorate the script reducer. This reducer will return the same state as the script reducer, but with two additional properties...