mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-11-23 20:02:50 +01:00
Update docs to specify response parts ordering (fixes #11)
This commit is contained in:
parent
1edbce34be
commit
e8a0b94d03
2 changed files with 17 additions and 4 deletions
12
README.md
12
README.md
|
@ -130,10 +130,12 @@ trigger](https://htmx.org/attributes/hx-trigger/) header.
|
|||
use axum_htmx::HxResponseTrigger;
|
||||
|
||||
// When we load our page, we will trigger any event listeners for "my-event.
|
||||
async fn index() -> (&'static str, HxResponseTrigger) {
|
||||
async fn index() -> (HxResponseTrigger, &'static str) {
|
||||
// Note: As HxResponseTrigger only implements `IntoResponseParts`, we must
|
||||
// return our trigger first here.
|
||||
(
|
||||
"Hello, world!",
|
||||
HxResponseTrigger::normal(["my-event", "second-event"]),
|
||||
"Hello, world!",
|
||||
)
|
||||
}
|
||||
```
|
||||
|
@ -148,7 +150,7 @@ use serde_json::json;
|
|||
// instead of the root module.
|
||||
use axum_htmx::{HxEvent, HxResponseTrigger};
|
||||
|
||||
async fn index() -> (&'static str, HxResponseTrigger) {
|
||||
async fn index() -> (HxResponseTrigger, &'static str) {
|
||||
let event = HxEvent::new_with_data(
|
||||
"my-event",
|
||||
// May be any object that implements `serde::Serialize`
|
||||
|
@ -159,7 +161,9 @@ async fn index() -> (&'static str, HxResponseTrigger) {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
("Hello, world!", HxResponseTrigger::normal([event]))
|
||||
// Note: As HxResponseTrigger only implements `IntoResponseParts`, we must
|
||||
// return our trigger first here.
|
||||
(HxResponseTrigger::normal([event]), "Hello, world!")
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -111,6 +111,9 @@ pub enum TriggerMode {
|
|||
/// visible ASCII (32-127) when serializing to JSON.
|
||||
///
|
||||
/// See <https://htmx.org/headers/hx-trigger/> for more information.
|
||||
///
|
||||
/// Note: An `HxResponseTrigger` implements `IntoResponseParts` and should be
|
||||
/// used before any other response object would consume the response parts.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct HxResponseTrigger {
|
||||
pub mode: TriggerMode,
|
||||
|
@ -129,18 +132,24 @@ impl HxResponseTrigger {
|
|||
|
||||
/// Creates new [normal](https://htmx.org/headers/hx-trigger/) trigger from
|
||||
/// events.
|
||||
///
|
||||
/// See `HxResponseTrigger` for more information.
|
||||
pub fn normal<T: Into<HxEvent>>(events: impl IntoIterator<Item = T>) -> Self {
|
||||
Self::new(TriggerMode::Normal, events)
|
||||
}
|
||||
|
||||
/// Creates new [after settle](https://htmx.org/headers/hx-trigger/) trigger
|
||||
/// from events.
|
||||
///
|
||||
/// See `HxResponseTrigger` for more information.
|
||||
pub fn after_settle<T: Into<HxEvent>>(events: impl IntoIterator<Item = T>) -> Self {
|
||||
Self::new(TriggerMode::AfterSettle, events)
|
||||
}
|
||||
|
||||
/// Creates new [after swap](https://htmx.org/headers/hx-trigger/) trigger
|
||||
/// from events.
|
||||
///
|
||||
/// See `HxResponseTrigger` for more information.
|
||||
pub fn after_swap<T: Into<HxEvent>>(events: impl IntoIterator<Item = T>) -> Self {
|
||||
Self::new(TriggerMode::AfterSwap, events)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue