SaveReplace replaces the current Undo record with new state, instead of creating a new record. This is useful for when you have a stream of the same type of manipulations and just want to save the last (it is better to handle that case up front as saving the state can be relatively expensive, but i
(action, data string, state []string)
| 174 | // up front as saving the state can be relatively expensive, but |
| 175 | // in some cases it is not possible). |
| 176 | func (us *Stack) SaveReplace(action, data string, state []string) { |
| 177 | us.Mu.Lock() |
| 178 | nr := us.Records[us.Index] |
| 179 | go us.SaveState(nr, us.Index, state) |
| 180 | } |
| 181 | |
| 182 | // SaveState saves given record of state at given index |
| 183 | func (us *Stack) SaveState(nr *Record, idx int, state []string) { |