On an undo action, we want to do the following steps:
- Remove the last element from the past
- Insert the current present state at the beginning of the future
- Set the present to the element we removed from the past in the first step
Replace the return state // TODO line following case actionTypes.UNDO, by doing the following:
- First, we check whether there are elements in the past array. If not, we simply return the current state:
if (past.length <= 0) return state
- Next, we store the last element from the past, because we will need it in the last step:
const previous = past[past.length - 1]
- Then, we create a new array from the past array, with the last element excluded:
const newPast = past.slice(0, past.length ...