Skip to content

iomodo/a-simple-undo-redo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

a-simple-undo-redo

A simple undo/redo functionality in Go

Interface

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

// 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

About

A simple undo/redo functionality in Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages