pub struct ComponentRegistry { /* private fields */ }Expand description
The components and template hooks one application registered.
Implementations§
Source§impl ComponentRegistry
impl ComponentRegistry
Sourcepub fn new(config: LivewireConfig) -> Self
pub fn new(config: LivewireConfig) -> Self
An empty registry for an application configured with config.
Sourcepub fn persistent(
&mut self,
guard: impl PersistentMiddleware + 'static,
) -> &mut Self
pub fn persistent( &mut self, guard: impl PersistentMiddleware + 'static, ) -> &mut Self
Registers a guard that runs on every update of a component mounted by a page.
The guard sees the update’s request and the page the component was mounted from, so a route guard the page ran runs again when the browser drives the component.
Sourcepub fn hook(
&mut self,
callback: impl Fn(&HookEvent<'_>) + Send + Sync + 'static,
) -> &mut Self
pub fn hook( &mut self, callback: impl Fn(&HookEvent<'_>) + Send + Sync + 'static, ) -> &mut Self
Registers a lifecycle hook, which the pipeline runs at each step.
Hooks run in registration order, on every request, for every component.
Sourcepub fn register<C: Component + Default>(
&mut self,
name: impl Into<String>,
) -> Result<&mut Self, RegistryError>
pub fn register<C: Component + Default>( &mut self, name: impl Into<String>, ) -> Result<&mut Self, RegistryError>
Registers a component under name.
§Errors
Fails when the name is invalid, or when another component already has it.
Sourcepub fn register_with<C: Component + Default>(
&mut self,
name: impl Into<String>,
factory: impl Fn() -> C + Send + Sync + 'static,
) -> Result<&mut Self, RegistryError>
pub fn register_with<C: Component + Default>( &mut self, name: impl Into<String>, factory: impl Fn() -> C + Send + Sync + 'static, ) -> Result<&mut Self, RegistryError>
Registers a component that is built by factory rather than by Default.
§Errors
Fails when the name is invalid, or when another component already has it.
Sourcepub fn register_synth<S: Synth>(&mut self) -> Result<&mut Self, RegistryError>
pub fn register_synth<S: Synth>(&mut self) -> Result<&mut Self, RegistryError>
Registers a synthesizer, so that a snapshot may name its key.
§Errors
Fails when another synthesizer already has the key.
Sourcepub fn register_synth_key(
&mut self,
key: &'static str,
) -> Result<&mut Self, RegistryError>
pub fn register_synth_key( &mut self, key: &'static str, ) -> Result<&mut Self, RegistryError>
Registers a synthesizer key that a field already names.
§Errors
Fails when another synthesizer already has the key.
Sourcepub fn templates(
&mut self,
configure: impl Fn(&mut Environment<'static>) + Send + Sync + 'static,
) -> &mut Self
pub fn templates( &mut self, configure: impl Fn(&mut Environment<'static>) + Send + Sync + 'static, ) -> &mut Self
Adds a callback that configures the .livewire engine, such as filters of the application’s
own.
Sourcepub fn synth_keys(&self) -> impl Iterator<Item = &'static str> + '_
pub fn synth_keys(&self) -> impl Iterator<Item = &'static str> + '_
The synthesizer keys the application registered.
Sourcepub fn instantiate(&self, name: &str) -> Option<Box<dyn Component>>
pub fn instantiate(&self, name: &str) -> Option<Box<dyn Component>>
A new instance of the component registered as name.
Sourcepub fn wire_fields(&self, name: &str) -> Option<&'static [WireField]>
pub fn wire_fields(&self, name: &str) -> Option<&'static [WireField]>
The wire-public fields of the component registered as name.
Sourcepub fn names(&self) -> impl ExactSizeIterator<Item = &str>
pub fn names(&self) -> impl ExactSizeIterator<Item = &str>
The names of the registered components, in order.
Sourcepub fn template_configurators(&self) -> &[TemplateConfigurator]
pub fn template_configurators(&self) -> &[TemplateConfigurator]
The callbacks that configure the engine.
Sourcepub fn config(&self) -> &LivewireConfig
pub fn config(&self) -> &LivewireConfig
The configuration the application froze the registry with.
Sourcepub fn synthesize_placeholder(&self) -> bool
pub fn synthesize_placeholder(&self) -> bool
Whether the built-in placeholder renders a lazy component before it loads.
Sourcepub fn without_placeholder(&mut self) -> &mut Self
pub fn without_placeholder(&mut self) -> &mut Self
Turns the built-in lazy placeholder off, for an application that renders its own.