pub struct ComponentContext<'a> {
pub component_id: String,
pub surface_id: String,
pub data_context: DataContext<'a>,
pub components: &'a SurfaceComponentsModel,
pub focused_id: Option<String>,
pub template_index: Option<usize>,
}Expand description
Transient context created for each component during rendering.
The caller is responsible for holding the RefCell borrows on DataModel and SurfaceComponentsModel for the duration of rendering.
Fields§
§component_id: StringThe component’s ID.
surface_id: StringThe surface ID this component belongs to.
data_context: DataContext<'a>Scoped data access for resolving dynamic values.
components: &'a SurfaceComponentsModelThe components model (escape hatch for inspecting siblings/children).
focused_id: Option<String>The ID of the currently focused component, if any.
template_index: Option<usize>The index of this component within a template iteration, if applicable.
Implementations§
Source§impl<'a> ComponentContext<'a>
impl<'a> ComponentContext<'a>
Sourcepub fn new(
component_id: String,
surface_id: String,
data_model: &'a DataModel,
components: &'a SurfaceComponentsModel,
functions: &'a HashMap<String, Box<dyn FunctionImplementation>>,
base_path: &str,
focused_id: Option<String>,
) -> Self
pub fn new( component_id: String, surface_id: String, data_model: &'a DataModel, components: &'a SurfaceComponentsModel, functions: &'a HashMap<String, Box<dyn FunctionImplementation>>, base_path: &str, focused_id: Option<String>, ) -> Self
Create a component context.
Callers should borrow surface.data_model and surface.components
before calling this and pass the references.
The base_path scopes data access for this component. When it ends in a
numeric segment (e.g. /items/3 — the shape every backend produces when
expanding a ChildList::Template), that segment is taken as the template
item index and exposes the @index system function. Callers needing
precise control can override it via with_template_index.
Sourcepub fn with_template_index(self, index: Option<usize>) -> Self
pub fn with_template_index(self, index: Option<usize>) -> Self
Override the template index (builder style), propagating it to the data
context so the @index system function resolves correctly.
Some(i) sets the index; None clears it (disabling @index).
Sourcepub fn set_template_index(&mut self, index: Option<usize>)
pub fn set_template_index(&mut self, index: Option<usize>)
Set the template index in place, propagating it to the data context.