Skip to content

struct

Props

pub struct Props {
    /* private fields */
}

The attributes and event handlers a parent passes to a component. Reads are reactive, so derived values update when the parent re-renders.

Methods

new

pub fn new(values: BTreeMap<String, Value>) -> Props

Props holding values, with no event handlers yet and a fresh id.

provide

pub fn provide<T: 'static>(&self, key: &str, value: T)

Provide value under key to every component rendered inside this one — including slot content written by the caller. Call it in setup; share state by providing signals (or a struct of them).

context

pub fn context<T: Clone + 'static>(&self, key: &str) -> Option<T>

The nearest ancestor's value for key, if it has the type T.

handler_names

pub fn handler_names(&self) -> Vec<String>

Names of the event handlers the parent passed (@name: …).

values

pub fn values(&self) -> BTreeMap<String, Value>

Every value the parent passed.

id

pub fn id(&self) -> String

A document-unique id for this component instance — use it to build id/aria-controls/aria-labelledby references.

get

pub fn get(&self, name: &str) -> Option<Value>

The value of prop name, if the parent passed it. Reading it inside an effect or computed value subscribes to it.

num

pub fn num(&self, name: &str) -> Option<f64>

Prop name as a number (numeric text counts), if it is one.

text

pub fn text(&self, name: &str) -> Option<String>

Prop name as text, if the parent passed it.

flag

pub fn flag(&self, name: &str) -> bool

Whether prop name is truthy (missing is false).

emit

pub fn emit(&self, name: &str, event: &Event) -> bool

Invoke the parent's handler for name (from @name: handler).

emitter

pub fn emitter(&self) -> Emitter

A handle that can emit this component's events later — it holds only the handlers, so storing it in shared context makes no cycles.

set_values

pub fn set_values(&self, values: BTreeMap<String, Value>) -> bool

Replace the values; returns whether anything changed.

set_handlers

pub fn set_handlers(&self, handlers: Vec<(String, Handler)>)

Replace the parent's event handlers (@name: …), by event name.

Trait implementations