Skip to main content

Component

Trait Component 

Source
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§

Source

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§

Source

fn boot(&mut self) -> Result<()>

Runs before the component mounts or hydrates, on every request.

Source

fn initialize(&mut self, context: &mut ComponentContext) -> Result<()>

Runs after boot, before the component mounts or hydrates.

Source

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.

Source

fn booted(&mut self) -> Result<()>

Runs after the component mounted, on its first request.

Source

fn hydrate(&mut self, context: &mut ComponentContext) -> Result<()>

Runs when a later request rebuilds the component from its snapshot.

Source

fn render(&self) -> Result<ComponentView>

Produces the component’s markup.

§Errors

Fails when the component cannot name its view or its data.

Source

fn dehydrate(&mut self, context: &mut ComponentContext) -> Result<()>

Runs before the snapshot is written.

Source

fn destroy(&mut self)

Runs after the response is built, when the component instance is dropped.

Source

fn updating( &mut self, property: &str, value: &Value, context: &mut ComponentContext, ) -> Result<()>

Runs before an update assigns property.

Source

fn updated( &mut self, property: &str, context: &mut ComponentContext, ) -> Result<()>

Runs after every update of a batch is assigned.

Source

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,

Whether the browser may run method, which an action’s authorize path decides.

§Errors

Fails when the policy itself cannot run.

Source

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.

Source

fn release_token(&self) -> &'static str

The token a redeployment changes, so a stale browser page is asked to reload.

Source

fn listeners(&self) -> &'static [Listener]

The events the component listens to.

Source

fn dispatches(&self) -> &'static [Listener]

The events the component dispatches when it mounts.

Source

fn exception(&mut self, error: &LivewireError, context: &mut ComponentContext)

Runs when an action failed, before the failure becomes a response.

Source

fn action_result_kind(&self, method: &str) -> ActionResultKind

Whether an action’s return value becomes a returns effect or JSON.

Source

fn class_options(&self) -> ClassOptions

The options the component’s class-level attribute declared.

Source

fn async_methods(&self) -> &'static [&'static str]

The actions the browser sends ahead of the others.

Source

fn json_methods(&self) -> &'static [&'static str]

The actions that answer with JSON instead of new markup.

Source

fn computed_values(&self, id: &str) -> Map<String, Value>

The component’s computed properties, which its template reads like fields.

A computed property is memoized for the rest of the request, so a template that prints it twice computes it once.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§