Documentation
¶
Overview ¶
Package ds provides helpers for building Datastar (https://data-star.dev/) reactive attributes.
This package includes:
- Signal management: Signal, Signals, Computed, Bind, BindKey
- Event handlers: On, OnClick, OnSubmit, OnInput, OnChange, OnLoad, OnIntersect, OnInterval, OnSignalPatch
- Reactive display: Show, Text, Class, Classes, Style, Styles, Attribute, Attrs
- DOM control: Ref, Indicator, IndicatorKey, Ignore, IgnoreSelf, IgnoreMorph, PreserveAttr, Effect, Init
- HTTP actions: Get, Post, Put, Patch, Delete (and Dynamic variants)
- HTTP options: RequestOptions, ContentType, FilterSignals, Headers, OpenWhenHidden, retry config
- Core actions: Peek, SetAll, ToggleAll
- Modifiers: Debounce, Throttle, Delay, Duration, Once, PreventDefault, ViewTransition, etc.
Pro attributes (require commercial license) are available in this package but documented as requiring a Datastar Pro license: Animate, CustomValidity, OnRAF (requestAnimationFrame), OnResize (element resize observation), Persist, QueryString, ReplaceURL, ScrollIntoView, ViewTransitionName.
Pro actions (require commercial license): Clipboard, ClipboardBase64, Fit, FitClamped, FitRounded, FitClampedRounded.
Pro Datastar attributes require a commercial license from https://data-star.dev/ These attributes provide additional functionality beyond the free tier.
Index ¶
- Variables
- func ActionClipboard(text js.Expr) js.Callable
- func ActionClipboardBase64(text js.Expr) js.Callable
- func ActionDelete(path js.Expr) js.Callable
- func ActionFit(v, oldMin, oldMax, newMin, newMax js.Expr) js.Callable
- func ActionFitClamped(v, oldMin, oldMax, newMin, newMax js.Expr) js.Callable
- func ActionFitClampedRounded(v, oldMin, oldMax, newMin, newMax js.Expr) js.Callable
- func ActionFitRounded(v, oldMin, oldMax, newMin, newMax js.Expr) js.Callable
- func ActionGet(path js.Expr) js.Callable
- func ActionPatch(path js.Expr) js.Callable
- func ActionPeek(expr js.Expr) js.Callable
- func ActionPost(path js.Expr) js.Callable
- func ActionPut(path js.Expr) js.Callable
- func ActionSetAll(value js.Expr, filter *FilterOptions) js.Callable
- func ActionToggleAll(filter *FilterOptions) js.Callable
- func And(actions ...js.Expr) js.Callable
- func Animate(options ...AttrMutator) h.Attribute
- func Attribute(name string, value ...AttrMutator) h.Attribute
- func Attrs(attrs map[string]string) h.Attribute
- func Bind(signalName string) h.Attribute
- func BindKey(signalName string, options ...AttrMutator) h.Attribute
- func Class(clsName string, value ...AttrMutator) h.Attribute
- func Classes(classes map[string]string) h.Attribute
- func Computed(name string, expression Value) h.Attribute
- func ComputedExpr(name string, options ...AttrMutator) h.Attribute
- func CustomValidity(expression ...AttrMutator) h.Attribute
- func DatastarAction(name string, args ...js.Expr) js.Callable
- func Effect(values ...AttrMutator) h.Attribute
- func Hide() h.Attribute
- func Ignore() h.Attribute
- func IgnoreMorph() h.Attribute
- func IgnoreSelf() h.Attribute
- func Indicator(signalName string) h.Attribute
- func IndicatorKey(signalName string, options ...AttrMutator) h.Attribute
- func Init(options ...AttrMutator) h.Attribute
- func JsonSignalsDebug(options *FilterOptions, modifiers ...AttrMutator) h.Attribute
- func Navigate(path string, values ...any) string
- func On(eventName string, options ...AttrMutator) h.Attribute
- func OnChange(options ...AttrMutator) h.Attribute
- func OnClick(options ...AttrMutator) h.Attribute
- func OnInput(options ...AttrMutator) h.Attribute
- func OnIntersect(options ...AttrMutator) h.Attribute
- func OnInterval(options ...AttrMutator) h.Attribute
- func OnLoad(options ...AttrMutator) h.Attribute
- func OnRAF(options ...AttrMutator) h.Attribute
- func OnResize(options ...AttrMutator) h.Attribute
- func OnSignalPatch(options ...AttrMutator) h.Attribute
- func OnSignalPatchFilter(options *FilterOptions) h.Attribute
- func OnSubmit(options ...AttrMutator) h.Attribute
- func Persist(options *FilterOptions, modifiers ...AttrMutator) h.Attribute
- func PersistKey(key string, modifiers ...AttrMutator) h.Attribute
- func PreserveAttr(attrs ...string) h.Attribute
- func QueryString(options *FilterOptions, modifiers ...AttrMutator) h.Attribute
- func Ref(signalName string, options ...AttrMutator) h.Attribute
- func ReplaceURL(expression ...AttrMutator) h.Attribute
- func ScrollIntoView(options ...AttrMutator) h.Attribute
- func Show(value ...AttrMutator) h.Attribute
- func Signal(name string, defaultJsValue any) h.Attribute
- func SignalExpr(name string, defaultExpression Value) h.Attribute
- func Signals(signals map[string]any) h.Attribute
- func Style(property string, expression ...AttrMutator) h.Attribute
- func Styles(styles map[string]string) h.Attribute
- func Text(value ...AttrMutator) h.Attribute
- func ViewTransitionName(expression ...AttrMutator) h.Attribute
- func WithChains(action js.Callable, chains ...PromiseChain) js.Callable
- type AttrFunc
- type AttrMutator
- func AndMutator(actions ...js.Expr) AttrMutator
- func Auto() AttrMutator
- func Capture() AttrMutator
- func Case(casing SignalCasing) AttrMutator
- func ConsoleLog(values ...js.Expr) AttrMutator
- func Debounce(d time.Duration, opts ...TimingMutatorFunc) AttrMutator
- func Delay(d time.Duration) AttrMutator
- func Duration(d time.Duration, opts ...DurationMutatorFunc) AttrMutator
- func Exit() AttrMutator
- func Filter() AttrMutator
- func FilterOptionsValue(o *FilterOptions) AttrMutator
- func Focus() AttrMutator
- func Full() AttrMutator
- func HCenter() AttrMutator
- func HEnd() AttrMutator
- func HNearest() AttrMutator
- func HStart() AttrMutator
- func Half() AttrMutator
- func History() AttrMutator
- func IfMissing() AttrMutator
- func Instant() AttrMutator
- func Once() AttrMutator
- func Outside() AttrMutator
- func Passive() AttrMutator
- func PreventDefault() AttrMutator
- func Self() AttrMutator
- func Session() AttrMutator
- func SetSignal(signalName string, jsValue any) AttrMutator
- func SetSignalExpr(signalName string, expression js.Expr) AttrMutator
- func Smooth() AttrMutator
- func StopPropagation() AttrMutator
- func Terse() AttrMutator
- func Threshold(value float64) AttrMutator
- func Throttle(d time.Duration, opts ...TimingMutatorFunc) AttrMutator
- func VCenter() AttrMutator
- func VEnd() AttrMutator
- func VNearest() AttrMutator
- func VStart() AttrMutator
- func ViewTransition() AttrMutator
- func Window() AttrMutator
- type Callable
- type DurationMutatorFunc
- type Expr
- type ExprMutator
- type FilterOptions
- type KV
- type PromiseChain
- type RequestOption
- type RequestOptionsBuilder
- func (b RequestOptionsBuilder) ContentType(ct string) RequestOptionsBuilder
- func (b RequestOptionsBuilder) FilterSignals(filter *FilterOptions) RequestOptionsBuilder
- func (b RequestOptionsBuilder) Headers(headers map[string]string) RequestOptionsBuilder
- func (b RequestOptionsBuilder) OpenWhenHidden(open bool) RequestOptionsBuilder
- func (b RequestOptionsBuilder) Payload(data any) RequestOptionsBuilder
- func (b RequestOptionsBuilder) RequestCancellation(mode string) RequestOptionsBuilder
- func (b RequestOptionsBuilder) Retry(mode string) RequestOptionsBuilder
- func (b RequestOptionsBuilder) RetryInterval(ms int) RequestOptionsBuilder
- func (b RequestOptionsBuilder) RetryMaxCount(count int) RequestOptionsBuilder
- func (b RequestOptionsBuilder) RetryMaxWaitMs(ms int) RequestOptionsBuilder
- func (b RequestOptionsBuilder) RetryScaler(scaler float64) RequestOptionsBuilder
- func (b RequestOptionsBuilder) Selector(sel string) RequestOptionsBuilder
- type SignalCasing
- type Stmt
- type Stringer
- type TimingMutatorFunc
- type Value
- func Clipboard(text Value) Value
- func ClipboardBase64(text Value) Value
- func Delete(path string, chains ...PromiseChain) Value
- func DeleteDynamic(path Value, chains ...PromiseChain) Value
- func DeleteWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
- func Fit(v, oldMin, oldMax, newMin, newMax Value) Value
- func FitClamped(v, oldMin, oldMax, newMin, newMax Value) Value
- func FitClampedRounded(v, oldMin, oldMax, newMin, newMax Value) Value
- func FitRounded(v, oldMin, oldMax, newMin, newMax Value) Value
- func Get(path string, chains ...PromiseChain) Value
- func GetDynamic(path Value, chains ...PromiseChain) Value
- func GetWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
- func JsonValue(value any) Value
- func Patch(path string, chains ...PromiseChain) Value
- func PatchDynamic(path Value, chains ...PromiseChain) Value
- func PatchWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
- func Peek(action Value) Value
- func Post(path string, chains ...PromiseChain) Value
- func PostDynamic(path Value, chains ...PromiseChain) Value
- func PostWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
- func Put(path string, chains ...PromiseChain) Value
- func PutDynamic(path Value, chains ...PromiseChain) Value
- func PutWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
- func Raw(s string) Value
- func SetAll(value Value, options *FilterOptions) Value
- func SignalRef(name string) Value
- func ToggleAll(options *FilterOptions) Value
- func V(expr js.Expr) Value
Constants ¶
This section is empty.
Variables ¶
var ( // Str creates a JavaScript string literal, properly escaped. Str = js.String // Int creates a JavaScript number literal from an integer. Int = js.Int // Int64 creates a JavaScript number literal from an int64. Int64 = js.Int64 // Float creates a JavaScript number literal from a float64. Float = js.Float // Bool creates a JavaScript boolean literal. Bool = js.Bool // Null creates a JavaScript null literal. Null = js.Null // Undefined creates a JavaScript undefined literal. Undefined = js.Undefined // JSON creates a JavaScript value from a Go value using JSON encoding. JSON = js.JSON // Array creates a JavaScript array literal from expressions. Array = js.Array // Object creates a JavaScript object literal from key-value pairs. Object = js.Object // Pair creates a key-value pair for Object(). Pair = js.Pair // Ident creates a JavaScript identifier reference. Ident = js.Ident // This creates the special "this" identifier. This = js.This // ToJS converts an expression to its JavaScript string representation. ToJS = js.ToJS // ToJSStmt converts a statement to its JavaScript string representation. ToJSStmt = js.ToJSStmt )
Re-export js value constructors
var ( Add = js.Add Sub = js.Sub Mul = js.Mul Div = js.Div Mod = js.Mod Eq = js.Eq NotEq = js.NotEq Lt = js.Lt LtEq = js.LtEq Gt = js.Gt GtEq = js.GtEq JSAnd = js.And JSOr = js.Or JSNot = js.Not Ternary = js.Ternary NullishCoalesce = js.NullishCoalesce Group = js.Group )
Re-export js operators
var ( Prop = js.Prop Method = js.Method Index = js.Index Call = js.Call New = js.New OptionalProp = js.OptionalProp OptionalCall = js.OptionalCall )
Re-export js property/method access
var ( ExprStmt = js.ExprStmt Let = js.Let Const = js.Const Assign = js.Assign AddAssign = js.AddAssign SubAssign = js.SubAssign Incr = js.Incr Decr = js.Decr PreIncr = js.PreIncr PreDecr = js.PreDecr PostIncr = js.PostIncr PostDecr = js.PostDecr Return = js.Return ReturnVoid = js.ReturnVoid )
Re-export js statements
var ( Console = js.Console Document = js.Document JSWindow = js.Window Event = js.Event JSConsoleLog = js.ConsoleLog ConsoleError = js.ConsoleError EventTarget = js.EventTarget EventValue = js.EventValue )
Re-export js builtins
Functions ¶
func ActionClipboard ¶ added in v0.2.0
ActionClipboard creates @clipboard(text) Datastar Pro action
func ActionClipboardBase64 ¶ added in v0.2.0
ActionClipboardBase64 creates @clipboard(text, true) Datastar Pro action for Base64-decoded content
func ActionDelete ¶ added in v0.2.0
ActionDelete creates @delete(path) Datastar action
func ActionFit ¶ added in v0.2.0
ActionFit creates @fit(v, oldMin, oldMax, newMin, newMax) Datastar Pro action
func ActionFitClamped ¶ added in v0.2.0
ActionFitClamped creates @fit(v, oldMin, oldMax, newMin, newMax, true) with clamping
func ActionFitClampedRounded ¶ added in v0.2.0
ActionFitClampedRounded creates @fit(v, oldMin, oldMax, newMin, newMax, true, true) with clamping and rounding
func ActionFitRounded ¶ added in v0.2.0
ActionFitRounded creates @fit(v, oldMin, oldMax, newMin, newMax, false, true) with rounding
func ActionPatch ¶ added in v0.2.0
ActionPatch creates @patch(path) Datastar action
func ActionPeek ¶ added in v0.2.0
ActionPeek creates @peek(() => expr) Datastar action for debugging
func ActionPost ¶ added in v0.2.0
ActionPost creates @post(path) Datastar action
func ActionSetAll ¶ added in v0.2.0
func ActionSetAll(value js.Expr, filter *FilterOptions) js.Callable
ActionSetAll creates @setAll(value, filter) Datastar action
func ActionToggleAll ¶ added in v0.2.0
func ActionToggleAll(filter *FilterOptions) js.Callable
ActionToggleAll creates @toggleAll(filter) Datastar action
func And ¶
And creates a JavaScript && expression from multiple expressions. Example: And(Raw("$a"), Raw("$b")) produces: $a && $b
func Animate ¶
func Animate(options ...AttrMutator) h.Attribute
Animate enables reactive animations on element attributes. Requires Datastar Pro license. Produces: data-animate
func Attribute ¶
func Attribute(name string, value ...AttrMutator) h.Attribute
Attribute sets a single HTML attribute value reactively. Example: Attribute("title", Raw("$foo")) Produces: data-attr:title="$foo"
func Attrs ¶
Attrs sets multiple HTML attributes reactively using object syntax. Example: Attrs(map[string]string{"title": "$foo", "disabled": "$bar"}) Produces: data-attr="{\"title\":\"$foo\",\"disabled\":\"$bar\"}"
func Bind ¶
Bind sets a signal to be used as the value of the element. Updates to the element will be reflected in the signal. The signal name will automatically be prefixed with "$".
func BindKey ¶
func BindKey(signalName string, options ...AttrMutator) h.Attribute
BindKey creates a two-way data binding using key syntax (signal name in key). Example: BindKey("foo", Case(CamelCase)) Produces: data-bind:foo__case.camel
func Class ¶
func Class(clsName string, value ...AttrMutator) h.Attribute
Class sets a class to be used as the value of the element. Updates to the class will be reflected in the element.
func Classes ¶
Classes sets multiple CSS classes conditionally using object syntax. Example: Classes(map[string]string{"hidden": "$foo", "font-bold": "$bar"}) Produces: data-class="{\"hidden\":\"$foo\",\"font-bold\":\"$bar\"}"
func Computed ¶
Computed creates a read-only signal computed from an expression. The signal auto-updates when dependencies change. Example: Computed("total", Raw("$price * $quantity")) Produces: data-computed:total="$price * $quantity"
func ComputedExpr ¶
func ComputedExpr(name string, options ...AttrMutator) h.Attribute
ComputedExpr creates a computed signal with modifiers. Example: ComputedExpr("total", Case(CamelCase), Raw("$price * $quantity"))
func CustomValidity ¶
func CustomValidity(expression ...AttrMutator) h.Attribute
CustomValidity adds custom validation messages to form inputs. Empty strings indicate valid; non-empty strings are shown as validation errors. Requires Datastar Pro license. Example: CustomValidity(Raw("$password === $confirmPassword ? ” : 'Passwords must match'")) Produces: data-custom-validity="$password === $confirmPassword ? ” : 'Passwords must match'"
func DatastarAction ¶
DatastarAction creates a Datastar action call: @action(args...) Example: DatastarAction("get", js.String("/api")) produces @get("/api")
func Effect ¶
func Effect(values ...AttrMutator) h.Attribute
Effect runs an expression reactively whenever dependencies change.
func Hide ¶
Hide returns a style attribute that hides the element. For reactive hiding, use Show() with a negated condition instead.
func IgnoreMorph ¶
IgnoreMorph prevents the element from being morphed during backend patches. Produces: data-ignore-morph
func IgnoreSelf ¶
IgnoreSelf ignores only the element itself, not its descendants. Produces: data-ignore__self
func IndicatorKey ¶
func IndicatorKey(signalName string, options ...AttrMutator) h.Attribute
IndicatorKey creates a fetch indicator signal using key syntax. Example: IndicatorKey("fetching", Case(CamelCase)) Produces: data-indicator:fetching__case.camel
func Init ¶
func Init(options ...AttrMutator) h.Attribute
Init runs an expression when the element loads into the DOM. Example: Init(Raw("$count = 1")) Produces: data-init="$count = 1"
func JsonSignalsDebug ¶
func JsonSignalsDebug(options *FilterOptions, modifiers ...AttrMutator) h.Attribute
JsonSignalsDebug displays reactive JSON stringified signals for debugging. Use with FilterOptions to include/exclude specific signals. Example: JsonSignalsDebug(nil) or JsonSignalsDebug(&FilterOptions{IncludeReg: ptr("user")}) Produces: data-json-signals or data-json-signals="{include: /user/}"
func Navigate ¶
Navigate generates JavaScript to navigate to a URL. Example: Navigate("/users/%d", 42) produces: window.location.href = "/users/42"
func On ¶
func On(eventName string, options ...AttrMutator) h.Attribute
Sets an action to be executed when the event is triggered. The action will be encoded as a JavaScript expression.
func OnChange ¶
func OnChange(options ...AttrMutator) h.Attribute
Sets an action to be executed when the change is detected. The action will be encoded as a JavaScript expression.
func OnClick ¶
func OnClick(options ...AttrMutator) h.Attribute
Sets an action to be executed when the element is clicked. The action will be encoded as a JavaScript expression.
func OnInput ¶
func OnInput(options ...AttrMutator) h.Attribute
Sets an action to be executed when the input is changed. The action will be encoded as a JavaScript expression.
func OnIntersect ¶
func OnIntersect(options ...AttrMutator) h.Attribute
OnIntersect runs an expression when the element intersects the viewport. Use Half() for 50% visibility, Full() for 100% visibility. Example: OnIntersect(Once(), Raw("$seen = true")) Produces: data-on-intersect__once="$seen = true"
func OnInterval ¶
func OnInterval(options ...AttrMutator) h.Attribute
OnInterval executes an expression at regular intervals. Default interval is 1 second. Use Duration() to customize. Example: OnInterval(Duration(500*time.Millisecond), Raw("$count++")) Produces: data-on-interval__duration.500ms="$count++"
func OnLoad ¶
func OnLoad(options ...AttrMutator) h.Attribute
Sets an action to be executed when the element is loaded. The action will be encoded as a JavaScript expression.
func OnRAF ¶
func OnRAF(options ...AttrMutator) h.Attribute
OnRAF executes an expression on every requestAnimationFrame event. Requires Datastar Pro license. Example: OnRAF(Throttle(100*time.Millisecond), Raw("$frameCount++")) Produces: data-on-raf__throttle.100ms="$frameCount++"
func OnResize ¶
func OnResize(options ...AttrMutator) h.Attribute
OnResize runs an expression when element dimensions change. Requires Datastar Pro license. Example: OnResize(Debounce(200*time.Millisecond), Raw("$width = el.offsetWidth")) Produces: data-on-resize__debounce.200ms="$width = el.offsetWidth"
func OnSignalPatch ¶
func OnSignalPatch(options ...AttrMutator) h.Attribute
OnSignalPatch runs an expression whenever signals are updated. A "patch" variable is available containing signal patch details. Example: OnSignalPatch(Raw("console.log('Signal changed!')")) Produces: data-on-signal-patch="console.log('Signal changed!')"
func OnSignalPatchFilter ¶
func OnSignalPatchFilter(options *FilterOptions) h.Attribute
OnSignalPatchFilter filters which signals trigger OnSignalPatch handlers. Example: OnSignalPatchFilter(&FilterOptions{IncludeReg: ptr("^counter$")}) Produces: data-on-signal-patch-filter="{include: /^counter$/}"
func OnSubmit ¶
func OnSubmit(options ...AttrMutator) h.Attribute
Sets an action to be executed when the form is submitted. The action will be encoded as a JavaScript expression.
func Persist ¶
func Persist(options *FilterOptions, modifiers ...AttrMutator) h.Attribute
Persist persists signals in local or session storage. Use Session() modifier for session storage instead of local storage. Requires Datastar Pro license. Example: Persist(nil) or Persist(&FilterOptions{IncludeReg: ptr("user")}) Produces: data-persist or data-persist="{include: /user/}"
func PersistKey ¶
func PersistKey(key string, modifiers ...AttrMutator) h.Attribute
PersistKey persists signals using a custom storage key. Requires Datastar Pro license. Example: PersistKey("mykey", Session()) Produces: data-persist:mykey__session
func PreserveAttr ¶
PreserveAttr preserves specified attribute values during DOM morphing. Example: PreserveAttr("open", "class") Produces: data-preserve-attr="open class"
func QueryString ¶
func QueryString(options *FilterOptions, modifiers ...AttrMutator) h.Attribute
QueryString syncs query parameters to/from signal values. Use Filter() to filter empty values, History() for browser history integration. Requires Datastar Pro license. Example: QueryString(nil) or QueryString(&FilterOptions{IncludeReg: ptr("search")}) Produces: data-query-string or data-query-string="{include: /search/}"
func Ref ¶
func Ref(signalName string, options ...AttrMutator) h.Attribute
Ref creates a signal referencing a DOM element. Example: Ref("myElement") Produces: data-ref:myElement
func ReplaceURL ¶
func ReplaceURL(expression ...AttrMutator) h.Attribute
ReplaceURL replaces the browser URL without page reload. Accepts relative or absolute URLs as evaluated expressions. Requires Datastar Pro license. Example: ReplaceURL(Raw("`/page${$page}`")) Produces: data-replace-url="`/page${$page}`"
func ScrollIntoView ¶
func ScrollIntoView(options ...AttrMutator) h.Attribute
ScrollIntoView scrolls the element into viewport view. Use scroll behavior and alignment modifiers. Requires Datastar Pro license. Example: ScrollIntoView(Smooth(), VCenter()) Produces: data-scroll-into-view__smooth__vcenter
func Show ¶
func Show(value ...AttrMutator) h.Attribute
Show conditionally shows/hides the element based on a signal.
func Signal ¶
Signal defines a signal with a default value. The signal's default value will be encoded as a JSON value. The signal name will automatically be prefixed with "$".
func SignalExpr ¶
SignalExpr sets a signal to an arbitrary JavaScript expression. The signal's default value will be appended to the attribute name. The signal name will automatically be prefixed with "$".
func Signals ¶
Signals defines multiple signals with default values using object syntax. The signals will be encoded as a JSON object. Example: Signals(map[string]any{"foo": 1, "bar": "hello"}) Produces: data-signals="{\"foo\":1,\"bar\":\"hello\"}"
func Style ¶
func Style(property string, expression ...AttrMutator) h.Attribute
Style sets an inline CSS style property reactively. Example: Style("background-color", Raw("$isRed ? 'red' : 'blue'")) Produces: data-style:background-color="$isRed ? 'red' : 'blue'"
func Styles ¶
Styles sets multiple inline CSS styles reactively using object syntax. Example: Styles(map[string]string{"display": "$hidden ? 'none' : 'block'", "color": "$red ? 'red' : 'green'"})
func Text ¶
func Text(value ...AttrMutator) h.Attribute
Text sets the text of the element to be the value of the signal. Updates to the signal will be reflected in the element.
func ViewTransitionName ¶
func ViewTransitionName(expression ...AttrMutator) h.Attribute
ViewTransitionName sets explicit view-transition-name for CSS animations. Requires Datastar Pro license. Example: ViewTransitionName(Raw("$itemId")) Produces: data-view-transition="$itemId"
func WithChains ¶
func WithChains(action js.Callable, chains ...PromiseChain) js.Callable
WithChains adds promise chains to a Datastar action, returning a new Callable
Types ¶
type AttrFunc ¶
type AttrFunc func(*attrBuilder)
AttrFunc is a function that implements AttrMutator.
type AttrMutator ¶
type AttrMutator interface{ Modify(*attrBuilder) }
AttrMutator modifies an attribute being built (name and/or statements).
func AndMutator ¶
func AndMutator(actions ...js.Expr) AttrMutator
AndMutator creates an AttrMutator that combines expressions with &&. Example: AndMutator(Raw("$a"), Raw("$b")) produces an AttrMutator.
func Capture ¶
func Capture() AttrMutator
Specifies that the event should not be captured. Only works for built-in events.
func Case ¶
func Case(casing SignalCasing) AttrMutator
Specifies the casing of the signal/event name
func ConsoleLog ¶
func ConsoleLog(values ...js.Expr) AttrMutator
ConsoleLog creates an AttrMutator that logs values to the console. Example: ConsoleLog(Signal("value"), Str("clicked"))
func Debounce ¶
func Debounce(d time.Duration, opts ...TimingMutatorFunc) AttrMutator
Debounces the events triggered
func Duration ¶
func Duration(d time.Duration, opts ...DurationMutatorFunc) AttrMutator
Duration sets the interval timing for data-on-interval. Default is 1 second if not specified. Example: Duration(500*time.Millisecond) produces __duration.500ms Example: Duration(2*time.Second, DurationLeading()) produces __duration.2s.leading
func Exit ¶
func Exit() AttrMutator
Exit triggers when element exits viewport instead of entering. Used with data-on-intersect to detect when an element leaves view.
func FilterOptionsValue ¶
func FilterOptionsValue(o *FilterOptions) AttrMutator
FilterOptionsValue returns an AttrMutator that outputs FilterOptions as a JS object with regex literals.
func HNearest ¶
func HNearest() AttrMutator
HNearest aligns element to nearest edge of horizontal viewport.
func History ¶
func History() AttrMutator
History enables browser history integration for QueryString.
func IfMissing ¶
func IfMissing() AttrMutator
IfMissing only patches signals if the keys don't already exist. Used with Signal/Signals attributes.
func Once ¶
func Once() AttrMutator
Prevents the event from being triggered multiple times. Only works for built-in events.
func Outside ¶
func Outside() AttrMutator
Triggers when the event is triggered outside of the element
func Passive ¶
func Passive() AttrMutator
Specifies that the event should not be canceled. Only works for built-in events.
func Self ¶
func Self() AttrMutator
Self modifier for data-ignore - ignores only the element, not descendants.
func Session ¶
func Session() AttrMutator
Session uses session storage instead of local storage for Persist.
func SetSignal ¶
func SetSignal(signalName string, jsValue any) AttrMutator
SetSignal creates an AttrMutator that sets a signal to a value. Use SetSignalExpr if you need to set the signal to a more complex expression. The signalName will automatically be prefixed with "$".
func SetSignalExpr ¶
func SetSignalExpr(signalName string, expression js.Expr) AttrMutator
SetSignalExpr creates an AttrMutator that sets a signal to an expression. The signalName will automatically be prefixed with "$".
func Terse ¶
func Terse() AttrMutator
Terse outputs compact JSON without whitespace for data-json-signals debug.
func Threshold ¶
func Threshold(value float64) AttrMutator
Threshold sets a custom visibility threshold (0.0-1.0) for intersection. Use instead of Half() or Full() for precise control. Example: Threshold(0.25) triggers at 25% visibility.
func Throttle ¶
func Throttle(d time.Duration, opts ...TimingMutatorFunc) AttrMutator
Throttles the events triggered
func VNearest ¶
func VNearest() AttrMutator
VNearest aligns element to nearest edge of vertical viewport.
func ViewTransition ¶
func ViewTransition() AttrMutator
Wraps expression in document.startViewTransition() when View Transition API is supported
type DurationMutatorFunc ¶
func DurationLeading ¶
func DurationLeading() DurationMutatorFunc
DurationLeading causes the first interval to fire immediately.
type ExprMutator ¶
ExprMutator wraps a js.Expr to satisfy AttrMutator
func E ¶
func E(expr js.Expr) ExprMutator
E wraps a js.Expr to use as an AttrMutator Example: OnClick(PreventDefault(), E(Signal("count")))
func (ExprMutator) Modify ¶
func (e ExprMutator) Modify(attr *attrBuilder)
type FilterOptions ¶
FilterOptions specifies regex patterns for filtering signals.
type PromiseChain ¶
type PromiseChain interface {
// contains filtered or unexported methods
}
PromiseChain represents a chainable action for HTTP requests (then/catch)
func CatchChain ¶
func CatchChain(expr js.Expr) PromiseChain
CatchChain creates a .catch() chain for error handling
func OnFailure ¶
func OnFailure(expr Value) PromiseChain
OnFailure creates a .catch() chain for error handling. This is an alias for CatchChain for backward compatibility.
func OnSuccess ¶
func OnSuccess(expr Value) PromiseChain
OnSuccess creates a .then() chain for successful request handling. This is an alias for ThenChain for backward compatibility.
func ThenChain ¶
func ThenChain(expr js.Expr) PromiseChain
ThenChain creates a .then() chain for successful request handling
type RequestOption ¶
type RequestOption interface {
// contains filtered or unexported methods
}
RequestOption is an option for HTTP request actions.
type RequestOptionsBuilder ¶
type RequestOptionsBuilder struct {
// contains filtered or unexported fields
}
RequestOptionsBuilder collects request options.
func RequestOptions ¶
func RequestOptions() RequestOptionsBuilder
RequestOptions creates a builder for HTTP request options. Use with GetWithOptions, PostWithOptions, etc. Example: GetWithOptions("/api", RequestOptions().ContentType("form").OpenWhenHidden(true))
func (RequestOptionsBuilder) ContentType ¶
func (b RequestOptionsBuilder) ContentType(ct string) RequestOptionsBuilder
ContentType sets the request content type. Values: "json" (default) or "form"
func (RequestOptionsBuilder) FilterSignals ¶
func (b RequestOptionsBuilder) FilterSignals(filter *FilterOptions) RequestOptionsBuilder
FilterSignals filters which signals are sent with the request.
func (RequestOptionsBuilder) Headers ¶
func (b RequestOptionsBuilder) Headers(headers map[string]string) RequestOptionsBuilder
Headers sets custom HTTP headers for the request.
func (RequestOptionsBuilder) OpenWhenHidden ¶
func (b RequestOptionsBuilder) OpenWhenHidden(open bool) RequestOptionsBuilder
OpenWhenHidden keeps the connection alive when the tab is hidden.
func (RequestOptionsBuilder) Payload ¶
func (b RequestOptionsBuilder) Payload(data any) RequestOptionsBuilder
Payload overrides the request body with custom JSON data. Use for POST/PUT/PATCH requests when you need a custom payload.
func (RequestOptionsBuilder) RequestCancellation ¶
func (b RequestOptionsBuilder) RequestCancellation(mode string) RequestOptionsBuilder
RequestCancellation sets the request cancellation mode. Values: "auto" (default), "disabled"
func (RequestOptionsBuilder) Retry ¶
func (b RequestOptionsBuilder) Retry(mode string) RequestOptionsBuilder
Retry sets the retry strategy for the request. Values: "auto" (default, retry on network errors), "error" (retry on errors and non-2xx), "always" (always retry), "never" (never retry)
func (RequestOptionsBuilder) RetryInterval ¶
func (b RequestOptionsBuilder) RetryInterval(ms int) RequestOptionsBuilder
RetryInterval sets the retry interval in milliseconds (default: 1000).
func (RequestOptionsBuilder) RetryMaxCount ¶
func (b RequestOptionsBuilder) RetryMaxCount(count int) RequestOptionsBuilder
RetryMaxCount sets the maximum number of retry attempts (default: 10).
func (RequestOptionsBuilder) RetryMaxWaitMs ¶
func (b RequestOptionsBuilder) RetryMaxWaitMs(ms int) RequestOptionsBuilder
RetryMaxWaitMs sets the maximum wait between retries in milliseconds (default: 30000).
func (RequestOptionsBuilder) RetryScaler ¶
func (b RequestOptionsBuilder) RetryScaler(scaler float64) RequestOptionsBuilder
RetryScaler sets the exponential backoff multiplier (default: 2).
func (RequestOptionsBuilder) Selector ¶
func (b RequestOptionsBuilder) Selector(sel string) RequestOptionsBuilder
Selector specifies a CSS selector for form elements (when contentType is 'form').
type SignalCasing ¶
type SignalCasing string
const ( CamelCase SignalCasing = "camel" // myEvent KebabCase SignalCasing = "kebab" // my-event SnakeCase SignalCasing = "snake" // my_event PascalCase SignalCasing = "pascal" // MyEvent )
type TimingMutatorFunc ¶
func Leading ¶
func Leading() TimingMutatorFunc
Leading causes the first trigger to fire immediately (for throttle)
func NoLeading ¶
func NoLeading() TimingMutatorFunc
NoLeading prevents the first trigger from firing immediately (for debounce)
func NoTrailing ¶
func NoTrailing() TimingMutatorFunc
NoTrailing prevents the final trigger from firing after the delay (for debounce)
func Trailing ¶
func Trailing() TimingMutatorFunc
Trailing causes the final trigger to fire after the delay (for throttle)
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value wraps a js.Expr and implements AttrMutator. This allows expressions to be used directly with Datastar attribute functions.
func Clipboard ¶
Clipboard copies text to the clipboard. Requires Datastar Pro license. Example: OnClick(Clipboard(Str("Hello, world!"))) Produces: data-on:click="@clipboard('Hello, world!')"
func ClipboardBase64 ¶
ClipboardBase64 copies Base64-decoded text to the clipboard. Useful for content with special characters, quotes, or code fragments. Requires Datastar Pro license. Example: OnClick(ClipboardBase64(Str("SGVsbG8sIHdvcmxkIQ=="))) Produces: data-on:click="@clipboard('SGVsbG8sIHdvcmxkIQ==', true)"
func Delete ¶
func Delete(path string, chains ...PromiseChain) Value
Delete performs a DELETE request. Returns a Value that can be used with event handlers.
func DeleteDynamic ¶
func DeleteDynamic(path Value, chains ...PromiseChain) Value
DeleteDynamic performs a DELETE request with a dynamic path. Returns a Value that can be used with event handlers.
func DeleteWithOptions ¶
func DeleteWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
DeleteWithOptions performs a DELETE request with options.
func Fit ¶
Fit linearly interpolates a value from one range to another. Requires Datastar Pro license. Syntax: @fit(v, oldMin, oldMax, newMin, newMax) Example: Computed("rgb", Fit(Raw("$slider"), Raw("0"), Raw("100"), Raw("0"), Raw("255")))
func FitClamped ¶
FitClamped linearly interpolates with clamping to keep results within the target range. Requires Datastar Pro license. Syntax: @fit(v, oldMin, oldMax, newMin, newMax, true)
func FitClampedRounded ¶
FitClampedRounded linearly interpolates with both clamping and rounding. Requires Datastar Pro license. Syntax: @fit(v, oldMin, oldMax, newMin, newMax, true, true)
func FitRounded ¶
FitRounded linearly interpolates with rounding to nearest integer. Requires Datastar Pro license. Syntax: @fit(v, oldMin, oldMax, newMin, newMax, false, true)
func Get ¶
func Get(path string, chains ...PromiseChain) Value
Get performs a GET request. Returns a Value that can be used with event handlers.
func GetDynamic ¶
func GetDynamic(path Value, chains ...PromiseChain) Value
GetDynamic performs a GET request with a dynamic path. Returns a Value that can be used with event handlers.
func GetWithOptions ¶
func GetWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
GetWithOptions performs a GET request with options.
func JsonValue ¶
JsonValue creates a JavaScript value from a Go value using JSON encoding. Panics if the value cannot be marshaled to JSON.
func Patch ¶
func Patch(path string, chains ...PromiseChain) Value
Patch performs a PATCH request. Returns a Value that can be used with event handlers.
func PatchDynamic ¶
func PatchDynamic(path Value, chains ...PromiseChain) Value
PatchDynamic performs a PATCH request with a dynamic path. Returns a Value that can be used with event handlers.
func PatchWithOptions ¶
func PatchWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
PatchWithOptions performs a PATCH request with options.
func Peek ¶
Peek creates a @peek(() => expr) Datastar action for debugging. Returns a Value that can be used with event handlers.
func Post ¶
func Post(path string, chains ...PromiseChain) Value
Post performs a POST request. Returns a Value that can be used with event handlers.
func PostDynamic ¶
func PostDynamic(path Value, chains ...PromiseChain) Value
PostDynamic performs a POST request with a dynamic path. Returns a Value that can be used with event handlers.
func PostWithOptions ¶
func PostWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
PostWithOptions performs a POST request with options.
func Put ¶
func Put(path string, chains ...PromiseChain) Value
Put performs a PUT request. Returns a Value that can be used with event handlers.
func PutDynamic ¶
func PutDynamic(path Value, chains ...PromiseChain) Value
PutDynamic performs a PUT request with a dynamic path. Returns a Value that can be used with event handlers.
func PutWithOptions ¶
func PutWithOptions(path string, opts RequestOptionsBuilder, chains ...PromiseChain) Value
PutWithOptions performs a PUT request with options.
func Raw ¶
Raw injects raw JavaScript code. This is the escape hatch for arbitrary JavaScript. Use with caution as this bypasses type safety.
func SetAll ¶
func SetAll(value Value, options *FilterOptions) Value
SetAll creates a @setAll(value, filter) Datastar action. Returns a Value that can be used with event handlers.
func SignalRef ¶
SignalRef creates a Datastar signal reference: $name Use this to reference a signal value in expressions. Example: SignalRef("count") produces $count
func ToggleAll ¶
func ToggleAll(options *FilterOptions) Value
ToggleAll creates a @toggleAll(filter) Datastar action. Returns a Value that can be used with event handlers.