viewdef

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package viewdef provides viewdef hot-loading support. CRC: crc-ViewdefStore.md Spec: viewdefs.md Sequence: seq-viewdef-hotload.md

CRC: crc-ViewdefStore.md Spec: viewdefs.md

Package viewdef provides viewdef management. CRC: crc-Viewdef.md Spec: viewdefs.md

ViewdefManager loads and serves viewdefs to frontend sessions. Spec: viewdefs.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseKey

func ParseKey(key string) (typeName, namespace string, err error)

ParseKey parses a TYPE.NAMESPACE key into type and namespace.

Types

type HotLoader added in v0.9.0

type HotLoader struct {
	// contains filtered or unexported fields
}

HotLoader watches the viewdef directory for file changes and triggers pushes.

func NewHotLoader added in v0.9.0

func NewHotLoader(cfg *config.Config, viewdefDir string, manager *ViewdefManager, sessions SessionPusher) (*HotLoader, error)

NewHotLoader creates a new hot loader for the given viewdef directory.

func (*HotLoader) Start added in v0.9.0

func (h *HotLoader) Start() error

Start begins watching for file changes.

func (*HotLoader) Stop added in v0.9.0

func (h *HotLoader) Stop() error

Stop stops the hot loader.

type SessionPusher added in v0.9.0

type SessionPusher interface {
	// GetSessionIDs returns a list of active vended session IDs.
	GetSessionIDs() []string
	// PushViewdefs pushes updated viewdefs to a session.
	PushViewdefs(sessionID string, viewdefs map[string]string)
}

SessionPusher provides session management for hot-loading viewdefs. CRC: crc-ViewdefStore.md

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages viewdef storage and delivery.

func NewStore

func NewStore() *Store

NewStore creates a new viewdef store.

func (*Store) Count

func (s *Store) Count() int

Count returns the number of stored viewdefs.

func (*Store) FlushUpdates

func (s *Store) FlushUpdates() map[string]string

FlushUpdates returns pending viewdef updates and clears the queue. Returns nil if no updates pending.

func (*Store) Get

func (s *Store) Get(typeName, namespace string) *Viewdef

Get retrieves a viewdef by TYPE.NAMESPACE. Falls back to TYPE.DEFAULT if TYPE.NAMESPACE not found.

func (*Store) GetByKey

func (s *Store) GetByKey(key string) *Viewdef

GetByKey retrieves a viewdef by TYPE.NAMESPACE key.

func (*Store) GetForType

func (s *Store) GetForType(typeName string) []*Viewdef

GetForType returns all viewdefs for a type.

func (*Store) GetPendingUpdatesJSON

func (s *Store) GetPendingUpdatesJSON() ([]byte, error)

GetPendingUpdatesJSON returns pending updates as JSON for variable 1's viewdefs property.

func (*Store) Has

func (s *Store) Has(typeName, namespace string) bool

Has checks if a viewdef exists.

func (*Store) HasPendingUpdates

func (s *Store) HasPendingUpdates() bool

HasPendingUpdates checks if there are queued viewdef updates.

func (*Store) Keys

func (s *Store) Keys() []string

Keys returns all viewdef keys.

func (*Store) LoadFromFS

func (s *Store) LoadFromFS(fsys fs.FS) error

LoadFromFS loads viewdefs from a filesystem (e.g., embedded or os.DirFS). Expects files at html/viewdefs/TYPE.NAMESPACE.html

func (*Store) QueueForType

func (s *Store) QueueForType(typeName string)

QueueForType queues all viewdefs for a type for delivery. Called when a variable of this type needs its viewdefs.

func (*Store) QueueViewdef

func (s *Store) QueueViewdef(viewdef *Viewdef)

QueueViewdef queues a specific viewdef for delivery.

func (*Store) Remove

func (s *Store) Remove(typeName, namespace string)

Remove deletes a viewdef.

func (*Store) ResetSentTypes

func (s *Store) ResetSentTypes()

ResetSentTypes clears the record of sent types. Call when a new frontend connects.

func (*Store) Store

func (s *Store) Store(viewdef *Viewdef)

Store adds or replaces a viewdef.

type Viewdef

type Viewdef struct {
	Type      string // Type name (e.g., "Contact")
	Namespace string // Namespace (e.g., "DEFAULT", "COMPACT", "OPTION")
	Content   string // HTML template content
}

Viewdef represents a view definition template.

func NewViewdef

func NewViewdef(typeName, namespace, content string) *Viewdef

NewViewdef creates a new viewdef.

func (*Viewdef) GetContent

func (v *Viewdef) GetContent() string

GetContent returns the HTML template content.

func (*Viewdef) GetNamespace

func (v *Viewdef) GetNamespace() string

GetNamespace returns the namespace.

func (*Viewdef) GetType

func (v *Viewdef) GetType() string

GetType returns the type name.

func (*Viewdef) Key

func (v *Viewdef) Key() string

Key returns the TYPE.NAMESPACE identifier string.

type ViewdefManager

type ViewdefManager struct {
	// contains filtered or unexported fields
}

ViewdefManager manages viewdef loading and tracking.

func NewViewdefManager

func NewViewdefManager() *ViewdefManager

NewViewdefManager creates a new viewdef manager.

func (*ViewdefManager) AddNewViewdefsForType added in v0.9.0

func (m *ViewdefManager) AddNewViewdefsForType(sessionID, typeName string, defs map[string]string)

AddNewViewdefsForType loads and marks viewdefs for a type as sent. This is called when a new type is encountered in the variable changes.

func (*ViewdefManager) AddViewdef

func (m *ViewdefManager) AddViewdef(key, content string)

AddViewdef adds or updates a viewdef dynamically. If viewdefDir is set, writes to file and tracks the file path.

func (*ViewdefManager) ClearSession

func (m *ViewdefManager) ClearSession(sessionID string)

ClearSession removes tracking data for a session.

func (*ViewdefManager) Count

func (m *ViewdefManager) Count() int

Count returns the number of loaded viewdefs.

func (*ViewdefManager) GetAllViewdefs

func (m *ViewdefManager) GetAllViewdefs() map[string]string

GetAllViewdefs returns all loaded viewdefs.

func (*ViewdefManager) GetChangedViewdefsForSession added in v0.9.0

func (m *ViewdefManager) GetChangedViewdefsForSession(sessionID string) map[string]string

GetChangedViewdefsForSession returns viewdefs that need to be sent to a session. This includes: - Viewdefs for new types that haven't been sent yet - Viewdefs that have been modified since they were last sent Marks returned viewdefs as sent with their current mod time.

func (*ViewdefManager) GetSessionsForViewdef added in v0.9.0

func (m *ViewdefManager) GetSessionsForViewdef(key string) []string

GetSessionsForViewdef returns all session IDs that have received a viewdef.

func (*ViewdefManager) GetViewdefsForType

func (m *ViewdefManager) GetViewdefsForType(typeName string) map[string]string

GetViewdefsForType returns all viewdefs for a given type. Returns a map of TYPE.NAMESPACE -> HTML content

func (*ViewdefManager) LoadFromBundle

func (m *ViewdefManager) LoadFromBundle() error

LoadFromBundle loads viewdefs from the embedded bundle.

func (*ViewdefManager) LoadFromDirectory

func (m *ViewdefManager) LoadFromDirectory(dir string) error

LoadFromDirectory loads viewdefs from a directory. Files should be named TYPE.NAMESPACE.html (e.g., Adder.DEFAULT.html)

func (*ViewdefManager) LoadFromFS

func (m *ViewdefManager) LoadFromFS(fsys fs.FS, dir string) error

LoadFromFS loads viewdefs from a filesystem (for custom site directories).

func (*ViewdefManager) LoadViewdefsForType added in v0.9.0

func (m *ViewdefManager) LoadViewdefsForType(typeName string)

LoadViewdefsForType loads viewdefs for a type from filesystem into cache. Does not mark them as sent - use GetChangedViewdefsForSession after to get them.

func (*ViewdefManager) MarkViewdefSent added in v0.9.0

func (m *ViewdefManager) MarkViewdefSent(sessionID, key string)

MarkViewdefSent marks a viewdef as sent for a session. Used when pushing viewdefs outside of normal flow (e.g., hot-reload).

func (*ViewdefManager) SetViewdefDir added in v0.9.0

func (m *ViewdefManager) SetViewdefDir(dir string)

SetViewdefDir sets the directory for on-demand viewdef loading.

Jump to

Keyboard shortcuts

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