This commit is contained in:
Jan Prochazka
2020-03-30 21:36:47 +02:00
parent 72b2329c2c
commit 8f245ca40f
4 changed files with 39 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ function reducer(state, action) {
history: [...state.history.slice(0, state.current + 1), action.value],
current: state.current + 1,
value: action.value,
canUndo: true,
canRedo: false,
};
case 'undo':
if (state.current > 0)
@@ -15,6 +17,8 @@ function reducer(state, action) {
history: state.history,
current: state.current - 1,
value: state.history[state.current - 1],
canUndo: state.current > 1,
canRedo: true,
};
return state;
case 'redo':
@@ -23,6 +27,8 @@ function reducer(state, action) {
history: state.history,
current: state.current + 1,
value: state.history[state.current + 1],
canUndo: true,
canRedo: state.current < state.history.length - 2,
};
return state;
case 'reset':