pub struct LivewireRequest { /* private fields */ }Expand description
One request’s mutable Livewire state.
Implementations§
Source§impl LivewireRequest
impl LivewireRequest
Sourcepub fn current() -> Option<Arc<Self>>
pub fn current() -> Option<Arc<Self>>
The request’s state, created on first use, or None outside a request.
§Panics
Panics when the request-local store is unavailable, which only happens outside the application.
Sourcepub fn push_mounting(&self, id: &str) -> StackGuard<'_>
pub fn push_mounting(&self, id: &str) -> StackGuard<'_>
Marks a component as mounting, and returns a guard that unmarks it when dropped.
Sourcepub fn mounting(&self) -> Option<String>
pub fn mounting(&self) -> Option<String>
The component that is mounting now, which is the parent of a component being mounted inside it.
Sourcepub fn push_rendering(&self, id: &str) -> StackGuard<'_>
pub fn push_rendering(&self, id: &str) -> StackGuard<'_>
Marks a component as rendering, and returns a guard that unmarks it when dropped.
Sourcepub fn render_depth(&self) -> usize
pub fn render_depth(&self) -> usize
How many components are rendering, which is the depth a nested render reports.
Sourcepub fn register(&self, id: &str, state: ComponentState)
pub fn register(&self, id: &str, state: ComponentState)
Registers a component’s state, replacing any state under the same ID.
Sourcepub fn remember_page(&self, path: &str, method: &str, origin: &str)
pub fn remember_page(&self, path: &str, method: &str, origin: &str)
Remembers the page this request rendered, which a mount records and an update replays.
Sourcepub fn page(&self) -> Option<PageContext>
pub fn page(&self) -> Option<PageContext>
The page this request rendered, when one did.
Sourcepub fn read<T>(
&self,
id: &str,
read: impl FnOnce(&ComponentState) -> T,
) -> Option<T>
pub fn read<T>( &self, id: &str, read: impl FnOnce(&ComponentState) -> T, ) -> Option<T>
Reads a component’s state.
Sourcepub fn change(&self, id: &str, change: impl FnOnce(&mut ComponentState))
pub fn change(&self, id: &str, change: impl FnOnce(&mut ComponentState))
Changes a component’s state, creating it when the component is not registered yet.
Sourcepub fn has_rendered(&self) -> bool
pub fn has_rendered(&self) -> bool
Whether any component rendered in this request, which decides whether the page needs the runtime at all.
Sourcepub fn add_child(&self, parent: &str, child: Child)
pub fn add_child(&self, parent: &str, child: Child)
Records that a component rendered a nested component.
Sourcepub fn add_asset(&self, asset: &str) -> bool
pub fn add_asset(&self, asset: &str) -> bool
Records an asset the response reports, returning whether it is new.
Sourcepub fn take_assets(&self) -> Vec<String>
pub fn take_assets(&self) -> Vec<String>
Takes the assets the response reports, in the order they were added.
Sourcepub fn mark_styles_rendered(&self)
pub fn mark_styles_rendered(&self)
Records that the page called livewire_styles() itself, so the response does not add them
again.
Sourcepub fn styles_rendered(&self) -> bool
pub fn styles_rendered(&self) -> bool
Whether the page called livewire_styles() itself.
Sourcepub fn mark_scripts_rendered(&self)
pub fn mark_scripts_rendered(&self)
Records that the page called livewire_scripts() itself, so the response does not add them
again.
Sourcepub fn scripts_rendered(&self) -> bool
pub fn scripts_rendered(&self) -> bool
Whether the page called livewire_scripts() itself.
Sourcepub fn first_asset_render(&self, asset: &str) -> bool
pub fn first_asset_render(&self, asset: &str) -> bool
Marks an asset as rendered in this request, returning false when it already was.
Sourcepub fn first_script_render(&self, script: &str) -> bool
pub fn first_script_render(&self, script: &str) -> bool
Marks a script as rendered in this request, returning false when it already was.
Sourcepub fn add_stream(&self, stream: Stream)
pub fn add_stream(&self, stream: Stream)
Records a streamed chunk.
Sourcepub fn take_streams(&self) -> Vec<Stream>
pub fn take_streams(&self) -> Vec<Stream>
Takes the streamed chunks, in the order they were sent.
Sourcepub fn is_streaming(&self) -> bool
pub fn is_streaming(&self) -> bool
Whether anything streamed, so the response is an event stream.
Sourcepub fn computed(&self, component: &str, name: &str) -> Option<Value>
pub fn computed(&self, component: &str, name: &str) -> Option<Value>
The memoized value of a computed property, if this request computed it already.
Sourcepub fn set_computed(&self, component: &str, name: &str, value: Value)
pub fn set_computed(&self, component: &str, name: &str, value: Value)
Memoizes a computed property’s value for the rest of the request.
Sourcepub fn forget_computed(&self, component: &str, name: &str)
pub fn forget_computed(&self, component: &str, name: &str)
Forgets a computed property, so the next read recomputes it.
Sourcepub fn first_checksum_check(&self) -> bool
pub fn first_checksum_check(&self) -> bool
Whether this request already checked the client’s checksum-failure allowance. The batch checks once, however many components it updates.
Sourcepub fn set_http_request(&self, request: Arc<Request>)
pub fn set_http_request(&self, request: Arc<Request>)
Keeps the HTTP request being handled, so an action can reach it.
Sourcepub fn http_request(&self) -> Option<Arc<Request>>
pub fn http_request(&self) -> Option<Arc<Request>>
The HTTP request being handled, or None outside a request.
Sourcepub fn set_persistent(&self, key: &str, value: Value)
pub fn set_persistent(&self, key: &str, value: Value)
Records a value the route’s persistent middleware resolved.
Sourcepub fn persistent(&self, key: &str) -> Option<Value>
pub fn persistent(&self, key: &str) -> Option<Value>
Reads a value the route’s persistent middleware resolved.