Expand description
Server-state-backed reactive components - Larust’s Livewire equivalent.
Unlike Livewire’s client-held, HMAC-signed state snapshot (a workaround
for PHP/Laravel’s stateless-between-requests model), a component’s state
lives entirely server-side, keyed by the user’s session: only an opaque
component id ever crosses the wire. See docs/ARCHITECTURE.md’s
“Reactive components” section for the full design rationale.
The crate itself keeps its original name (larust-live) - only the
user-facing directive/trait/route surface is @wire/WireComponent/
/__larust_wire/....
App authors implement WireComponent, register instances via
components/LiveRegistry, mount them from a template with
@wire('name', { prop: expr, ... }), and wire the two routes this crate
provides (update, runtime_js) into their app’s router - nothing
here is auto-mounted, matching this framework’s “explicit over magic”
convention for routes/middleware/listeners elsewhere.
push is a separate, unrelated feature living in the same crate:
genuine server-pushed updates (@live('channel') ... @endlive,
WebSocket-based) rather than @wire’s client-initiated AJAX sync -
see that module’s own doc comment for why these two are deliberately
not the same mechanism.
Modules§
- push
- Genuine server-pushed real-time updates -
@live('channel') ... @endlivein a template, paired with a [broadcast] call wherever server state actually changes. Deliberately a different mechanism from@wire’s reactive components, not a bigger version of the same one:@wireis client-initiated (a user’s ownwire:model/wire:click/wire:submittriggers an AJAX round-trip that only ever updates that visitor’s own view);@liveis server-initiated (any server-side event pushes an update to every currently connected viewer of that channel, with zero interaction required in any of their tabs - the live-chat/live-notification case neither@wirenor real Livewire itself can do, since both are built around a request/response cycle, not a held-open connection).
Structs§
- Live
Registry - Update
Payload - A deeply-nested
props/argspayload (an attacker-controlled input, gated only by CSRF) can’t stack-overflow this endpoint’s JSON parsing:axum::Json’sserde_json::from_sliceruns withserde_json’s default recursion limit (128 levels,Deserializer::disable_recursion_limitleft uncalled) already in force - confirmed againstserde_json’s own source, not assumed. - Wire
Plugin - The two routes
@wire(...)needs, bundled forlarust_http::Router::plugin- sugar for the exact.get/.postpair this module’s own doc comment shows an app writing by hand today. Registration itself is still the app’s explicit choice (.plugin(WirePlugin)inroutes/web.rs), this only removes the need to know or copy the two literal route strings.
Traits§
- Wire
Component - A server-state-backed reactive component - Larust’s Livewire-equivalent.
Unlike Livewire,
Self’s state never crosses the wire: it lives server-side, keyed by the user’s session (seelarust-live::state), and only an opaque component id is ever sent to/from the browser.
Functions§
- components
- Starts building the process-wide wire-component registry. Call
.register::<C>()for each component, then.publish()once, typically right beforeApplication::serve()- same “build via fluent chain, then publish once” shape aslarust_events::listeners()/ListenerRegistry. - mount
- Mounts a fresh instance of the component registered as
name, storing its initial state server-side (keyed bysession) and returning the rendered<div data-wire-id="...">wrapper - what a@wire(...)codegen call site splices directly into the surrounding page’s HTML. - runtime_
js GET /__larust_wire/runtime.js- the vendored client runtime, served from the installedlarust-livecrate itself (include_str!’d, not vendored into every scaffolded app’spublic/js/) so it stays version-locked to the framework with zero drift/“forgot to re-copy after an upgrade” risk.- update
POST /__larust_wire/{component_id}- handles both awire:model-style prop sync and awire:click-style action call in one request (seeUpdatePayload): every sync carries the component’s entire currentwire:modelfield set, not a delta, which is what correctly threads a deferred field’s just-typed value through when a different element’s click/wire-sync is what actually triggers the request.