prop

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Border

type Border = Prop[*style.Border]

type Color

type Color = Prop[*style.Color]

type Presettable

type Presettable interface {
	Preset(
		ctx context.Context,
		context interface{},
		params ...interface{},
	)
	SetLogger(log zerolog.Logger)
	ClearCache()
}

Presettable is a general interface for providing preset values to many properties at once.

type Prop

type Prop[T any] struct {
	// contains filtered or unexported fields
}

Prop is a property that can be either static or dynamic. If it is static, it will always return the same value. If it is dynamic, it will call a Janet function to calculate the value.

func NewStatic

func NewStatic[T any](value T) *Prop[T]

NewStatic creates a new static property with the given value.

func (*Prop[T]) ClearCache

func (p *Prop[T]) ClearCache()

ClearCache clears the cache of the property, forcing it to be recalculated on the next call to Get if necessary.

func (*Prop[T]) Get

func (p *Prop[T]) Get(
	ctx context.Context,
	context interface{},
	params ...interface{},
) (value T, ok bool)

Get returns the value of the property. If the property is static, it will return the value and true. If the property is dynamic, it will call the function with the context and parameters and return the result.

func (*Prop[T]) GetPreset

func (p *Prop[T]) GetPreset() (value T, ok bool)

GetPreset returns the value of the property, computing it using the preset values provided in the Preset method.

func (*Prop[T]) MarshalJanet

func (p *Prop[T]) MarshalJanet() interface{}

func (*Prop[T]) Preset

func (p *Prop[T]) Preset(
	ctx context.Context,
	context interface{},
	params ...interface{},
)

Preset sets the context and parameters for the property ahead of time. This is useful for properties that are dynamic and need to be calculated with a specific context and parameters.

func (*Prop[T]) SetLogger

func (p *Prop[T]) SetLogger(log zerolog.Logger)

SetLogger sets the logger for the property. This is useful for debugging purposes.

func (*Prop[T]) SetTTL

func (p *Prop[T]) SetTTL(ttl time.Duration)

SetTTL sets the time-to-live for the property. This is the amount of time to wait before recalculating the property.

func (*Prop[T]) Static

func (p *Prop[T]) Static() (value T, ok bool)

Static reports whether the property is static. If it is, it will return the value and true. If it is not, it will return the zero value of the type and false.

func (*Prop[T]) UnmarshalJanet

func (p *Prop[T]) UnmarshalJanet(value *janet.Value) error

type String

type String = Prop[string]

Jump to

Keyboard shortcuts

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