pub trait Component: LivewireState {
Show 22 methods
// Required method
fn call<'life0, 'life1, 'async_trait>(
&'life0 mut self,
call: Call,
context: &'life1 mut ComponentContext,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn boot(&mut self) -> Result<()> { ... }
fn initialize(&mut self, context: &mut ComponentContext) -> Result<()> { ... }
fn mount(
&mut self,
params: Params,
context: &mut ComponentContext,
) -> Result<()> { ... }
fn booted(&mut self) -> Result<()> { ... }
fn hydrate(&mut self, context: &mut ComponentContext) -> Result<()> { ... }
fn render(&self) -> Result<ComponentView> { ... }
fn dehydrate(&mut self, context: &mut ComponentContext) -> Result<()> { ... }
fn destroy(&mut self) { ... }
fn updating(
&mut self,
property: &str,
value: &Value,
context: &mut ComponentContext,
) -> Result<()> { ... }
fn updated(
&mut self,
property: &str,
context: &mut ComponentContext,
) -> Result<()> { ... }
fn authorize<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
method: &'life1 str,
context: &'life2 ComponentContext,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn hydrate_models<'life0, 'life1, 'async_trait>(
&'life0 mut self,
context: &'life1 mut ComponentContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn release_token(&self) -> &'static str { ... }
fn listeners(&self) -> &'static [Listener] { ... }
fn dispatches(&self) -> &'static [Listener] { ... }
fn exception(
&mut self,
error: &LivewireError,
context: &mut ComponentContext,
) { ... }
fn action_result_kind(&self, method: &str) -> ActionResultKind { ... }
fn class_options(&self) -> ClassOptions { ... }
fn async_methods(&self) -> &'static [&'static str] { ... }
fn json_methods(&self) -> &'static [&'static str] { ... }
fn computed_values(&self, id: &str) -> Map<String, Value> { ... }
}Expand description
A component: wire-public state plus the lifecycle the server runs around it.
Every method has a default, so a component implements only the hooks it needs. The derive and
#[livewire::component] generate the state methods and the action
dispatch; an inherent method is reachable from the browser only when it appears in the annotated
implementation.
Required Methods§
Sourcefn call<'life0, 'life1, 'async_trait>(
&'life0 mut self,
call: Call,
context: &'life1 mut ComponentContext,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn call<'life0, 'life1, 'async_trait>(
&'life0 mut self,
call: Call,
context: &'life1 mut ComponentContext,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Runs one action the browser called.
§Errors
Fails when the method is unknown, its parameters do not decode, or the action fails.
Provided Methods§
Sourcefn boot(&mut self) -> Result<()>
fn boot(&mut self) -> Result<()>
Runs before the component mounts or hydrates, on every request.
Sourcefn initialize(&mut self, context: &mut ComponentContext) -> Result<()>
fn initialize(&mut self, context: &mut ComponentContext) -> Result<()>
Runs after boot, before the component mounts or hydrates.
Sourcefn mount(
&mut self,
params: Params,
context: &mut ComponentContext,
) -> Result<()>
fn mount( &mut self, params: Params, context: &mut ComponentContext, ) -> Result<()>
Runs when the component first appears on the page.
§Errors
Fails when the props cannot be read into the component’s fields.
Sourcefn hydrate(&mut self, context: &mut ComponentContext) -> Result<()>
fn hydrate(&mut self, context: &mut ComponentContext) -> Result<()>
Runs when a later request rebuilds the component from its snapshot.
Sourcefn render(&self) -> Result<ComponentView>
fn render(&self) -> Result<ComponentView>
Sourcefn dehydrate(&mut self, context: &mut ComponentContext) -> Result<()>
fn dehydrate(&mut self, context: &mut ComponentContext) -> Result<()>
Runs before the snapshot is written.
Sourcefn destroy(&mut self)
fn destroy(&mut self)
Runs after the response is built, when the component instance is dropped.
Sourcefn updating(
&mut self,
property: &str,
value: &Value,
context: &mut ComponentContext,
) -> Result<()>
fn updating( &mut self, property: &str, value: &Value, context: &mut ComponentContext, ) -> Result<()>
Runs before an update assigns property.
Sourcefn updated(
&mut self,
property: &str,
context: &mut ComponentContext,
) -> Result<()>
fn updated( &mut self, property: &str, context: &mut ComponentContext, ) -> Result<()>
Runs after every update of a batch is assigned.
Whether the browser may run method, which an action’s authorize path decides.
§Errors
Fails when the policy itself cannot run.
Sourcefn hydrate_models<'life0, 'life1, 'async_trait>(
&'life0 mut self,
context: &'life1 mut ComponentContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn hydrate_models<'life0, 'life1, 'async_trait>(
&'life0 mut self,
context: &'life1 mut ComponentContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Fetches the model references this component holds, before the hooks, the actions, and the render read them.
The derive generates this for #[livewire(model)] fields; a component without one keeps the
default, which resolves nothing.
Sourcefn release_token(&self) -> &'static str
fn release_token(&self) -> &'static str
The token a redeployment changes, so a stale browser page is asked to reload.
Sourcefn dispatches(&self) -> &'static [Listener]
fn dispatches(&self) -> &'static [Listener]
The events the component dispatches when it mounts.
Sourcefn exception(&mut self, error: &LivewireError, context: &mut ComponentContext)
fn exception(&mut self, error: &LivewireError, context: &mut ComponentContext)
Runs when an action failed, before the failure becomes a response.
Sourcefn action_result_kind(&self, method: &str) -> ActionResultKind
fn action_result_kind(&self, method: &str) -> ActionResultKind
Whether an action’s return value becomes a returns effect or JSON.
Sourcefn class_options(&self) -> ClassOptions
fn class_options(&self) -> ClassOptions
The options the component’s class-level attribute declared.
Sourcefn async_methods(&self) -> &'static [&'static str]
fn async_methods(&self) -> &'static [&'static str]
The actions the browser sends ahead of the others.
Sourcefn json_methods(&self) -> &'static [&'static str]
fn json_methods(&self) -> &'static [&'static str]
The actions that answer with JSON instead of new markup.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".