Documentation
¶
Index ¶
- func PerformAction[T interface{}](action *Action[T], f ActionFunction[T]) tea.Cmd
- type Action
- func (a Action[T]) HasData() bool
- func (a Action[T]) IsDone() bool
- func (a Action[T]) IsError() bool
- func (a Action[T]) IsLoading() bool
- func (a Action[T]) IsSuccess() bool
- func (action *Action[T]) ProcessInit(a ActionInit[T])
- func (action *Action[t]) ProcessResult(res ActionResult[t])
- func (a *Action[T]) Reset()
- func (a *Action[T]) ResetTea() tea.Cmd
- func (a *Action[T]) Restart()
- func (a *Action[T]) Start()
- func (a *Action[T]) StartTea() tea.Cmd
- type ActionFunction
- type ActionInit
- type ActionResult
- type Actions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PerformAction ¶
func PerformAction[T interface{}](action *Action[T], f ActionFunction[T]) tea.Cmd
Wrapper that makes your life easier when performing an action You can also use the oldschool method of creating a function that returns a tea.Cmd, and use tui.NewResult() with that
Types ¶
type Action ¶
type Action[T interface{}] struct {
Name string
Result bool
Error error
Started bool
Finished bool
Attempt uint // allows you to ignore results from previous attempts
Data *T
}
This is an action that can be performed by a page
func (Action[T]) HasData ¶
Can be used for optimistic updates, where you want to use the previous data while the new data is loading
func (*Action[T]) ProcessInit ¶
func (action *Action[T]) ProcessInit(a ActionInit[T])
Check if an init matches an action and if so, start the action
func (*Action[t]) ProcessResult ¶
func (action *Action[t]) ProcessResult(res ActionResult[t])
Checks if action matches result, and then updates the action with the result
type ActionFunction ¶
type ActionFunction[T interface{}] func() (*T, error)
type ActionInit ¶
type ActionInit[T interface{}] struct {
Name string
}
type ActionResult ¶
type ActionResult[T interface{}] struct {
Name string
Result bool
Error error
ForAttempt uint // allows you to ignore results from previous attempts
Data *T
}
This is a message returned after an action is performed it describes the action and the data that was returned
func NewResult ¶
func NewResult[T interface{}](a Action[T], success bool, err error, data *T, attempt uint) ActionResult[T]
Generate a new ActionResult from an Action
func (ActionResult[T]) IsFor ¶
func (a ActionResult[T]) IsFor(action *Action[T]) bool
Check if a given result is for a specific action and attempt
type Actions ¶
A collection of Actions that can be used by a model
func (Actions) ProcessResults ¶
func (a Actions) ProcessResults(res ActionResult[any])
ProcessResult takes an ActionResult and updates the Actions where the name matches