edifice.Element#
- class edifice.Element[source]#
Bases:
object
The base class for Edifice Elements.
In user code you should almost never use
Element
directly. Instead use Base Elements andcomponent()
Elements.A
Element
is a stateful container wrapping a render function. Elements have both internal and external properties.The external properties, props, are passed into the
Element
by anotherElement
’s render function through the constructor. These values are owned by the external caller and should not be modified by thisElement
.Methods
__init__
()register_ref
(reference)Registers provided
Reference
to this Element.set_key
(key)Sets the key of the Element.
Attributes
The children of this Element.
The props of this Element.
- property props: PropsDict#
The props of this Element.
- register_ref(reference)[source]#
Registers provided
Reference
to this Element.During render, the provided reference will be set to point to the currently rendered instance of this Element (i.e. if another instance of the Element is rendered and the RenderEngine decides to reconcile the existing and current instances, the reference will eventually point to that previously existing Element.
- Parameters:
reference (
Reference
) – the Reference to register- Return type:
Self
- Returns:
The Element self.
- set_key(key)[source]#
Sets the key of the Element.
The key is used by the re-rendering logic to match a new list of Elements with an existing list of Elements. The algorithm will assume that Elements with the same key are logically the same. If the key is not provided, the list index will be used as the key; however, providing the key may provide more accurate results, leading to efficiency gains.
Returns the Element to allow for chaining.
Example:
# inside a render call with edifice.View(): edifice.Label("Hello").set_key("en") edifice.Label("Bonjour").set_key("fr") edifice.Label("Hola").set_key("es")
- Parameters:
key (
str
) – The key to label the Element with.- Return type:
Self
- Returns:
The Element itself.