Documentation
¶
Overview ¶
Package loader provides primitives to load an applet both when the underlying file changes and on demand when an update is requested.
Index ¶
- func RenderApplet(ctx context.Context, path string, config map[string]any, options ...Option) ([]byte, []string, error)
- type ImageFormat
- type Loader
- func (l *Loader) CallSchemaHandler(ctx context.Context, config map[string]any, handlerName, parameter string) (string, error)
- func (l *Loader) Close() error
- func (l *Loader) GetMainFile() string
- func (l *Loader) GetSchema() []byte
- func (l *Loader) LoadApplet(config map[string]any) (string, error)
- func (l *Loader) Locale() language.Tag
- func (l *Loader) Location() *time.Location
- func (l *Loader) Meta() canvas.Metadata
- func (l *Loader) Run(ctx context.Context) error
- func (l *Loader) SetIs2x(is2x bool)
- func (l *Loader) SetLocale(loc string) error
- func (l *Loader) SetTimezone(tz string) error
- type Option
- func WithFilters(filters encode.RenderFilters) Option
- func WithImageFormat(imageFormat ImageFormat) Option
- func WithLanguage(lang language.Tag) Option
- func WithLocation(location *time.Location) Option
- func WithMaxDuration(maxDuration time.Duration) Option
- func WithMeta(meta canvas.Metadata) Option
- func WithShowFullAnimation(v *bool) Option
- func WithSilenceOutput(silenceOutput bool) Option
- func WithTimeout(timeout time.Duration) Option
- type RenderConfig
- type Update
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is a structure to provide applet loading when a file changes or on demand.
func NewLoader ¶
func NewLoader( id string, root *os.Root, watch bool, fileChanges chan struct{}, updatesChan chan Update, configOutFile string, options ...Option, ) (*Loader, error)
NewLoader instantiates a new loader structure. The loader will read off of fileChanges channel and write updates to the updatesChan. Updates are base64 encoded WebP strings. If watch is enabled, both file changes and on demand requests will send updates over the updatesChan.
func (*Loader) CallSchemaHandler ¶
func (*Loader) GetMainFile ¶ added in v0.51.1
func (*Loader) LoadApplet ¶
LoadApplet loads the applet on demand.
TODO: This method is thread safe, but has a pretty glaring race condition. If two callers request an update at the same time, they have the potential to get each others update. At the time of writing, this method is only called when you refresh a webpage during app development - so it doesn't seem likely that it's going to cause issues in the short term.
func (*Loader) Run ¶
Run executes the main loop. If there are config changes, those are recorded. If there is an on-demand request, it's processed and sent back to the caller and sent out as an update. If there is a file change, we update the applet and send out the update over the updatesChan.
func (*Loader) SetTimezone ¶ added in v0.49.0
type Option ¶ added in v0.49.0
type Option func(config *RenderConfig)
func WithFilters ¶ added in v0.49.0
func WithFilters(filters encode.RenderFilters) Option
func WithImageFormat ¶ added in v0.49.0
func WithImageFormat(imageFormat ImageFormat) Option
func WithLanguage ¶ added in v0.49.0
func WithLocation ¶ added in v0.49.0
func WithMaxDuration ¶ added in v0.49.0
func WithShowFullAnimation ¶ added in v0.51.3
func WithSilenceOutput ¶ added in v0.49.0
func WithTimeout ¶ added in v0.49.0
type RenderConfig ¶ added in v0.49.0
type RenderConfig struct {
Path string
Config map[string]any
Meta canvas.Metadata
MaxDuration time.Duration
ShowFullAnimation *bool
Timeout time.Duration
ImageFormat ImageFormat
SilenceOutput bool
Location *time.Location
Language language.Tag
Filters encode.RenderFilters
}
func NewRenderConfig ¶ added in v0.49.0
func NewRenderConfig(path string, config map[string]any, options ...Option) *RenderConfig