state

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package state contains utilities for managing state transitions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func()

Action represents a single unit for work.

type Change

type Change interface {
	Apply()
	Revert()
}

Change represents a state change.

func AccumActionChange

func AccumActionChange(forward, reverse []Action, accumDuration time.Duration) Change

AccumActionChange is similar to ActionChange except that it is also extendable. The accumDuration interval is used to specify accumulation threshold for the change.

func ActionChange

func ActionChange(accumDuration time.Duration, forward, reverse []Action) Change

ActionChange returns a Change that is based on the specified forward and reverse actions.

func CombinedChange

func CombinedChange(changes ...Change) Change

CombinedChange creates a composite change off of a number of smaller changes.

type ExtendableChange

type ExtendableChange interface {

	// Extend returns whether the specified change was merged into the current
	// one.
	Extend(change Change) bool
}

ExtendableChange represents a change that can be extended (e.g. editbox write).

type History

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

History tracks the sequence of changes and allows for undo and redo.

func NewHistory

func NewHistory(capacity int) *History

NewHistory creates a new History instance with the specified capacity, which determines the maximum amount of changes that will be tracked.

func (*History) CanRedo

func (h *History) CanRedo() bool

CanRedo returns whether there is a tracked change that can be redone.

func (*History) CanUndo

func (h *History) CanUndo() bool

CanUndo returns whether there is a tracked change that can be undone.

func (*History) Clear

func (h *History) Clear()

Clear removes all undo and redo history tracked.

func (*History) Do

func (h *History) Do(change Change)

Do applies the specified change and tracks it in the undo history.

func (*History) LastChange

func (h *History) LastChange() Change

LastChange returns the last applied change, if there is one, otherwise it returns nil.

func (*History) Redo

func (h *History) Redo()

Redo applies a change that was previously undone.

func (*History) Undo

func (h *History) Undo()

Undo reverts the last change and tracks it into the redo history.

Jump to

Keyboard shortcuts

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