Skip to main content

serverOnly()

function serverOnly\<T\>(options: ObservableOptions\<T\>): WritableObservable\<T\>;

Defined in: src/lib/observable/serverOnly.ts:48

Create a server-only observable.

This observable exists only on the server and is not synchronized to clients. Other server-side modules can subscribe to value changes.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
optionsObservableOptions<T>Configuration options

Returns

WritableObservable<T>

A writable observable (server-only)

Example

// Server-side module
const serverConfig = serverOnly({
    id: "my-module:serverConfig",
    initialValue: { maxPlayers: 32, debug: false },
});
 
// Subscribe to changes
serverConfig.subscribe((config, prev) => {
    console.log("Config changed:", config);
});
 
// Update value
serverConfig.update(cfg => ({ ...cfg, debug: true }));