Skip to content
Snippets Groups Projects
Commit efe31ae6 authored by Maximilian Giller's avatar Maximilian Giller
Browse files

Removed duplicate code

parent f2520967
No related branches found
No related tags found
No related merge requests found
export default class ManagedData {
constructor(data) {
this.data = data;
this.history = [];
this.history = []; // Newest state is always at 0
this.historyPosition = 0;
this.storeCurrentData("Initial state");
......@@ -11,27 +11,32 @@ export default class ManagedData {
onRedo() {}
undo() {
if (this.historyPosition + 1 >= this.history.length) {
if (this.step(1)) {
this.onUndo();
return true;
} else {
return false;
}
this.historyPosition += 1;
this.data = JSON.parse(this.history[this.historyPosition].data);
this.onUndo();
return true;
}
redo() {
if (this.historyPosition <= 0) {
if (this.step(-1)) {
this.onRedo();
return true;
} else {
return false;
}
}
this.historyPosition -= 1;
this.data = JSON.parse(this.history[this.historyPosition].data);
step(direction = 1) {
var newHistoryPosition = this.historyPosition + Math.sign(direction);
this.onRedo();
if (newHistoryPosition >= this.history.length || newHistoryPosition < 0) {
return false;
}
this.historyPosition = newHistoryPosition;
this.data = JSON.parse(this.history[this.historyPosition].data);
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment