API cheat sheet
Use this page to look up a name once you know the model. For a runnable introduction, start with From local to shared.
Plexus
Section titled “Plexus”Document creation, connection, and transactions. See Connecting clients and Reactivity and transactions.
// ── Plexus ──const plexus = Plexus.bootstrap(root, documentId?, doc?);const plexus = Plexus.connect(existingDoc);
plexus.root; // root modelplexus.doc; // underlying Y.Docplexus.loadEntity<T>(uuid); // entity by UUIDplexus.getAllOfType(Constructor); // all instances of typeplexus.parentsOf(node, ParentClass, field); // reverse lookupplexus.transact(fn); // batched transactionplexus.undo();plexus.redo();PlexusModel
Section titled “PlexusModel”Identity and operations on a model instance. See Document lifecycle.
// ── PlexusModel<Parent> — Parent types .parent; construct with PlexusInit<this> ──entity.localID; // process-local creation order; always present; never serializedentity.uuid; // CRDT identity; throws before materializationentity.documentId; // Y.Doc guid; undefined if unmaterialized / dependencyentity.parent; // owning parent, or nullentity.parentField; // field name on parent, or nullentity.parentFieldKey; // key inside that field, or nullentity.rootAncestor; // walk to Plexus root, or nullentity.isRoot;entity.isDetached; // materialized and unreachable from root; ephemeral is notentity.detach(); // remove from parent; stays in doc; true if it was attachedentity.clone(overrides?); // deep clone of owned subtreeentity.toJSON(); // plain object of schema fieldsentity.parentsOf(ParentClass, field); // yield parents that hold this entity in fieldModel.modelName; // registered type nameModel.schema; // field → kind@syncing
Section titled “@syncing”Field kinds and action decorators. See Models and fields, Ownership and references, and Virtual maps.
// ── @syncing — stage-3 accessors only; @syncing("Name") required every hierarchy level; names unique ──@syncing("Name")class Model extends PlexusModel<Parent> { @syncing accessor title: string; // val: primitive or model reference; undefined → null @syncing.list accessor items: Item[]; // Array; reassignment diffs in place @syncing.set accessor tags: Set<string>; @syncing.record accessor meta: Record<string, string>; @syncing.map accessor scores: Map<User, number>; // structural keys @syncing.child accessor active: Page | null; // owning scalar; one parent; reparent removes from old @syncing.child.list accessor pages: Page[]; // owning Array; children unique @syncing.child.set accessor comps: Set<Comp>; @syncing.child.record accessor configs: Record<string, Config>; @syncing.child.map accessor byId: Map<string, Task>; // values owned, keys not @syncing.virtual((k) => new Slot({ k })) accessor slots: VirtualMap<K, Slot>; // .get(key) materializes; mutations throw; needs doc @syncing.declare<Out, In>() accessor head: Out; // TS variance only; runtime = @syncing // every field decorator also has .declare<Out, In>()
@syncing.action doStuff() {} // one update + undo unit per doc; commit-on-crash @syncing.action({ rollbackIf }) risky() {} // matching throw discards the batch}