clientOwned()
function clientOwned\<T\>(options: SyncedObservableOptions\<T\>): ClientOwnedObservable\<T\>;Defined in: src/lib/observable/clientOwned.ts:72
Create a client-owned observable.
On client: Returns a writable observable that syncs to server. On server: Returns a view that stores per-player values (read-only). On web: Returns a stub (web uses the React integration layer).
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
options | SyncedObservableOptions<T> | Configuration options |
Returns
Client-owned observable
Example
// In a service or module
const playerInput = clientOwned({
id: "player:input",
initialValue: { x: 0, y: 0, action: null },
});
// Client-side: modify the state
playerInput.set({ x: 1, y: 0, action: "move" });
// Server-side: read player's value
const playerValue = playerInput.getPlayerValue(playerId);
playerInput.subscribeToPlayer(playerId, (input) => {
console.log("Player input changed:", input);
});