Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrValueNotSettable = errors.New("value not settable")
Functions ¶
This section is empty.
Types ¶
type BindClickedHook ¶
type BindClickedHook[T comparable] func(bind Binder[T], elem *jaws.Element, name string) (err error)
BindClickedHook is a function to call when a click event is received.
The Binder locks are not held when the function is called.
type BindGetHook ¶
type BindGetHook[T comparable] func(bind Binder[T], elem *jaws.Element) (value T)
BindGetHook 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 BindSetHook ¶
type BindSetHook[T comparable] func(bind Binder[T], elem *jaws.Element, value T) (err error)
BindSetHook 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 BindSuccessHook ¶
BindSuccessHook 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.
type Binder ¶
type Binder[T comparable] interface { RWLocker Setter[T] jtag.TagGetter Formatter jaws.ClickHandler JawsBinderPrev() Binder[T] // returns the previous Binder in the chain, or nil JawsGetLocked(elem *jaws.Element) (value T) JawsSetLocked(elem *jaws.Element, value T) (err error) // 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 BindSetHook[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 BindGetHook[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]) // FormatHTML returns a HTMLGetter using fmt.Sprintf(f, JawsGet[T](elem)) FormatHTML(f string) (getter HTMLGetter) // 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 BindClickedHook[T]) (newbind Binder[T]) }
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`.
- Formatter: `Format("%v") 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 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]