pub struct PropsUpdate { /* private fields */ }Expand description
New props for mounted islands, sent in an HX-Trigger header.
htmx sends the PROPS_EVENT event. The loader sets data-react-props
on the first element that matches each selector. React renders the same
root again, so the component keeps its state.
use autumn_plugin_react::PropsUpdate;
use autumn_web::prelude::*;
#[post("/cart")]
async fn add_to_cart() -> AutumnResult<(PropsUpdate, Markup)> {
let update = PropsUpdate::new().set("#cart", &serde_json::json!({ "count": 3 }))?;
Ok((update, html! { p { "Added." } }))
}- htmx handles
HX-Triggerbefore the swap. To update an island that the same response swaps in, useafter_settle. - The update merges with a trigger header that the response already
has. A header that later code sets with
insertreplaces it. Then callapply_tolast. - Props travel in a response header. Keep them small: proxies limit header size (nginx: 4 KB to 8 KB by default).
- Build selectors from trusted values. A selector from user input can select a different island.
An empty update sends no header.
Implementations§
Source§impl PropsUpdate
impl PropsUpdate
Sourcepub fn set<T: Serialize + ?Sized>(
self,
selector: impl Into<String>,
props: &T,
) -> Result<Self, PropsError>
pub fn set<T: Serialize + ?Sized>( self, selector: impl Into<String>, props: &T, ) -> Result<Self, PropsError>
Sourcepub const fn after_settle(self) -> Self
pub const fn after_settle(self) -> Self
Sends the update in HX-Trigger-After-Settle. htmx then sends the
event after the swap, so the update can reach a new island.
Sourcepub const fn header_name(&self) -> &'static str
pub const fn header_name(&self) -> &'static str
The header that carries the update: hx-trigger, or
hx-trigger-after-settle.
Sourcepub fn to_header_value(&self) -> String
pub fn to_header_value(&self) -> String
The header value:
{"autumn:react:props":[{"target":"#cart","props":{…}}]}.
The text is visible ASCII. Other characters become \uXXXX
escapes, because a header value cannot hold them.
Trait Implementations§
Source§impl Clone for PropsUpdate
impl Clone for PropsUpdate
Source§impl Debug for PropsUpdate
impl Debug for PropsUpdate
Source§impl Default for PropsUpdate
impl Default for PropsUpdate
Source§impl IntoResponseParts for PropsUpdate
impl IntoResponseParts for PropsUpdate
Source§fn into_response_parts(
self,
res: ResponseParts,
) -> Result<ResponseParts, Self::Error>
fn into_response_parts( self, res: ResponseParts, ) -> Result<ResponseParts, Self::Error>
Set parts of the response
Auto Trait Implementations§
impl Forget for PropsUpdate
impl Freeze for PropsUpdate
impl RefUnwindSafe for PropsUpdate
impl Send for PropsUpdate
impl Sync for PropsUpdate
impl Unpin for PropsUpdate
impl UnsafeUnpin for PropsUpdate
impl UnwindSafe for PropsUpdate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
Open a deferred
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.