Skip to main content

Crate larust_live

Crate larust_live 

Source
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') ... @endlive in 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: @wire is client-initiated (a user’s own wire:model/ wire:click/wire:submit triggers an AJAX round-trip that only ever updates that visitor’s own view); @live is 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 @wire nor real Livewire itself can do, since both are built around a request/response cycle, not a held-open connection).

Structs§

LiveRegistry
UpdatePayload
A deeply-nested props/args payload (an attacker-controlled input, gated only by CSRF) can’t stack-overflow this endpoint’s JSON parsing: axum::Json’s serde_json::from_slice runs with serde_json’s default recursion limit (128 levels, Deserializer::disable_recursion_limit left uncalled) already in force - confirmed against serde_json’s own source, not assumed.
WirePlugin
The two routes @wire(...) needs, bundled for larust_http::Router::plugin - sugar for the exact .get/.post pair this module’s own doc comment shows an app writing by hand today. Registration itself is still the app’s explicit choice (.plugin(WirePlugin) in routes/web.rs), this only removes the need to know or copy the two literal route strings.

Traits§

WireComponent
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 (see larust-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 before Application::serve() - same “build via fluent chain, then publish once” shape as larust_events::listeners()/ListenerRegistry.
mount
Mounts a fresh instance of the component registered as name, storing its initial state server-side (keyed by session) 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 installed larust-live crate itself (include_str!’d, not vendored into every scaffolded app’s public/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 a wire:model-style prop sync and a wire:click-style action call in one request (see UpdatePayload): every sync carries the component’s entire current wire:model field 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.