engine

package
v0.0.0-...-0564b78 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PipelineProcessorKeyStripHLiveAttrs      = "hlive_strip_hlive_attr"
	PipelineProcessorKeyRenderer             = "hlive_renderer"
	PipelineProcessorKeyEventBindingCache    = "hlive_eb"
	PipelineProcessorKeyAttributePluginMount = "hlive_attr_mount"
	PipelineProcessorKeyMount                = "hlive_mount"
	PipelineProcessorKeyUnmount              = "hlive_unmount"
	PipelineProcessorKeyConvertToString      = "hlive_conv_str"
)
View Source
const (
	AttrID     = "hid"
	AttrOn     = "hon"
	AttrUpload = "data-hlive-upload"
)

GoGoRacer special attributes

View Source
const (
	WebSocketDisconnectTimeoutDefault = time.Second * 5
	PageSessionLimitDefault           = 1000
	PageSessionGarbageCollectionTick  = time.Second
)

Defaults

View Source
const EventBindingsCacheDefault = 10 // Default for a small page
View Source
const PipelineProcessorKeyPubSubMount = "hlivekit_ps_mount"
View Source
const PubSubAttributeName = "data-hlive-pubsub"

Variables

View Source
var ErrDOMInvalidated = errors.New("dom invalidated")
View Source
var (
	ErrRenderElement = errors.New("attempted to render an unrecognized element")
)

Public errors

Functions

func IsElement

func IsElement(el any) bool

IsElement returns true is the pass value is a valid Element.

An Element is anything that cna be rendered at HTML.

func IsNode

func IsNode(node any) bool

IsNode returns true is the pass value is a valid Node.

A Node is a value that could be rendered as HTML by itself. An int for example can be converted to a string which is valid HTML. An attribute would not be valid and doesn't make sense to cast to a string.

func IsNonNodeElement

func IsNonNodeElement(el any) bool

func PageOptionDOMFunc

func PageOptionDOMFunc(domFunc func() *NodeGroup) func(*Page)

func PageOptionEventBindingCache

func PageOptionEventBindingCache(m *hashmap.Map[string, *EventBinding]) func(*Page)

func PageOptionRenderer

func PageOptionRenderer(renderer *Renderer) func(*Page)

func Render

func Render(ctx context.Context)

Render will trigger a WebSocket render for the current page

func RenderComponent

func RenderComponent(ctx context.Context, comp Componenter)

RenderComponent will trigger a WebSocket render for the current page from the passed Componenter down only

func RenderElement

func RenderElement(ctx context.Context, comp *UberElement)

RenderElement

Types

type Adder

type Adder interface {
	// Add elements to a Tagger
	Add(elements ...any)
}

Adder interface for inputting elements to Tagger type values.

type Attribute

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

Attribute represents an HTML attribute e.g. id="submitBtn"

func NewAttribute

func NewAttribute(name string, value string) *Attribute

NewAttribute create a new Attribute

func NewAttributeLockBox

func NewAttributeLockBox(name string, value *LockBox[string]) *Attribute

NewAttributeLockBox create a new Attribute using the passed LockBox value

func (*Attribute) Clone

func (a *Attribute) Clone() *Attribute

Clone creates a new Attribute using the data from this Attribute

func (*Attribute) GetName

func (a *Attribute) GetName() string

func (*Attribute) GetValue

func (a *Attribute) GetValue() string

func (*Attribute) IsNoEscapeString

func (a *Attribute) IsNoEscapeString() bool

func (*Attribute) MarshalMsgpack

func (a *Attribute) MarshalMsgpack() ([]byte, error)

func (*Attribute) SetNoEscapeString

func (a *Attribute) SetNoEscapeString(noEscapeString bool)

func (*Attribute) SetValue

func (a *Attribute) SetValue(value string)

func (*Attribute) UnmarshalMsgpack

func (a *Attribute) UnmarshalMsgpack(b []byte) error

type AttributePluginer

type AttributePluginer interface {
	Attributer

	// Initialize will only be called once per attribute name for diff render
	Initialize(page Pager)
	// InitializeSSR will only be called once per attribute name for server side render
	InitializeSSR(page Pager)
}

type Attributer

type Attributer interface {
	GetName() string
	GetValue() string
	IsNoEscapeString() bool
	Clone() *Attribute
}

func InstallPubSub

func InstallPubSub(pubSub *PubSub) Attributer

type Attrs

type Attrs map[string]string

Attrs is a helper for adding and updating Attributes to nodes

func (Attrs) GetAttributers

func (a Attrs) GetAttributers() []Attributer

type AttrsLockBox

type AttrsLockBox map[string]*LockBox[string]

func (AttrsLockBox) GetAttributers

func (a AttrsLockBox) GetAttributers() []Attributer

type AttrsOff

type AttrsOff []string

AttrsOff a helper for removing Attributes

type Cache

type Cache interface {
	Get(key any) (value any, hit bool)
	Set(key any, value any)
}

Cache allow cache adapters to be used in HLive

type Class

type Class string

TODO: add tests and docs

type ClassBool

type ClassBool map[string]bool

ClassBool a special Attribute for working with CSS classes on nodes using a bool to toggle them on and off. It supports turning them on and off and allowing overriding. Due to how Go maps work the order of the classes in the map is not preserved. All Classes are de-duped, overriding a Class by adding new ClassBool will result in the old Class getting updated. You don't have to use ClassBool to add a class attribute, but it's the recommended way to do it.

type ClassList

type ClassList []string

TODO: add tests and docs

type ClassListOff

type ClassListOff []string

TODO: add tests and docs

type ClassOff

type ClassOff string

TODO: add tests and docs

type Component

type Component struct {
	*Tag

	AutoRender bool
	// contains filtered or unexported fields
}

Component is the default implementation of Componenter.

func C

func C(name string, elements ...any) *Component

func NewComponent

func NewComponent(name string, elements ...any) *Component

NewComponent is a constructor for Component.

You can add zero or many Attributes and Tags.

func W

func W(tag *Tag, elements ...any) *Component

W is a shortcut for Wrap.

Wrap takes a Tag and creates a Component with it.

func Wrap

func Wrap(tag *Tag, elements ...any) *Component

Wrap takes a Tag and creates a Component with it.

func (*Component) Add

func (c *Component) Add(elements ...any)

Add an element to this Component.

This is an easy way to add anything.

func (*Component) GetComponent

func (c *Component) GetComponent() Componenter

func (*Component) GetEventBinding

func (c *Component) GetEventBinding(id string) *EventBinding

GetEventBinding will return an EventBinding that exists directly on this element, it doesn't check its children. Returns nil is not found.

func (*Component) GetEventBindings

func (c *Component) GetEventBindings() []*EventBinding

GetEventBindings returns all EventBindings for this component, not it's children.

func (*Component) GetID

func (c *Component) GetID() string

GetID returns this component's unique ID

func (*Component) IsAutoRender

func (c *Component) IsAutoRender() bool

IsAutoRender indicates if this component should trigger "Auto Render"

func (*Component) RemoveEventBinding

func (c *Component) RemoveEventBinding(id string)

RemoveEventBinding removes an EventBinding that matches the passed ID.

No error if the passed id doesn't match an EventBinding. It doesn't check its children.

func (*Component) SetID

func (c *Component) SetID(id string)

SetID component's unique ID

type ComponentMountable

type ComponentMountable struct {
	*Component
	// contains filtered or unexported fields
}

func CM

func CM(name string, elements ...any) *ComponentMountable

CM is a shortcut for NewComponentMountable

func NewComponentMountable

func NewComponentMountable(name string, elements ...any) *ComponentMountable

func WM

func WM(tag *Tag, elements ...any) *ComponentMountable

WM is a shortcut for WrapMountable.

func WrapMountable

func WrapMountable(tag *Tag, elements ...any) *ComponentMountable

WrapMountable takes a Tag and creates a Component with it.

func (*ComponentMountable) AddTeardown

func (c *ComponentMountable) AddTeardown(teardown func())

func (*ComponentMountable) Mount

func (c *ComponentMountable) Mount(ctx context.Context)

func (*ComponentMountable) SetMount

func (c *ComponentMountable) SetMount(mount func(ctx context.Context))

func (*ComponentMountable) SetUnmount

func (c *ComponentMountable) SetUnmount(unmount func(ctx context.Context))

func (*ComponentMountable) Teardown

func (c *ComponentMountable) Teardown()

func (*ComponentMountable) Unmount

func (c *ComponentMountable) Unmount(ctx context.Context)

type ComponentPubSub

type ComponentPubSub struct {
	*ComponentMountable
	// contains filtered or unexported fields
}

ComponentPubSub add PubSub to ComponentMountable

func CPS

func CPS(name string, elements ...any) *ComponentPubSub

CPS is a shortcut for NewComponentPubSub

func NewComponentPubSub

func NewComponentPubSub(name string, elements ...any) *ComponentPubSub

func (*ComponentPubSub) AfterPubSubMount

func (c *ComponentPubSub) AfterPubSubMount(ctx context.Context, pubSub *PubSub)

func (*ComponentPubSub) PubSubMount

func (c *ComponentPubSub) PubSubMount(ctx context.Context, pubSub *PubSub)

func (*ComponentPubSub) SetAfterMountPubSub

func (c *ComponentPubSub) SetAfterMountPubSub(f func(ctx context.Context, pubSub *PubSub))

func (*ComponentPubSub) SetMountPubSub

func (c *ComponentPubSub) SetMountPubSub(f func(ctx context.Context, pubSub *PubSub))

type Componenter

type Componenter interface {
	UniqueTagger
	// GetEventBinding returns a binding by its id
	GetEventBinding(id string) *EventBinding
	// GetEventBindings returns all event bindings for this tag
	GetEventBindings() []*EventBinding
	// RemoveEventBinding remove an event binding from this component
	RemoveEventBinding(id string)
	// IsAutoRender indicates if the page should rerender after an event binding on this tag is called
	IsAutoRender() bool
}

Componenter builds on UniqueTagger and adds the ability to handle events.

type CtxKey

type CtxKey string
const (
	CtxRenderKey          CtxKey = "render"
	CtxRenderComponentKey CtxKey = "render_comp"
)

Context keys

type Differ

type Differ struct {
	JavaScript []byte
	// contains filtered or unexported fields
}

func NewDiffer

func NewDiffer() *Differ

func (*Differ) SetLogger

func (d *Differ) SetLogger(logger zerolog.Logger)

func (*Differ) Trees

func (d *Differ) Trees(selector string, pathIndicies []int, oldNode, newNode any) ([]*diffInfo, error)

Trees diff two node tress

Path: childIndex>childIndex Path: 0>1>3

After tree copy you only have Tagger (with []Attribute), HTML, and strings. Then can be grouped in a NodeGroup

type ElementGroup

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

ElementGroup is a Group of Elements

func Elements

func Elements(elements ...any) *ElementGroup

Elements groups zero or more Element values.

func (*ElementGroup) Add

func (g *ElementGroup) Add(elements ...any)

func (*ElementGroup) Get

func (g *ElementGroup) Get() []any

type Event

type Event struct {
	// The binding that was listening for this event
	Binding *EventBinding
	// If an input has a value set by the browsers on page load, different to the inputs value attribute this type of
	// event is sent. This typically happens on page reload after data has been inputted to a field.
	IsInitial bool
	// The value of the field, if relevant
	Value string
	// Used when an event source could have multiple values
	Values []string
	// Selected is true, for the element interacted with, if a radio or checkbox is checked or a select option is selected.
	// Most relevant for checkbox as it always has a value, this lets you know if they are currently checked or not.
	Selected bool
	// TODO: move to nullable value
	// Key related values are only used on keyboard related events
	Key      string
	CharCode int
	KeyCode  int
	ShiftKey bool
	AltKey   bool
	CtrlKey  bool
	// Used for file inputs and uploads
	File *gas.FromClient_File
	// Extra, for non-browser related data, for use by plugins
	Extra map[string]string
}

type EventBinding

type EventBinding struct {
	// Unique ID for this binding
	ID string
	// Function to call when binding is triggered
	Handler EventHandler
	// Component we are bound to
	Component Componenter
	// Call this binding once then discard it
	Once bool
	// Name of the JavaScript event that will trigger this binding
	Name string
}

func NewEventBinding

func NewEventBinding() *EventBinding

func On

func On(name string, handler EventHandler) *EventBinding

func OnOnce

func OnOnce(name string, handler EventHandler) *EventBinding

type EventHandler

type EventHandler func(ctx context.Context, e Event)

type GetComponenter

type GetComponenter interface {
	GetComponent() Componenter
}

type HTML

type HTML string

HTML must always have a single root element, as we count it as 1 node in the tree but the browser will not if you have multiple root elements

func (*HTML) MarshalMsgpack

func (e *HTML) MarshalMsgpack() ([]byte, error)

func (*HTML) UnmarshalMsgpack

func (e *HTML) UnmarshalMsgpack(b []byte) error

type HTMLElement

type HTMLElement = ComponentMountable

func Element

func Element(name string, elements ...any) *HTMLElement

type LockBox

type LockBox[V any] struct {
	// contains filtered or unexported fields
}

func NewLockBox

func NewLockBox[V any](val V) *LockBox[V]

func (*LockBox[V]) Get

func (b *LockBox[V]) Get() V

func (*LockBox[V]) GetLockedAny

func (b *LockBox[V]) GetLockedAny() any

func (*LockBox[V]) Lock

func (b *LockBox[V]) Lock(f func(val V) V)

func (*LockBox[V]) Set

func (b *LockBox[V]) Set(val V)

type LockBoxer

type LockBoxer interface {
	GetLockedAny() any
}

type Mounter

type Mounter interface {
	UniqueTagger
	// Mount is called after a component is mounted
	Mount(ctx context.Context)
}

Mounter wants to be notified after it's mounted.

type NodeBox

type NodeBox[V any] struct {
	*LockBox[V]
}

func Box

func Box[V any](node V) *NodeBox[V]

func (NodeBox[V]) GetNode

func (b NodeBox[V]) GetNode() any

type NodeBoxer

type NodeBoxer interface {
	GetNode() any
}

type NodeGroup

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

NodeGroup is a Group of Nodes

func G

func G(nodes ...any) *NodeGroup

G is shorthand for Group.

Group zero or more Nodes together.

func Group

func Group(nodes ...any) *NodeGroup

Group zero or more Nodes together.

func (*NodeGroup) Add

func (g *NodeGroup) Add(nodes ...any)

func (*NodeGroup) Get

func (g *NodeGroup) Get() []any

Get returns all nodes, dereferences any valid pointers

func (*NodeGroup) MarshalMsgpack

func (g *NodeGroup) MarshalMsgpack() ([]byte, error)

func (*NodeGroup) UnmarshalMsgpack

func (g *NodeGroup) UnmarshalMsgpack(b []byte) error

type Page

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

func NewPage

func NewPage(options ...PageOption) *Page

func (*Page) Close

func (p *Page) Close(ctx context.Context)

func (*Page) DOMBrowser

func (p *Page) DOMBrowser() any

func (*Page) GetBrowserNodeByID

func (p *Page) GetBrowserNodeByID(id string) *Tag

func (*Page) GetNodes

func (p *Page) GetNodes() *NodeGroup

func (*Page) GetPage

func (p *Page) GetPage() *Page

func (*Page) GetSessionID

func (p *Page) GetSessionID() uint64

func (*Page) HookAfterRenderAdd

func (p *Page) HookAfterRenderAdd(hook func(ctx context.Context, diffs []*gas.Diff, send chan<- *gas.ToClient))

func (*Page) HookBeforeEventAdd

func (p *Page) HookBeforeEventAdd(hook func(context.Context, Event) (context.Context, Event))

func (*Page) HookBeforeMountAdd

func (p *Page) HookBeforeMountAdd(hook func(context.Context, *Page))

func (*Page) HookCloseAdd

func (p *Page) HookCloseAdd(hook func(context.Context, *Page))

func (*Page) HookMountAdd

func (p *Page) HookMountAdd(hook func(context.Context, *Page))

func (*Page) HookUnmountAdd

func (p *Page) HookUnmountAdd(hook func(context.Context, *Page))

func (*Page) PipelineDiff

func (p *Page) PipelineDiff() *Pipeline

func (*Page) PipelineSSR

func (p *Page) PipelineSSR() *Pipeline

func (*Page) RunDiffPipeline

func (p *Page) RunDiffPipeline(ctx context.Context, w io.Writer) (*NodeGroup, error)

func (*Page) RunRenderPipeline

func (p *Page) RunRenderPipeline(ctx context.Context, w io.Writer) (*NodeGroup, error)

func (*Page) ServeHTTP

func (p *Page) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Page) ServeWS

func (p *Page) ServeWS(ctx context.Context, sessID uint64, send chan<- *gas.ToClient, receive <-chan *gas.FromClient) error

func (*Page) SetDOMBrowser

func (p *Page) SetDOMBrowser(dom any)

func (*Page) SetLogger

func (p *Page) SetLogger(logger zerolog.Logger)

type PageFunc

type PageFunc func() Pager

type PageOption

type PageOption func(*Page)

type PageServer

type PageServer struct {
	Sessions *PageSessionStore
	Upgrader websocket.Upgrader
	// contains filtered or unexported fields
}

func MustNewPageServer

func MustNewPageServer(pf PageFunc) *PageServer

func NewPageServer

func NewPageServer(pf func() Pager) (*PageServer, error)

func NewPageServerWithSessionStore

func NewPageServerWithSessionStore(pf PageFunc, sess *PageSessionStore) *PageServer

func (*PageServer) ServeHTTP

func (s *PageServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type PageSession

type PageSession struct {
	Send    chan *gas.ToClient   // Buffered channel of outbound messages.
	Receive chan *gas.FromClient // Buffered channel of inbound messages.
	// contains filtered or unexported fields
}

func (*PageSession) GetContextInitial

func (sess *PageSession) GetContextInitial() context.Context

func (*PageSession) GetContextPage

func (sess *PageSession) GetContextPage() context.Context

func (*PageSession) GetID

func (sess *PageSession) GetID() uint64

func (*PageSession) GetInitialContextCancel

func (sess *PageSession) GetInitialContextCancel() context.CancelFunc

func (*PageSession) GetPage

func (sess *PageSession) GetPage() Pager

func (*PageSession) GetPageContextCancel

func (sess *PageSession) GetPageContextCancel() context.CancelFunc

func (*PageSession) IsConnected

func (sess *PageSession) IsConnected() bool

func (*PageSession) SetConnected

func (sess *PageSession) SetConnected(connected bool)

func (*PageSession) SetContextCancel

func (sess *PageSession) SetContextCancel(cancel context.CancelFunc)

func (*PageSession) SetContextPage

func (sess *PageSession) SetContextPage(ctx context.Context)

func (*PageSession) SetPage

func (sess *PageSession) SetPage(page Pager)

type PageSessionStore

type PageSessionStore struct {
	DisconnectTimeout time.Duration
	SessionLimit      uint32

	GarbageCollectionTick time.Duration
	Done                  chan bool
	// contains filtered or unexported fields
}

func NewPageSessionStore

func NewPageSessionStore() (*PageSessionStore, error)

func (*PageSessionStore) Delete

func (pss *PageSessionStore) Delete(id uint64)

func (*PageSessionStore) GarbageCollection

func (pss *PageSessionStore) GarbageCollection()

func (*PageSessionStore) Get

func (pss *PageSessionStore) Get(id uint64) *PageSession

func (*PageSessionStore) GetSessionCount

func (pss *PageSessionStore) GetSessionCount() int

func (*PageSessionStore) New

func (pss *PageSessionStore) New() (*PageSession, error)

New PageSession.

type Pager

type Pager interface {
	GetPage() *Page
}

type PipeAttributerHandler

type PipeAttributerHandler func(ctx context.Context, w io.Writer, tag Attributer) (Attributer, error)

type PipeNodeGroupHandler

type PipeNodeGroupHandler func(ctx context.Context, w io.Writer, node *NodeGroup) (*NodeGroup, error)

type PipeNodeHandler

type PipeNodeHandler func(ctx context.Context, w io.Writer, node any) (any, error)

type PipeTagHandler

type PipeTagHandler func(ctx context.Context, w io.Writer, tag *Tag) (*Tag, error)

type PipeTaggerHandler

type PipeTaggerHandler func(ctx context.Context, w io.Writer, tagger Tagger) (Tagger, error)

type Pipeline

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

func NewPipeline

func NewPipeline(pps ...*PipelineProcessor) *Pipeline

func (*Pipeline) Add

func (p *Pipeline) Add(processors ...*PipelineProcessor)

func (*Pipeline) AddAfter

func (p *Pipeline) AddAfter(processorKey string, processors ...*PipelineProcessor)

func (*Pipeline) AddBefore

func (p *Pipeline) AddBefore(processorKey string, processors ...*PipelineProcessor)

func (*Pipeline) RemoveAll

func (p *Pipeline) RemoveAll()

func (*Pipeline) Replace

func (p *Pipeline) Replace(processorKey string, processors ...*PipelineProcessor)

type PipelineProcessor

type PipelineProcessor struct {
	// Will replace an existing processor with the same key. An empty string won't error.
	Key             string
	Disabled        bool
	BeforeWalk      PipeNodeGroupHandler
	OnSimpleNode    PipeNodeHandler
	BeforeTagger    PipeTaggerHandler
	BeforeAttribute PipeAttributerHandler
	AfterAttribute  PipeAttributerHandler
	AfterTagger     PipeTagHandler
	AfterWalk       PipeNodeGroupHandler
}

func NewPipelineProcessor

func NewPipelineProcessor(key string) *PipelineProcessor

func PipelineProcessorAttributePluginMount

func PipelineProcessorAttributePluginMount(page Pager) *PipelineProcessor

func PipelineProcessorAttributePluginMountSSR

func PipelineProcessorAttributePluginMountSSR(page Pager) *PipelineProcessor

func PipelineProcessorConvertToString

func PipelineProcessorConvertToString() *PipelineProcessor

func PipelineProcessorEventBindingCache

func PipelineProcessorEventBindingCache(cache *hashmap.Map[string, *EventBinding]) *PipelineProcessor

func PipelineProcessorMount

func PipelineProcessorMount() *PipelineProcessor

func PipelineProcessorRenderer

func PipelineProcessorRenderer(renderer *Renderer) *PipelineProcessor

func PipelineProcessorUnmount

func PipelineProcessorUnmount(page Pager) *PipelineProcessor

type PubSub

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

func NewPubSub

func NewPubSub() *PubSub

func (*PubSub) Publish

func (ps *PubSub) Publish(topic string, value any)

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(sub QueueSubscriber, topics ...string)

func (*PubSub) SubscribeFunc

func (ps *PubSub) SubscribeFunc(subFunc func(message QueueMessage), topics ...string) SubscribeFunc

func (*PubSub) SubscribeWait

func (ps *PubSub) SubscribeWait(sub QueueSubscriber, topics ...string)

func (*PubSub) SubscribeWaitFunc

func (ps *PubSub) SubscribeWaitFunc(subFunc func(message QueueMessage), topics ...string) SubscribeFunc

func (*PubSub) Unsubscribe

func (ps *PubSub) Unsubscribe(sub QueueSubscriber, topics ...string)

func (*PubSub) UnsubscribeWait

func (ps *PubSub) UnsubscribeWait(sub QueueSubscriber, topics ...string)

type PubSubAfterMounter

type PubSubAfterMounter interface {
	PubSubMounter
	AfterPubSubMount(context.Context, *PubSub)
}

type PubSubAttribute

type PubSubAttribute struct {
	*Attribute
	// contains filtered or unexported fields
}

func (*PubSubAttribute) Initialize

func (a *PubSubAttribute) Initialize(page *Page)

func (*PubSubAttribute) InitializeSSR

func (a *PubSubAttribute) InitializeSSR(page *Page)

func (*PubSubAttribute) PipelineProcessorPubSub

func (a *PubSubAttribute) PipelineProcessorPubSub() *PipelineProcessor

type PubSubMounter

type PubSubMounter interface {
	GetID() string
	PubSubMount(context.Context, *PubSub)
}

type PubSubSSRMounter

type PubSubSSRMounter interface {
	GetID() string
	PubSubSSRMount(context.Context, *PubSub)
}

type QueueMessage

type QueueMessage struct {
	Topic string
	Value any
}

type QueueSubscriber

type QueueSubscriber interface {
	GetID() string
	OnMessage(message QueueMessage)
}

type Renderer

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

func NewRenderer

func NewRenderer() *Renderer

func (*Renderer) Attribute

func (r *Renderer) Attribute(attrs []Attributer, w io.Writer) error

Attribute renders an Attribute to it's HTML string representation While it's possible to have HTML attributes without values it simplifies things if we always have a value

func (*Renderer) HTML

func (r *Renderer) HTML(w io.Writer, el any) error

HTML renders items that can be render to valid HTML nodes

func (*Renderer) SetLogger

func (r *Renderer) SetLogger(logger zerolog.Logger)

type Style

type Style map[string]string

Style is a special Element that allows you to work the properties of style attribute. A property and value will be added or updated. You don't have to use Style to add a style attribute, but it's the recommended way to do it.

type StyleLockBox

type StyleLockBox map[string]*LockBox[string]

StyleLockBox like Style but, you can update the property values indirectly TODO: add test

type StyleOff

type StyleOff []string

StyleOff remove an existing style property, ignored if the property doesn't exist TODO: add test

type SubscribeFunc

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

func NewSub

func NewSub(onMessageFn func(message QueueMessage)) SubscribeFunc

func (SubscribeFunc) GetID

func (s SubscribeFunc) GetID() string

func (SubscribeFunc) OnMessage

func (s SubscribeFunc) OnMessage(message QueueMessage)

type Tag

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

Tag is the default HTML tag implementation.

Use T or NewTag to create a value.

func NewTag

func NewTag(name string, elements ...any) *Tag

NewTag creates a new Tag value.

func T

func T(name string, elements ...any) *Tag

func (*Tag) Add

func (t *Tag) Add(element ...any)

Add zero or more elements to this Tag.

func (*Tag) AddAttributes

func (t *Tag) AddAttributes(attrs ...any)

AddAttributes will add zero or more attributes types (Attributer, Attribute, Attrs, Style, ClassBool).

Adding an attribute with the same name will override an existing attribute.

func (*Tag) GetAttribute

func (t *Tag) GetAttribute(name string) Attributer

GetAttribute returns an Attributer value by its name.

This includes attribute values related to Class, and Style. If an Attributer of the passed name has not been set `nil` it's returned.

func (*Tag) GetAttributeValue

func (t *Tag) GetAttributeValue(name string) string

GetAttributeValue returns a value for a given Attributer name.

If an attribute has not yet been set, then an empty string is returned.

func (*Tag) GetAttributes

func (t *Tag) GetAttributes() []Attributer

GetAttributes returns a list of Attributer values that this tag has.

Any Class, Style values are returned here as Attribute values.

func (*Tag) GetName

func (t *Tag) GetName() string

GetName get the tag name.

func (*Tag) GetNodes

func (t *Tag) GetNodes() *NodeGroup

GetNodes returns a NodeGroup with any child Nodes that have been added to this Node.

func (*Tag) IsNil

func (t *Tag) IsNil() bool

IsNil returns true if pointer is nil

func (*Tag) IsVoid

func (t *Tag) IsVoid() bool

IsVoid indicates if this is a void type tag, e.g. `<hr>`.

func (*Tag) MarshalMsgpack

func (t *Tag) MarshalMsgpack() ([]byte, error)

func (*Tag) RemoveAttributes

func (t *Tag) RemoveAttributes(names ...string)

func (*Tag) SetName

func (t *Tag) SetName(name string)

SetName sets the tag name, e.g. for a `<div>` it's the `div` part.

func (*Tag) SetVoid

func (t *Tag) SetVoid(void bool)

SetVoid sets the tag to be a void type tag e.g. `<hr>`.

func (*Tag) UnmarshalMsgpack

func (t *Tag) UnmarshalMsgpack(b []byte) error

type Tagger

type Tagger interface {
	// GetName returns a tag's name. For example <hr>'s name is hr.
	GetName() string
	// GetAttributes returns all attributes for this tag.
	GetAttributes() []Attributer
	// GetNodes returns this tags children nodes, to be rendered inside this tag.
	GetNodes() *NodeGroup
	// IsVoid indicates if this has a closing tag or not. Void tags don't have a closing tag.
	IsVoid() bool
	// IsNil returns true if pointer is nil.
	//
	// It's easy to create something like `var t *Tag` but forget to give it a value.
	// This allows us to not have panics in that case.
	IsNil() bool
}

Tagger represents a static HTML tag.

type Teardowner

type Teardowner interface {
	UniqueTagger
	// AddTeardown adds a teardown function
	AddTeardown(teardown func())
	// Teardown call the set teardown function passed in SetTeardown
	Teardown()
}

Teardowner wants to have manual control when it needs to be removed from a Page. If you have a Mounter or Unmounter that will be permanently removed from a Page they must call the passed function to clean up their references.

type UberChild

type UberChild interface {
	// contains filtered or unexported methods
}

type UberElement

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

func Uber

func Uber(tagName string) *UberElement

func (*UberElement) Attr

func (ue *UberElement) Attr(attrs ...Attributer) *UberElement

func (*UberElement) AttrRemove

func (ue *UberElement) AttrRemove(keys ...string) *UberElement

func (*UberElement) Box

func (ue *UberElement) Box(box NodeBoxer) *UberElement

func (*UberElement) Class

func (ue *UberElement) Class(class string) *UberElement

func (*UberElement) ClassOff

func (ue *UberElement) ClassOff(class string) *UberElement

func (*UberElement) Component

func (ue *UberElement) Component(components ...GetComponenter) *UberElement

func (*UberElement) Element

func (ue *UberElement) Element(childElements ...UberChild) *UberElement

func (*UberElement) GetComponent

func (ue *UberElement) GetComponent() Componenter

func (*UberElement) GetComponentPubSub

func (ue *UberElement) GetComponentPubSub() *ComponentPubSub

TODO: do something better

func (*UberElement) HTML

func (ue *UberElement) HTML(htmlVal string) *UberElement

func (*UberElement) IntoBox

func (ue *UberElement) IntoBox() UberElementBox

func (*UberElement) LockBox

func (ue *UberElement) LockBox(box LockBoxer) *UberElement

func (*UberElement) On

func (ue *UberElement) On(eventBindings ...*EventBinding) *UberElement

func (*UberElement) RemoveEventBinding

func (ue *UberElement) RemoveEventBinding(eventBindingID string) *UberElement

func (*UberElement) SetAfterMountPubSub

func (ue *UberElement) SetAfterMountPubSub(f func(ctx context.Context, pubSub *PubSub)) *UberElement

func (*UberElement) SetMount

func (ue *UberElement) SetMount(mount func(ctx context.Context)) *UberElement

func (*UberElement) SetMountPubSub

func (ue *UberElement) SetMountPubSub(f func(ctx context.Context, pubSub *PubSub)) *UberElement

func (*UberElement) SetUnmount

func (ue *UberElement) SetUnmount(unmount func(ctx context.Context)) *UberElement

func (*UberElement) Style

func (ue *UberElement) Style(key, value string) *UberElement

func (*UberElement) Styles

func (ue *UberElement) Styles(styles Style) *UberElement

func (*UberElement) Val

func (ue *UberElement) Val() *UberValue

type UberElementBox

type UberElementBox struct {
	*NodeBox[*UberElement]
}

type UberValue

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

func (*UberValue) BindStr

func (uv *UberValue) BindStr(val *string) *UberElement

func (*UberValue) Int

func (uv *UberValue) Int(val int) *UberElement

func (*UberValue) Str

func (uv *UberValue) Str(val string) *UberElement

type UniqueAdder

type UniqueAdder interface {
	Adder
	// GetID will return a unique id
	GetID() string
}

UniqueAdder is an Adder that can be uniquely identified in a DOM Tree.

type UniqueTagger

type UniqueTagger interface {
	Tagger
	// GetID will return a unique id
	GetID() string
	// SetID Components will be assigned a unique id
	SetID(id string)
}

UniqueTagger is a Tagger that can be uniquely identified in a DOM Tree.

type Unmounter

type Unmounter interface {
	UniqueTagger
	// Unmount is called before a component is unmounted
	Unmount(ctx context.Context)
}

Unmounter wants to be notified before it's unmounted.

Jump to

Keyboard shortcuts

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