hlivekit

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 10 Imported by: 7

README

HLiveKit

A toolkit of useful functionality for HLive

Features:

  • Focus
    • Give a node input focus
  • On Diff Apply
    • Call a handler after a HLive diff has been applied in the browser
  • Component List
    • Manage a dynamic list of components, for example results of a search.
  • Component List Simple (Advanced)
    • Like a Component List but without the memory cleanup logic.

Ideas

  • Add client side interactions for real-time feedback
  • Key binding to, for example, submit a form?
  • x-cloak like feature
    • Hide things until HLive had initialised
  • Copy to clipboard
    • navigator.clipboard.writeText(<value>)
  • Drag and drop

Documentation

Index

Constants

View Source
const (
	DiffApplyEvent         = "diffapply"
	DiffApplyAttributeName = "data-hlive-on-diffapply"
)
View Source
const FocusAttributeName = "data-hlive-focus"
View Source
const PipelineProcessorKeyPubSubMount = "hlivekit_ps_mount"
View Source
const (
	PreemptDisableAttributeName = "data-hlive-pre-disable"
)
View Source
const PubSubAttributeName = "data-hlive-pubsub"
View Source
const RedirectAttributeName = "data-redirect"
View Source
const ScrollTopAttributeName = "data-scrollTop"

Variables

View Source
var DiffApplyScript []byte
View Source
var ErrInvalidListAdd = errors.New("value is not valid for a list")
View Source
var FocusJavaScript []byte
View Source
var PreemptDisableOnClickJavaScript []byte
View Source
var RedirectJavaScript []byte
View Source
var ScrollTopJavaScript []byte

Functions

func Focus

func Focus() l.Attributer

func FocusRemove

func FocusRemove(tag l.Adder)

func InstallPubSub

func InstallPubSub(pubSub *PubSub) hlive.Attributer

func OnDiffApply

func OnDiffApply(handler l.EventHandler) *l.ElementGroup

func OnDiffApplyOnce

func OnDiffApplyOnce(handler l.EventHandler) *l.ElementGroup

TODO: how we remove the attribute once done?

func PreemptDisableOn

func PreemptDisableOn(eb *l.EventBinding) *l.ElementGroup

TODO: Once?

func Redirect

func Redirect(url string) l.Attributer

func ScrollTop

func ScrollTop(val int) l.Attributer

func ScrollTopRemove

func ScrollTopRemove(tag l.Adder)

Types

type CacheRistretto added in v0.2.0

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

CacheRistretto cache adapter for Ristretto

func NewCacheRistretto added in v0.2.0

func NewCacheRistretto(cache *ristretto.Cache) *CacheRistretto

func (*CacheRistretto) Get added in v0.2.0

func (c *CacheRistretto) Get(key any) (any, bool)

func (*CacheRistretto) Set added in v0.2.0

func (c *CacheRistretto) Set(key any, value any)

type ComponentGetNodes

type ComponentGetNodes struct {
	*hlive.ComponentMountable

	GetNodesFunc func() *hlive.NodeGroup
}

ComponentGetNodes add a custom GetNodes function to ComponentMountable

func CGN

func CGN(name string, getNodesFunc func() *hlive.NodeGroup, elements ...any) *ComponentGetNodes

CGN is a shortcut for NewComponentGetNodes

func NewComponentGetNodes

func NewComponentGetNodes(name string, getNodesFunc func() *hlive.NodeGroup, elements ...any) *ComponentGetNodes

func (*ComponentGetNodes) GetNodes

func (c *ComponentGetNodes) GetNodes() *hlive.NodeGroup

type ComponentList

type ComponentList struct {
	*ComponentListSimple
}

ComponentList is a way to manage a dynamic collection of Teardowner Node values. For example, the rows of a table.

As the Node values in ComponentList are often added and removed there lies the possibility of memory leaks. To prevent this the items in the list must be Teardowner values. The list will call Teardown on each item as long as they are removed using its RemoveItem and RemoveAllItems functions.

See NewComponentMountable, CM, WrapMountable, and WM for help with creating Teardowner values.

func List

func List(name string, elements ...any) *ComponentList

List is a shortcut for NewComponentList.

func NewComponentList

func NewComponentList(name string, elements ...any) *ComponentList

NewComponentList returns a value of ComponentList

func (*ComponentList) Add

func (list *ComponentList) Add(elements ...any)

Add an element to this Component.

You can add Groups, Teardowner, EventBinding, or None Node Elements

func (*ComponentList) AddItem

func (list *ComponentList) AddItem(items ...l.Teardowner)

AddItem allows you to add a node to the list

Add nodes are often added and removed nodes needed to be a Teardowner. See NewComponentMountable, CM, WrapMountable, and WM for help with creating Teardowner values.

func (*ComponentList) RemoveAllItems

func (list *ComponentList) RemoveAllItems()

RemoveAllItems empties the list of items and calls Teardown on each of them.

func (*ComponentList) RemoveItems

func (list *ComponentList) RemoveItems(items ...l.Teardowner)

RemoveItems will remove a Teardowner can call its Teardown function.

type ComponentListSimple

type ComponentListSimple struct {
	*l.ComponentMountable
	// contains filtered or unexported fields
}

ComponentListSimple is a version of ComponentList that doesn't have the Teardown logic

func NewComponentListSimple

func NewComponentListSimple(name string, elements ...any) *ComponentListSimple

NewComponentListSimple creates a ComponentListSimple value

func (*ComponentListSimple) Add

func (list *ComponentListSimple) Add(elements ...any)

Add an element to this ComponentListSimple.

You can add Groups, UniqueTagger, EventBinding, or None Node Elements

func (*ComponentListSimple) AddItems

func (list *ComponentListSimple) AddItems(items ...l.UniqueTagger)

func (*ComponentListSimple) GetNodes

func (list *ComponentListSimple) GetNodes() *l.NodeGroup

GetNodes returns the list of items.

func (*ComponentListSimple) RemoveAllItems

func (list *ComponentListSimple) RemoveAllItems()

func (*ComponentListSimple) RemoveItems

func (list *ComponentListSimple) RemoveItems(items ...l.UniqueTagger)

type ComponentPubSub

type ComponentPubSub struct {
	*hlive.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 WCPS added in v0.2.1

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

WCPS is a shortcut for WrapComponentPubSub

func WrapComponentPubSub added in v0.2.1

func WrapComponentPubSub(c *hlive.ComponentMountable) *ComponentPubSub

func (*ComponentPubSub) AfterPubSubMount added in v0.2.0

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

func (*ComponentPubSub) PubSubMount

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

func (*ComponentPubSub) SetAfterMountPubSub added in v0.2.0

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

func (*ComponentPubSub) SetMountPubSub added in v0.2.0

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

type DiffApplyAttribute

type DiffApplyAttribute struct {
	*l.Attribute
	// contains filtered or unexported fields
}

func (*DiffApplyAttribute) Initialize

func (a *DiffApplyAttribute) Initialize(page *l.Page)

func (*DiffApplyAttribute) InitializeSSR

func (a *DiffApplyAttribute) InitializeSSR(page *l.Page)

type FocusAttribute

type FocusAttribute struct {
	*l.Attribute
	// contains filtered or unexported fields
}

func (*FocusAttribute) Initialize

func (a *FocusAttribute) Initialize(page *l.Page)

func (*FocusAttribute) InitializeSSR

func (a *FocusAttribute) InitializeSSR(page *l.Page)

type PreemptDisableAttribute

type PreemptDisableAttribute struct {
	*l.Attribute
	// contains filtered or unexported fields
}

func (*PreemptDisableAttribute) Initialize

func (a *PreemptDisableAttribute) Initialize(page *l.Page)

func (*PreemptDisableAttribute) InitializeSSR

func (a *PreemptDisableAttribute) InitializeSSR(page *l.Page)

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 added in v0.2.0

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

func (*PubSub) SubscribeWaitFunc added in v0.2.0

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 added in v0.2.0

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

type PubSubAfterMounter added in v0.2.0

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

type PubSubAttribute

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

func (*PubSubAttribute) Initialize

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

func (*PubSubAttribute) InitializeSSR

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

func (*PubSubAttribute) PipelineProcessorPubSub

func (a *PubSubAttribute) PipelineProcessorPubSub() *hlive.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 RedirectAttribute

type RedirectAttribute struct {
	*l.Attribute
	// contains filtered or unexported fields
}

func (*RedirectAttribute) Initialize

func (a *RedirectAttribute) Initialize(page *l.Page)

func (*RedirectAttribute) InitializeSSR

func (a *RedirectAttribute) InitializeSSR(page *l.Page)

type ScrollTopAttribute

type ScrollTopAttribute struct {
	*l.Attribute
	// contains filtered or unexported fields
}

func (*ScrollTopAttribute) Initialize

func (a *ScrollTopAttribute) Initialize(page *l.Page)

func (*ScrollTopAttribute) InitializeSSR

func (a *ScrollTopAttribute) InitializeSSR(page *l.Page)

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)

Jump to

Keyboard shortcuts

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