command

package
v1.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotReceiver    = errors.New("not implement receiver interface")
	ErrNotCommand     = errors.New("not implement Command interface")
	ErrNotUndoCommand = errors.New("not implement UndoCommand interface")
	ErrNotRedoCommand = errors.New("not implement RedoCommand interface")
)
View Source
var (
	ErrNotFoundUndoCommand = errors.New("not found command in undo command stack")
	ErrNotFoundRedoCommand = errors.New("not found command in redo command stack")
)

Functions

This section is empty.

Types

type CommandFunc

type CommandFunc func(ctx context.Context) (context.Context, error)

The CommandFunc type is an adapter to allow the use of ordinary functions as Command. If f is a function with the appropriate signature, CommandFunc(f) is a Command that calls f.

func (CommandFunc) Execute

func (f CommandFunc) Execute(ctx context.Context) (context.Context, error)

Execute calls f(ctx).

type ConcreteCommand

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

func NewConcreteCommand

func NewConcreteCommand(receiver Receiver) *ConcreteCommand

func (*ConcreteCommand) Execute

func (cmd *ConcreteCommand) Execute(ctx context.Context) error

type Handler added in v1.3.0

type Handler[C any] interface {
	Handle(ctx context.Context, cmd C) error
}

Handler is a command handler that to encapsulate a unit of processing work to be performed.

type Invoker

type Invoker struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Invoker) Call

func (invoker *Invoker) Call(ctx context.Context, cmd Command) (context.Context, error)

func (*Invoker) Redo

func (invoker *Invoker) Redo(ctx context.Context) (context.Context, error)

func (*Invoker) Undo

func (invoker *Invoker) Undo(ctx context.Context) (context.Context, error)

type Middleware

type Middleware interface {
	// Decorate wraps the underlying Command, adding some functionality.
	Decorate(cmd Command) Command
}

Middleware allows us to write something like decorators to Command. It can execute something before Execute or after.

type MiddlewareFunc

type MiddlewareFunc func(cmd Command) Command

The MiddlewareFunc type is an adapter to allow the use of ordinary functions as Middleware. If f is a function with the appropriate signature, MiddlewareFunc(f) is a Middleware that calls f.

func (MiddlewareFunc) Decorate

func (f MiddlewareFunc) Decorate(cmd Command) Command

Decorate call f(cmd).

type Receiver

type Receiver interface {
	Action(ctx context.Context) error
}

type RedoCommandFunc

type RedoCommandFunc func(ctx context.Context) (context.Context, error)

The RedoCommandFunc type is an adapter to allow the use of ordinary functions as RedoCommand. If f is a function with the appropriate signature, RedoCommandFunc(f) is a RedoCommand that calls f.

func (RedoCommandFunc) Redo

Redo calls f(ctx).

type RedoHandler added in v1.3.0

type RedoHandler[C any] interface {
	Handle(ctx context.Context, cmd C) error
}

RedoHandler redo a Command

type RichCommand

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

func NewRichCommand

func NewRichCommand(cmd Command, undoCmd UndoCommand, redoCmd RedoCommand) *RichCommand

func (*RichCommand) Execute

func (cmd *RichCommand) Execute(ctx context.Context) (context.Context, error)

func (*RichCommand) Redo

func (cmd *RichCommand) Redo(ctx context.Context) (context.Context, error)

func (*RichCommand) Undo

func (cmd *RichCommand) Undo(ctx context.Context) (context.Context, error)

type UndoCommandFunc

type UndoCommandFunc func(ctx context.Context) (context.Context, error)

The UndoCommandFunc type is an adapter to allow the use of ordinary functions as UndoCommand. If f is a function with the appropriate signature, UndoCommandFunc(f) is a UndoCommand that calls f.

func (UndoCommandFunc) Undo

Undo calls f(ctx).

type UndoHandler added in v1.3.0

type UndoHandler[C any] interface {
	Handle(ctx context.Context, cmd C) error
}

UndoHandler undo a Command

Jump to

Keyboard shortcuts

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