Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrValueNotSettable = errors.New("value not settable")
Functions ¶
This section is empty.
Types ¶
type Binder ¶
type Binder[T comparable] interface { RWLocker Setter[T] tag.TagGetter jaws.ClickHandler jaws.ContextMenuHandler jaws.InitialHTMLAttrHandler JawsGetLocked(elem *jaws.Element) (value T) JawsSetLocked(elem *jaws.Element, value T) (err error) // JawsInitialHTMLAttrLocked returns the initial HTML attribute while // the Binder lock is held. JawsInitialHTMLAttrLocked(elem *jaws.Element) (s template.HTMLAttr) // SetLocked returns a Binder[T] that will call fn instead of JawsSetLocked. // // The lock will be held at this point. // Do not lock or unlock the Binder within fn. Do not call JawsSet. // // The bind argument to the function is the previous Binder in the chain, // and you probably want to call it's JawsSetLocked first. SetLocked(fn SetHook[T]) (newbind Binder[T]) // GetLocked returns a Binder[T] that will call fn instead of JawsGetLocked. // // The lock will be held at this point, preferring RLock over Lock, if available. // Do not lock or unlock the Binder within fn. Do not call JawsGet. // // The bind argument to the function is the previous Binder in the chain, // and you probably want to call it's JawsGetLocked first. GetLocked(fn GetHook[T]) (newbind Binder[T]) // Success returns a Binder[T] that will call fn after the value has been set // with no errors. No locks are held when the function is called. // If the function returns an error, that will be returned from JawsSet. // // The function must have one of the following signatures: // * func() // * func() error // * func(*Element) // * func(*Element) error Success(fn any) (newbind Binder[T]) // GetHTML returns a Binder[T] that will call fn instead of the default // escaped fmt.Sprintf("%v", JawsGetLocked(elem)) HTML rendering. // // The lock will be held at this point, preferring RLock over Lock, if available. // Do not lock or unlock the Binder within fn. Do not call JawsGet. GetHTML(fn GetHTMLHook[T]) (newbind Binder[T]) // Clicked returns a Binder[T] that will call fn when JawsClick is invoked. // // The Binder locks are not held when the function is called. Clicked(fn ClickedHook[T]) (newbind Binder[T]) // ContextMenu returns a Binder[T] that will call fn when JawsContextMenu // is invoked. // // The Binder locks are not held when the function is called. ContextMenu(fn ContextMenuHook[T]) (newbind Binder[T]) // InitialHTMLAttr returns a Binder[T] that will call fn when // JawsInitialHTMLAttr is invoked. // // The lock will be held at this point, preferring RLock over Lock, if available. // Do not lock or unlock the Binder within fn. Do not call JawsGet. // To call the previous handler in the chain, call JawsInitialHTMLAttrLocked. InitialHTMLAttr(fn InitialHTMLAttrHook[T]) (newbind Binder[T]) }
type ClickedHook ¶ added in v0.400.0
type ClickedHook[T comparable] func(bind Binder[T], elem *jaws.Element, click jaws.Click) (err error)
ClickedHook is a function to call when a click event is received.
The Binder locks are not held when the function is called.
type ContextMenuHook ¶ added in v0.400.0
type ContextMenuHook[T comparable] func(bind Binder[T], elem *jaws.Element, click jaws.Click) (err error)
ContextMenuHook is a function to call when a context menu event is received.
The Binder locks are not held when the function is called.
type GetHTMLHook ¶ added in v0.400.0
GetHTMLHook is a function to call when JawsGetHTML() is called.
The lock will be held before calling the function, preferring RLock over Lock, if available. Do not lock or unlock the Binder in the function. Do not call JawsGet.
type GetHook ¶ added in v0.400.0
type GetHook[T comparable] func(bind Binder[T], elem *jaws.Element) (value T)
GetHook is a function that replaces JawsGetLocked for a Binder.
The lock will be held before calling the function, preferring RLock over Lock, if available. Do not lock or unlock the Binder in the function. Do not call JawsGet.
The bind argument is the previous Binder in the chain, and you probably want to call it's JawsGetLocked first.
type Getter ¶
type Getter[T comparable] interface { JawsGet(elem *jaws.Element) (value T) }
func MakeGetter ¶
func MakeGetter[T comparable](v any) Getter[T]
type HTMLGetter ¶
A HTMLGetter is the primary way to deliver generated HTML content to dynamic HTML nodes.
func HTMLGetterFunc ¶
HTMLGetterFunc wraps a function and returns a HTMLGetter.
func MakeHTMLGetter ¶
func MakeHTMLGetter(v any) HTMLGetter
MakeHTMLGetter returns a HTMLGetter for v.
Depending on the type of v, we return:
- HTMLGetter: `JawsGetHTML(e *Element) template.HTML` to be used as-is.
- Getter[string]: `JawsGet(elem *Element) string` that will be escaped using `html.EscapeString`.
- fmt.Stringer: `String() string` that will be escaped using `html.EscapeString`.
- a static `template.HTML` or `string` to be used as-is with no HTML escaping.
- everything else is rendered using `fmt.Sprint()` and escaped using `html.EscapeString`.
WARNING: Plain string values are NOT HTML-escaped. This is intentional so that HTML markup can be passed conveniently from Go templates (e.g. `{{$.Span "<i>text</i>"}}`). Never pass untrusted user input as a plain string; use template.HTML to signal that the content is trusted, or wrap user input in a Getter or fmt.Stringer so it will be escaped automatically.
type InitialHTMLAttrHook ¶ added in v0.400.0
type InitialHTMLAttrHook[T comparable] func(bind Binder[T], elem *jaws.Element) (s template.HTMLAttr)
InitialHTMLAttrHook is a function to call when an Element is initially rendered.
The lock will be held at this point, preferring RLock over Lock, if available. Do not lock or unlock the Binder within fn. Do not call JawsGet.
type SetHook ¶ added in v0.400.0
type SetHook[T comparable] func(bind Binder[T], elem *jaws.Element, value T) (err error)
SetHook is a function that replaces JawsSetLocked for a Binder.
The lock will be held before calling the function, preferring RLock over Lock, if available. Do not lock or unlock the Binder in the function. Do not call JawsSet.
The bind argument is the previous Binder in the chain, and you probably want to call it's JawsSetLocked first.
type Setter ¶
type Setter[T comparable] interface { Getter[T] // JawsSet may return ErrValueUnchanged to indicate value was already set. JawsSet(elem *jaws.Element, value T) (err error) }
func MakeSetter ¶
func MakeSetter[T comparable](v any) Setter[T]
func MakeSetterFloat64 ¶
type SetterFloat64 ¶
type SuccessHook ¶ added in v0.400.0
SuccessHook is a function to call when a call to JawsSet returns with no error.
The Binder locks are not held when the function is called.
Success hooks in a Binder chain are called in the order they were registered. If one of them returns an error, that error is returned from JawsSet and no more success hooks are called.