duplex

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package duplex is a redux-like state management for bubbletea to build nice TUI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reduce

func Reduce[S State](curr S, reducers []Reducer[S], actions ...Action) iter.Seq[State]

Reduce is the type of the reducer of the store.

Types

type Action

type Action func() (Update, error)

Action is the type of the action of the store.

type Duplexer

type Duplexer[S State] interface {
	// Dispatch dispatches an event to the store.
	Dispatch(actions Action) tea.Cmd
}

Duplexer is the interface for the duplex state machine.

func New

func New[S State](initialState S, reducers ...Reducer[S]) Duplexer[S]

New creates a new store.

type Reducer

type Reducer[S State] func(curr S, update Update) S

Reducer is the type of the reducer of the store.

type State

type State any

State is the type of the state of the store.

type StateChangeError

type StateChangeError struct{}

StateChangeError ...

type StateChangeMsg

type StateChangeMsg[S State] interface {
	// Prev gets the previous state of the store.
	Prev() S
	// Curr gets the current state of the store.
	Curr() S
}

StateChangeMsg is a message that contains the.

func NewStateChangeMsg

func NewStateChangeMsg[S State](prev, curr S) StateChangeMsg[S]

NewStateChangeMsg creates a new state change.

type Update

type Update any

Update is the type of the update of the store.

Jump to

Keyboard shortcuts

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