https://github.com/iomodo/a-simple-undo-redo
A simple undo/redo functionality in Go
https://github.com/iomodo/a-simple-undo-redo
go golang undo undo-redo
Last synced: 3 months ago
JSON representation
A simple undo/redo functionality in Go
- Host: GitHub
- URL: https://github.com/iomodo/a-simple-undo-redo
- Owner: iomodo
- License: mit
- Created: 2019-05-26T19:43:34.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-26T20:22:41.000Z (almost 7 years ago)
- Last Synced: 2024-06-20T00:42:28.249Z (almost 2 years ago)
- Topics: go, golang, undo, undo-redo
- Language: Go
- Size: 3.91 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# a-simple-undo-redo
A simple undo/redo functionality in Go
## Interface
~~~Go
type State interface{}
type Undoer interface {
State() State // returns the current state
Save(newState State) // saves the new state onto the history
Undo() // undos the state
Redo() // redos the state
Clear() // clears the history
}
~~~
## Example
~~~Go
// create undoer with unlimited capacity
undoer := NewUndoer(0)
undoer.Save(1)
undoer.Save(2)
undoer.Save(3)
undoer.Undo()
undoer.Undo()
undoer.State() // returns 1
undoer.Redo()
undoer.State() // returns 2
~~~