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 and @component 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 another Element’s render function through the constructor. These values are owned by the external caller and should not be modified by this Element.

Methods

__init__()

register_ref(reference)

Registers provided Reference to this Element.

set_key(key)

Set the key of an Element.

Attributes

children

The children of this Element.

props

The props of this Element.

property children: tuple[Element, ...]#

The children 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.

Parameters:

reference (Reference[Self]) – the Reference to register

Return type:

Self

Returns:

The Element self.

set_key(key)[source]#

Set the key of an Element.

The key is used when re-rendering to match new child Elements with old child Elements. The diffing algorithm will assume that child Elements with the same key are identical.

Each key must be unique and persistent. The Edifice Rules of Keys are the same as the React Rules of Keys.

  • Keys must be unique among siblings. However, it’s okay to use the same keys for Elements of different parents.

  • Keys must not change or that defeats their purpose! Don’t generate them while rendering.

Returns the Element to allow for chaining.

Example:

with VBoxView():
    if english:
        Label("Hello").set_key("en")
    if french:
        Label("Bonjour").set_key("fr")
    if spanish:
        Label("Hola").set_key("es")
Parameters:

key (str | None) – The Element unique key string.

Return type:

Self

Returns:

The Element.