Skip to content

Instantly share code, notes, and snippets.

@goldensunliu
Created March 4, 2018 23:05
Show Gist options
  • Save goldensunliu/7518b31e8e5ab723d2a235ae2beced3b to your computer and use it in GitHub Desktop.
Save goldensunliu/7518b31e8e5ab723d2a235ae2beced3b to your computer and use it in GitHub Desktop.
class Game extends Compoent {
...
redo = () => {
const { history } = this.state;
let { historyOffSet } = this.state;
if (history.size) {
historyOffSet = Math.min(history.size - 1, historyOffSet + 1);
const board = history.get(historyOffSet);
this.setState({ board, historyOffSet });
}
};
undo = () => {
const { history } = this.state;
let { historyOffSet, board } = this.state;
if (history.size) {
historyOffSet = Math.max(0, historyOffSet - 1);
board = history.get(historyOffSet);
this.setState({ board, historyOffSet, history });
}
};
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment