Cranpose Core
The core runtime engine for Cranpose. This crate implements the fundamental algorithms for managing the composition tree, state snapshots, and change detection.
When to Use
Use cranpose-core directly if you are:
- Building a custom tree management system unrelated to UI (e.g., a reactive scene graph).
- Implementing low-level state primitives.
- Developing a renderer for a strictly non-standard environment where the higher-level
cranpose-uimight be too opinionated.
Key Concepts
- Slot Table: A linear, gap-buffer-based data structure that stores the composition tree efficiently in memory. It optimizes for locality and minimizes allocations compared to pointer-based trees.
- Composer: The primary interface for building and updating the slot table. It tracks the current position in the tree and handles inserting, updating, or removing nodes.
- Snapshot System: A multi-version concurrency control (MVCC) system for state. It allows
MutableStateto be read and written transactions, enabling atomic updates and ensuring UI consistency during concurrent operations. - Recomposition: The process of re-executing composable functions when their dependencies change. The runtime tracks dependencies at a fine-grained level (scopes) to minimize re-execution.
Example: Manual State Transaction
The following example shows how to perform atomic state updates using the snapshot system explicitly.
use ;