Skip to content

Support Datastar v1.0.1 data-bind __prop/__event and data-on __document modifiers#42

Open
maragubot wants to merge 2 commits into
maragudk:mainfrom
maragubot:datastar-v1.0.0
Open

Support Datastar v1.0.1 data-bind __prop/__event and data-on __document modifiers#42
maragubot wants to merge 2 commits into
maragudk:mainfrom
maragubot:datastar-v1.0.0

Conversation

@maragubot

@maragubot maragubot commented Apr 18, 2026

Copy link
Copy Markdown

Summary

Adds support for the new attribute modifiers introduced in Datastar v1.0.0 and refined in v1.0.1:

  • data-bind __prop modifier — bind through a specific property (camelCased at runtime in v1.0.1)
  • data-bind __event modifier — define which events sync the element back to the signal
  • data-on __document modifier — attach event listeners to the document element

In v1.0.1 the __prop and __event modifiers may be used independently of each other, so both the single- and combined-modifier forms are valid.

API additions

  • Prop(name string) Modifier — returns the full __prop.name modifier. Panics on empty name.
  • Event(names ...string) Modifier — returns the full __event.a.b.c modifier. Panics when no names or any empty name is given.
  • ModifierDocument constant
  • Bind() now accepts modifiers ...Modifier (source-compatible with existing single-argument calls; all demo/main.go call sites unchanged)

Usage

data.Bind("isChecked", data.Prop("checked"))
data.Bind("query", data.Event("input", "change"))
data.Bind("isChecked", data.Prop("checked"), data.Event("change"))
data.On("keydown", "$foo = ''", data.ModifierDocument)

Other

  • Bump vendored docs/datastar.js to v1.0.1
  • Update AGENTS.md compatibility note to v1.0.1

Runtime-only v1.0.0/v1.0.1 changes (morphing, fetch behavior, kebab fix, select signal-type fix, retryMaxWaitMs rename, Rocket rewrite) are out of scope for this library.

Test plan

  • make test passes (95.6% coverage)
  • Tests cover __prop, __event (single and multiple events), combined __prop+__event, and __document
  • Panic tests for Prop(""), Event(), and Event("x", "")
  • Example functions added for godoc
  • Vendored bundle verified to no longer contain the v1.0.0 BindPropRequiredWhenEventProvided / BindEventRequired pairing constraint

…vent` helpers for Datastar v1.0.0

- `data-bind` gains `__prop` and `__event` modifier support via a new
  variadic `modifiers` parameter on `Bind()`.
- `data-on` gains `__document` modifier support.
- Bump vendored `datastar.js` to v1.0.0 and update compatibility note.
- `Prop(name)` now returns the full `__prop.name` modifier; `Event(names...)`
  returns the full `__event.a.b.c` modifier. Drop the now-redundant
  `ModifierProp` and `ModifierEvent` constants — one helper call replaces
  the paired-modifier form and removes a footgun where callers could emit
  invalid attributes.
- Both helpers now panic on empty input, matching `Duration` and `Threshold`.
- Fix `Bind` godoc to show the value form the library actually emits, and
  note that `__prop` and `__event` may be used independently (v1.0.1).
- Bump vendored `datastar.js` and compat note to v1.0.1.
@maragubot maragubot changed the title Support Datastar v1.0.0 attribute modifiers (__prop, __event, __document) Support Datastar v1.0.1 data-bind __prop/__event and data-on __document modifiers Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant