Documentation ¶
Index ¶
- func AfterUpdate(afterUpdater AfterUpdater)
- func CurrentRoute() string
- func Destroy() tea.Msg
- func New(root Component[NoProps]) model
- func NewProgram(root Component[NoProps], options ...tea.ProgramOption) *tea.Program
- func RenderAny[TProps any, TRenderer AnyRenderer[TProps]](renderer TRenderer, props TProps, width, height int) (result string)
- func RouteMatchesPlaceholder(route string, placeholder string) (map[string]string, bool)
- func SetCurrentRoute(newRoute string)
- func WasRouteChanged() bool
- func WithRoute(route string) func(*tea.Program)
- func WithoutInput() func(*tea.Program)
- type AfterUpdater
- type AnyProplessRenderer
- type AnyRenderer
- type BasicComponent
- type BasicPropfulComponent
- type Component
- type DumbRenderer
- type InvisibleComponent
- type NoProps
- type ProplessRenderer
- type Renderer
- type SomeComponent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AfterUpdate ¶
func AfterUpdate(afterUpdater AfterUpdater)
Queue component for AfterUpdate event
func CurrentRoute ¶
func CurrentRoute() string
func NewProgram ¶ added in v0.3.0
It simplifies tea.NewProgram(reactea.New(root), opts...) to reactea.NewProgram(root, opts...)
Note: Return type is *tea.Program, Reactea doesn't have it's own wrapper (reactea.Program) type, yet (?)
func RenderAny ¶
func RenderAny[TProps any, TRenderer AnyRenderer[TProps]](renderer TRenderer, props TProps, width, height int) (result string)
Renders all AnyRenderers in one function
Note: If you are using ProplessRenderer/DumbRenderer just pass reactea.NoProps{} or struct{}{}
Note: Using named return type for 100% coverage
func RouteMatchesPlaceholder ¶ added in v0.4.0
Checks whether route (e.g. teams/123/12) matches placeholder (e.g teams/:teamId/:playerId) Returns map of found params and if it matches Params have to follow regex ^:.*$ ^ being beginning of current path level (/^level/) $ being end of current path level (/level$/)
Note: Entire matched route can be accessed with key "$" Note: Placeholders can be optional => foo/?:/?: will match foo/bar and foo and foo/bar/baz Note: The most outside placeholders can be optional recursive => foo/+?: will match foo/bar and foo and foo/bar/baz Note: It allows for defining wildcards with foo/:/bar Note: Duplicate params will result in overwrite of first param
func SetCurrentRoute ¶
func SetCurrentRoute(newRoute string)
func WasRouteChanged ¶
func WasRouteChanged() bool
func WithoutInput ¶ added in v0.3.1
Useful for testing on Github Actions, by default Bubble Tea would try reading from /dev/tty, but on Github Actions it's restricted resulting in error
Types ¶
type AfterUpdater ¶
type AnyProplessRenderer ¶ added in v0.2.0
type AnyProplessRenderer interface { ProplessRenderer | DumbRenderer }
type AnyRenderer ¶ added in v0.2.0
type AnyRenderer[TProps any] interface { func(TProps, int, int) string | AnyProplessRenderer }
Why not Renderer[TProps]? It would have to be type alias there are no type aliases yet for generics, but they are planned for Go 1.20. Something to keep in mind for future
type BasicComponent ¶
type BasicComponent struct{}
The most basic form of Reactea Component It implements all not required methods so you don't have to
func (*BasicComponent) AfterUpdate ¶
func (c *BasicComponent) AfterUpdate() tea.Cmd
func (*BasicComponent) Destroy ¶
func (c *BasicComponent) Destroy()
type BasicPropfulComponent ¶
type BasicPropfulComponent[TProps any] struct { // contains filtered or unexported fields }
Stores props in struct. If you want to derive state from UpdateProps() you're probably looking at wrong thing
func (*BasicPropfulComponent[TProps]) Init ¶
func (c *BasicPropfulComponent[TProps]) Init(props TProps) tea.Cmd
func (*BasicPropfulComponent[TProps]) Props ¶
func (c *BasicPropfulComponent[TProps]) Props() TProps
func (*BasicPropfulComponent[TProps]) UpdateProps ¶
func (c *BasicPropfulComponent[TProps]) UpdateProps(props TProps)
type Component ¶
type Component[TProps any] interface { // You always have to initialize component with some kind of // props - it can even be zero value // Init() Is meant to both initialize subcomponents and run // long IO operations through tea.Cmd Init(TProps) tea.Cmd // It's called when component is about to be destroyed // // Note: It's parent component's job to call it so // relying on it outside of Reactea builtins is // not reliable Destroy() // Typical tea.Model Update(), we handle all IO events here Update(tea.Msg) tea.Cmd // Callee already knows at which size should it render at Render(int, int) string // It's an Update() but for props, the state derive stage // happens here UpdateProps(TProps) // AfterUpdate is stage useful for components like routers // to prepare content. Saying that you will probably never // need to use it AfterUpdate() tea.Cmd }
func Componentify ¶ added in v0.2.0
func Componentify[TProps any, TRenderer AnyRenderer[TProps]](renderer TRenderer) Component[TProps]
Componentifies AnyRenderer Returns uninitialized component with renderer taking care of .Render()
type DumbRenderer ¶
type DumbRenderer = func() string
Doesn't have state, props, even scalling for target dimensions = DumbRenderer, or Stringer
type InvisibleComponent ¶
type InvisibleComponent struct{}
Utility component for displaying empty string on Render()
type ProplessRenderer ¶
SUPEEEEEER shorthand for components
func PropfulToLess ¶
func PropfulToLess[TProps any](renderer Renderer[TProps], props TProps) ProplessRenderer
Wraps propful into propless renderer