undo

package
v0.0.0-...-bb5bdbf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package undo provides a doubly linked structure to store a list of actions that can later be reverted or reperformed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	// contains filtered or unexported fields
}

Actor encapsulates all undo/redo functionality. Use NewActor() to create an initialized Actor

func NewActor

func NewActor() Actor

NewActor creates an initialized Actor

func (*Actor) AddAction

func (h *Actor) AddAction(id string, a ReversibleAction) error

AddAction performs the action and appends it onto the current node and updates the current node. Will destroy any history ahead of the current node.

func (*Actor) Redo

func (h *Actor) Redo(id string) (bool, error)

Redo moves the current pointer ahead one action and performs it. If current action is the tail, do nothing

func (*Actor) Undo

func (h *Actor) Undo(id string) (bool, error)

Undo reverses out the current action and moves the current pointer back one action. If current action is the head, do nothing

type CreateAndInputAction

type CreateAndInputAction struct {
	// contains filtered or unexported fields
}

CreateAndInputAction encapsulates adding a new drink to the database and inputting it

func NewCreateAndInputAction

func NewCreateAndInputAction(d model.Drink, de model.DrinkEntry) *CreateAndInputAction

NewCreateAndInputAction returns an initialized CreateAndInputAction

func (*CreateAndInputAction) Do

func (a *CreateAndInputAction) Do() (err error)

Do implements the ReversibleAction interface

func (*CreateAndInputAction) Undo

func (a *CreateAndInputAction) Undo() (err error)

Undo implements the ReversibleAction interface

type CreateDrinkAction

type CreateDrinkAction struct {
	// contains filtered or unexported fields
}

CreateDrinkAction encapsulates adding a new drink to the database

func NewCreateDrinkAction

func NewCreateDrinkAction(d model.Drink) *CreateDrinkAction

NewCreateDrinkAction returns an initialized CreateDrinkAction

func (*CreateDrinkAction) Do

func (a *CreateDrinkAction) Do() error

Do implements the ReversibleAction interface

func (*CreateDrinkAction) Undo

func (a *CreateDrinkAction) Undo() error

Undo implements the ReversibleAction interface

type InputDrinksAction

type InputDrinksAction struct {
	// contains filtered or unexported fields
}

InputDrinksAction encapsulates stocking a drink

func NewInputDrinksAction

func NewInputDrinksAction(de model.DrinkEntry) *InputDrinksAction

NewInputDrinksAction returns an initialized InputDrinksAction

func (*InputDrinksAction) Do

func (a *InputDrinksAction) Do() error

Do implements the ReversibleAction interface

func (*InputDrinksAction) Undo

func (a *InputDrinksAction) Undo() error

Undo implements the ReversibleAction interface

type OutputDrinksAction

type OutputDrinksAction struct {
	// contains filtered or unexported fields
}

OutputDrinksAction encapsulates serving a drink

func NewOutputDrinksAction

func NewOutputDrinksAction(de model.DrinkEntry) *OutputDrinksAction

NewOutputDrinksAction returns an initialized OutputDrinksAction

func (*OutputDrinksAction) Do

func (a *OutputDrinksAction) Do() error

Do implements the ReversibleAction interface

func (*OutputDrinksAction) Undo

func (a *OutputDrinksAction) Undo() error

Undo implements the ReversibleAction interface

type ReversibleAction

type ReversibleAction interface {
	Do() error
	Undo() error
}

ReversibleAction defines an undo-able database change

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL