Skip to main content

Component

Trait Component 

Source
pub trait Component:
    Send
    + Sync
    + 'static {
    // Required methods
    fn class_name() -> &'static str
       where Self: Sized;
    fn view_path() -> &'static str
       where Self: Sized;
    fn snapshot_data(&self) -> Value;
    fn load_snapshot(data: &Value) -> Result<Self>
       where Self: Sized;
    fn apply_writes<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        writes: &'life1 [PropertyWrite],
        ctx: &'life2 mut Ctx,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn dispatch_call<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 mut self,
        method: &'life1 str,
        args: Vec<Value>,
        ctx: &'life2 mut Ctx,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn listeners() -> Vec<String>
       where Self: Sized { ... }
    fn mount(props: MountProps) -> Self
       where Self: Sized + Default { ... }
    fn render(&self) -> Result<String>
       where Self: Sized { ... }
}
Expand description

User-facing trait — implemented for every Spark component by the #[spark::component] attribute macro on the struct + #[spark::actions] on the impl block.

Render is sync because the template engine is sync and the typical render path is pure data → HTML; async work (DB hits, API calls) belongs in actions and mount, not in render.

Required Methods§

Source

fn class_name() -> &'static str
where Self: Sized,

Source

fn view_path() -> &'static str
where Self: Sized,

Source

fn snapshot_data(&self) -> Value

Source

fn load_snapshot(data: &Value) -> Result<Self>
where Self: Sized,

Source

fn apply_writes<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, writes: &'life1 [PropertyWrite], ctx: &'life2 mut Ctx, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn dispatch_call<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, method: &'life1 str, args: Vec<Value>, ctx: &'life2 mut Ctx, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Provided Methods§

Source

fn listeners() -> Vec<String>
where Self: Sized,

Source

fn mount(props: MountProps) -> Self
where Self: Sized + Default,

Source

fn render(&self) -> Result<String>
where Self: Sized,

Implementors§