vuer.rtc.store
GraphStore - High-level API for managing CRDT-based scene graph state.
This module provides the main interface for working with the data store, matching the TypeScript createGraph() API.
Usage: from vuer.rtc import create_graph
store = create_graph( session_id="my-session", on_send=lambda msg: websocket.send(msg.to_dict()), )
Edit operations (buffered)
store.edit(Operation(key="cube", otype="vector3.add", path="position", value=[1, 0, 0]))
Commit edits as a message
msg = store.commit()
Receive remote messages
store.receive(incoming_message)
Undo/redo
store.undo() store.redo()
Get current state
state = store.get_state() graph = state.graph
GraphStore
Main store for managing CRDT-based scene graph state.
This class provides the high-level API for working with the data store:
- edit(): Add uncommitted operations
- commit(): Commit edits as a message
- receive(): Process received messages from server
- ack(): Mark message as acknowledged
- undo()/redo(): Undo/redo operations
- compact(): Create snapshot from acknowledged entries
- get_state(): Get current state
- subscribe(): Subscribe to state changes
GraphStore.init
Create a new GraphStore.
Args: session_id: Unique identifier for this session on_send: Callback invoked when a message should be sent to server on_state_change: Callback invoked when state changes initial_snapshot: Optional snapshot to restore from
GraphStore.get_state
Get the current client state.
GraphStore.graph
Get the current scene graph.
GraphStore.session_id
Get the session ID.
GraphStore.subscribe
Subscribe to state changes.
Args: callback: Function called with new state on each change
Returns: Unsubscribe function
GraphStore.edit
Add an uncommitted operation to the edit buffer.
Operations are buffered and not immediately applied. Call commit() to apply them and create a message.
Args: op: The operation to add
GraphStore.edit_batch
Add multiple uncommitted operations to the edit buffer.
Args: ops: List of operations to add
GraphStore.cancel_edits
Cancel all uncommitted edits and revert to the starting state.
GraphStore.has_pending_edits
Check if there are uncommitted edits.
GraphStore.commit
Commit current edits as a CRDT message.
Args: description: Optional description for the commit
Returns: The committed message, or None if no edits to commit
GraphStore.receive
Process a message received from the server or another client.
Args: msg: The received message
GraphStore.ack
Mark a message as acknowledged by the server.
Args: msg_id: ID of the message to acknowledge
GraphStore.get_unacked_messages
Get all unacknowledged messages (for resending on reconnect).
GraphStore.has_pending_messages
Check if there are unacknowledged messages.
GraphStore.get_pending_count
Get count of unacknowledged messages.
GraphStore.undo
Undo the last operation from this session.
Returns: The undo message to send, or None if nothing to undo
GraphStore.redo
Redo the last undone operation from this session.
Returns: The redo message to send, or None if nothing to redo
GraphStore.compact
Create a snapshot from all acknowledged entries.
This compacts the journal by baking acknowledged entries into the snapshot, reducing memory usage and speeding up replay.
Returns: The new snapshot
GraphStore.get_snapshot
Get the current snapshot.
GraphStore.init_from_server
Initialize state from server-provided snapshot and journal.
Args: snapshot: The server's snapshot journal: Journal entries to replay (as messages)
create_graph
Factory function to create a GraphStore.
This matches the TypeScript createGraph() API.
Args: session_id: Unique session identifier (auto-generated if not provided) on_send: Callback when message should be sent to server on_state_change: Callback when state changes initial_snapshot: Optional snapshot to restore from
Returns: A new GraphStore instance
Public imports
These symbols are available from this module. Their definitions are documented in the linked modules.
ClientState—vuer.rtc.types.ClientStateCRDTMessage—vuer.rtc.types.CRDTMessageEditBuffer—vuer.rtc.types.EditBufferJournalEntry—vuer.rtc.types.JournalEntryOperation—vuer.rtc.types.OperationSceneGraph—vuer.rtc.types.SceneGraphSnapshot—vuer.rtc.types.SnapshotOType—vuer.rtc.types.OTypecreate_empty_graph—vuer.rtc.types.create_empty_graphcreate_initial_snapshot—vuer.rtc.types.create_initial_snapshotcreate_initial_state—vuer.rtc.types.create_initial_stategenerate_message_id—vuer.rtc.types.generate_message_idincrement_clock—vuer.rtc.types.increment_clockmerge_clocks—vuer.rtc.types.merge_clocksapply_message_mut—vuer.rtc.operations.dispatcher.apply_message_mutapply_operation—vuer.rtc.operations.dispatcher.apply_operationOperationMeta—vuer.rtc.operations.dispatcher.OperationMetarebuild_graph—vuer.rtc.operations.dispatcher.rebuild_graph