Scenario: userProxy.profile.email = '...' in the UI.
- Accessing
profilereturns theprofilecontroller proxy (a Valtio proxy for aY.Map). This proxy is the object you use; it performs the controller behavior under the hood. - The Valtio subscription on the object proxy receives a top-level
setoperation foremail. - The operation is enqueued into the coordinator's write scheduler.
- On the next microtask, the scheduler flushes all pending operations in a single
doc.transact(..., VALTIO_Y_ORIGIN). - Inside the transaction,
yProfileMap.set('email', '...')is called (or convert complex values using converter utilities if needed). - The transaction ends.
yRoot.observeDeepcallback fires, but the handler ignores it becausetransaction.origin === VALTIO_Y_ORIGIN.doc.on('update')may fire via the provider and propagate to peers.
Note: When assigning a plain object/array into a controller proxy, the system eagerly upgrades it to a Y type during planning. After the scheduler's transaction completes and the Y type is fully integrated, post-transaction callbacks replace the plain value with a live controller proxy under a reconciliation lock. This ensures the controller is created only after the Y value exists and keeps nested edits encapsulated within the child controller proxy, avoiding parent-level routing.
Scenario: A peer inserts a new item into a shared list (a Y.Array).
- The provider applies the update:
Y.applyUpdate(doc, update). yRoot.observeDeepcallback fires with events and a transaction object.- The synchronizer checks
transaction.origin !== VALTIO_Y_ORIGIN(to ignore our own changes) and processes the events. - For each event, it walks up to find the nearest materialized ancestor (boundary).
- Two-phase reconciliation:
- Phase 1: Reconcile boundaries to ensure structure and materialize controller proxies for new Y types.
- Phase 2: Apply granular array deltas (if available) for efficient updates.
- For arrays, the reconciler either applies the delta or performs a full structural reconcile (building new content with controller proxies).
- The Valtio proxy is updated under a reconciliation lock (to prevent reflection back to Yjs).
- Valtio detects the changes; components using
useSnapshotof that proxy re-render.