Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
angelofallars authored Jan 18, 2024
1 parent 17f43ee commit 553d960
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Check if requests are from HTMX, and use a type-safe, declarative
syntax for HTMX response headers to control HTMX behavior from the server.

Write [triggers](#triggers) without dealing with JSON formatting.
Define trigger behavior, and htmx-go handles the rest.
Define trigger behavior, and htmx-go handles the rest. By using triggers to trigger client-side events, **event-driven** applications are easier to develop.

Use [Swap Strategy](#swap-strategy) methods to fine-tune `hx-swap` behavior.

Expand All @@ -34,8 +34,9 @@ func handler(w http.ResponseWriter, r *http.Request) {
if htmx.IsHTMX(r) {
htmx.NewResponse().
Reswap(htmx.SwapBeforeEnd).
Retarget("#errors").
ReplaceURL("/errors").
Retarget("#contacts").
AddTrigger(htmx.Trigger("enable-submit")).
AddTrigger(htmx.TriggerDetail("display-message", "Hello world!")
Write(w)
}
}
Expand Down Expand Up @@ -122,7 +123,9 @@ func handler(w http.ResponseWriter, r *http.Request) {

### Triggers

You can add triggers and let htmx-go take care of formatting
[HTMX Reference: `hx-trigger`](https://htmx.org/headers/hx-trigger/)

You can add triggers to trigger client-side [events](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events) and let htmx-go take care of formatting
and JSON serialization of the header values.

Define event triggers:
Expand Down Expand Up @@ -161,6 +164,8 @@ htmx.NewResponse().

### Swap strategy

[HTMX Reference: `hx-swap`](https://htmx.org/attributes/hx-swap/)

`Response.Reswap()` takes in `SwapStrategy` values from this library.

```go
Expand Down Expand Up @@ -206,8 +211,6 @@ htmx.SwapDefault.ShowNone()
// HX-Reswap: show:none
```

[HTMX Reference: `hx-swap`](https://htmx.org/attributes/hx-swap/)

### Code organization

HTMX response writers can be declared outside of functions with `var` so you can reuse them in several
Expand Down

0 comments on commit 553d960

Please sign in to comment.