Skip to content

Mutation ops

Four record types describe every change to the native view tree: create, update, insert, and destroy. The Reconciler emits them; the view backend from get_backend applies them in one apply_mutations call per commit. Geometry isn't an op: the renderer core lays out each commit.

Batched mutation protocol between the reconciler and native backends.

Every commit pass produces an ordered list of small mutation ops referencing integer tags (stable per-view identifiers), and the whole list is applied in a single apply_mutations call. The renderer core validates the batch, lays it out, and turns it into a mount transaction for the platform's UI thread (RFC 0007); frames never travel as ops.

Why tags instead of view objects?

  • The diff phase runs before any native view exists, so ops cannot reference views directly.
  • Tags give the native side a stable identity to key its own view registry, event routing, and animation bookkeeping on.
  • A flat list of (op, tag, payload) tuples serializes directly into the bridge's transaction envelope, so one commit is one crossing.

Op ordering rules (the reconciler guarantees these):

  1. A CreateOp for a tag precedes any other op referencing that tag.
  2. InsertOp ops appear after both the parent and child exist.
  3. DestroyOp ops are emitted children-first; handlers detach the view from its parent as part of destruction.

Classes:

Name Description
UnsetType

The explicit absence of a native property, distinct from null.

CreateOp

Create a native view for tag of element type type_name.

UpdateOp

Apply changed_props to the view registered under tag.

InsertOp

Ensure the child view sits at index inside the parent view.

DestroyOp

Release the native view registered under tag.

Attributes:

Name Type Description
UNSET

Remove a property and restore its native default on the next commit.

Mutation

Union of every op type carried by a commit transaction.

UNSET module-attribute

UNSET = UnsetType.VALUE

Remove a property and restore its native default on the next commit.

Mutation module-attribute

Union of every op type carried by a commit transaction.

UnsetType

Bases: Enum

The explicit absence of a native property, distinct from null.

CreateOp

CreateOp(
    tag: int,
    type_name: str,
    props: Optional[Dict[str, Any]] = None,
)

Bases: _Op

Create a native view for tag of element type type_name.

Attributes:

Name Type Description
tag int

Unique integer identity assigned by the reconciler.

type_name str

Element type name (e.g. "Text").

props Dict[str, Any]

Initial clean props; callables have already been moved to the view's event handlers and replaced by the _pn_events name set.

UpdateOp

UpdateOp(
    tag: int, changed_props: Optional[Dict[str, Any]] = None
)

Bases: _Op

Apply changed_props to the view registered under tag.

Removed props are signaled with UNSET. None sets a nullable property to an explicit native null value.

Attributes:

Name Type Description
tag int

Unique integer identity of the target view.

changed_props Dict[str, Any]

Mapping of modified prop names to their new values. Removed props appear with the UNSET sentinel.

InsertOp

InsertOp(parent_tag: int, child_tag: int, index: int)

Bases: _Op

Ensure the child view sits at index inside the parent view.

Handlers must treat this as move-aware: if the child is already attached to the parent at a different position, it is moved rather than duplicated. index is clamped by handlers to the current child count.

Attributes:

Name Type Description
parent_tag int

Integer tag of the container view.

child_tag int

Integer tag of the child view to insert or move.

index int

Zero-based insertion index, clamped by handlers to the current child count.

DestroyOp

DestroyOp(tag: int)

Bases: _Op

Release the native view registered under tag.

The backend drops its tag record and the native component manager releases platform resources (listeners, timers, image loads) eagerly instead of waiting for GC.

Attributes:

Name Type Description
tag int

Unique integer identity of the view to destroy.

Next steps

  • See where the callables stripped from these payloads go in Events.
  • See how each op is applied to a concrete widget in Native views.
  • Read what component managers size themselves against in Platform metrics.
  • Read the diffing pass that produces these lists in Reconciliation.