Created
March 4, 2018 23:05
-
-
Save goldensunliu/7518b31e8e5ab723d2a235ae2beced3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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