Skip to content

Commit a6ac83e

Browse files
committed
history bugfix / refactor
1 parent 82526e0 commit a6ac83e

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

app/store/history.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import throttle from 'lodash/throttle';
33
import { environment } from './environment';
44

55
const maxHistory = 1000;
6-
let past = [];
7-
let now = undefined;
8-
let future = [];
6+
const past = [];
7+
const future = [];
8+
let now;
99
let timeTravelling = false;
1010

1111
export function initHistory() {
@@ -43,13 +43,15 @@ function setCurrent() {
4343
}
4444

4545
const addHistory = () => {
46-
if (!timeTravelling) {
46+
if (timeTravelling) {
47+
timeTravelling = false;
48+
} else {
4749
console.log('add history');
4850
now && past.push(now);
4951

5052
now = getCurrent();
5153

52-
future = [];
54+
future.splice(0, future.length);
5355

5456
if (past.length >= maxHistory) {
5557
past.shift();
@@ -59,7 +61,6 @@ const addHistory = () => {
5961

6062
export const undo = throttle(() => {
6163
timeTravelling = true;
62-
console.log(true);
6364

6465
if (past.length) {
6566
future.push(now);
@@ -68,9 +69,6 @@ export const undo = throttle(() => {
6869

6970
setCurrent();
7071
}
71-
72-
console.log(false);
73-
timeTravelling = false;
7472
}, 100);
7573

7674
export const redo = throttle(() => {
@@ -83,6 +81,4 @@ export const redo = throttle(() => {
8381

8482
setCurrent();
8583
}
86-
87-
timeTravelling = false;
8884
}, 100);

0 commit comments

Comments
 (0)