Vuer

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

python
class GraphStore

Source

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

python
def __init__(self, session_id: str, on_send: Optional[SendCallback]=None, on_state_change: Optional[StateChangeCallback]=None, initial_snapshot: Optional[Snapshot]=None)

Source

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

python
def get_state(self) -> ClientState

Source

Get the current client state.

GraphStore.graph

python
def graph(self) -> SceneGraph

Source

Get the current scene graph.

GraphStore.session_id

python
def session_id(self) -> str

Source

Get the session ID.

GraphStore.subscribe

python
def subscribe(self, callback: StateChangeCallback) -> Callable[[], None]

Source

Subscribe to state changes.

Args: callback: Function called with new state on each change

Returns: Unsubscribe function

GraphStore.edit

python
def edit(self, op: Operation) -> None

Source

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

python
def edit_batch(self, ops: List[Operation]) -> None

Source

Add multiple uncommitted operations to the edit buffer.

Args: ops: List of operations to add

GraphStore.cancel_edits

python
def cancel_edits(self) -> None

Source

Cancel all uncommitted edits and revert to the starting state.

GraphStore.has_pending_edits

python
def has_pending_edits(self) -> bool

Source

Check if there are uncommitted edits.

GraphStore.commit

python
def commit(self, description: Optional[str]=None) -> Optional[CRDTMessage]

Source

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

python
def receive(self, msg: CRDTMessage) -> None

Source

Process a message received from the server or another client.

Args: msg: The received message

GraphStore.ack

python
def ack(self, msg_id: str) -> None

Source

Mark a message as acknowledged by the server.

Args: msg_id: ID of the message to acknowledge

GraphStore.get_unacked_messages

python
def get_unacked_messages(self) -> List[CRDTMessage]

Source

Get all unacknowledged messages (for resending on reconnect).

GraphStore.has_pending_messages

python
def has_pending_messages(self) -> bool

Source

Check if there are unacknowledged messages.

GraphStore.get_pending_count

python
def get_pending_count(self) -> int

Source

Get count of unacknowledged messages.

GraphStore.undo

python
def undo(self) -> Optional[CRDTMessage]

Source

Undo the last operation from this session.

Returns: The undo message to send, or None if nothing to undo

GraphStore.redo

python
def redo(self) -> Optional[CRDTMessage]

Source

Redo the last undone operation from this session.

Returns: The redo message to send, or None if nothing to redo

GraphStore.compact

python
def compact(self) -> Snapshot

Source

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

python
def get_snapshot(self) -> Snapshot

Source

Get the current snapshot.

GraphStore.init_from_server

python
def init_from_server(self, snapshot: Snapshot, journal: List[CRDTMessage]) -> None

Source

Initialize state from server-provided snapshot and journal.

Args: snapshot: The server's snapshot journal: Journal entries to replay (as messages)

create_graph

python
def create_graph(session_id: Optional[str]=None, on_send: Optional[SendCallback]=None, on_state_change: Optional[StateChangeCallback]=None, initial_snapshot: Optional[Snapshot]=None) -> GraphStore

Source

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.