Skip to main content
Version: v2

StateMap Interface

Map of local client's values. Modifications are transmitted to all other connected clients.

Sealed

This type is "sealed," meaning that code outside of the library defining it should not implement or extend it. Future versions of this type may add members or make typing of readonly members more specific.

Signature​

/** @sealed */
export interface StateMap<K extends string, V>

Type Parameters​

ParameterConstraintDescription
Kstring
V

Properties​

PropertyModifiersTypeDescription
sizereadonlynumberThe number of elements in the StateMap.

Methods​

MethodReturn TypeDescription
clear()void$delete(key)s all elements in the StateMap.
delete(key)booleanRemoves the element with the specified key from the StateMap, if it exists.
forEach(callbackfn, thisArg)voidExecutes a provided function once per each key/value pair in the StateMap, in arbitrary order.
get(key)DeepReadonly<JsonDeserialized<V>> | undefinedReturns the element with the specified key from the StateMap, if it exists.
has(key)booleanChecks if an element with the specified key exists in the StateMap.
keys()IterableIterator<K>Returns an iterable of keys in the map.
set(key, value)thisAdds a new element with a specified key and value to the StateMap. If an element with the same key already exists, the element will be updated. The value will be transmitted to all other connected clients.

Property Details​

size​

The number of elements in the StateMap.

Signature​

readonly size: number;

Type: number

Method Details​

clear​

$delete(key)s all elements in the StateMap.

Signature​

clear(): void;

Remarks​

This is not yet implemented.

delete​

Removes the element with the specified key from the StateMap, if it exists.

Signature​

delete(key: K): boolean;

Remarks​

No entry is fully removed. Instead an undefined placeholder is locally and transmitted to all other clients. For better performance limit the number of deleted entries and reuse keys when possible.

Parameters​

ParameterTypeDescription
keyK

Returns​

true if an element in the StateMap existed and has been removed, or false if the element does not exist.

Return type: boolean

forEach​

Executes a provided function once per each key/value pair in the StateMap, in arbitrary order.

Signature​

forEach(callbackfn: (value: DeepReadonly<JsonDeserialized<V>>, key: K, map: StateMap<K, V>) => void, thisArg?: unknown): void;

Parameters​

ParameterModifiersTypeDescription
callbackfn(value: DeepReadonly<JsonDeserialized<V>>, key: K, map: StateMap<K, V>) => void
thisArgoptionalunknown

get​

Returns the element with the specified key from the StateMap, if it exists.

Signature​

get(key: K): DeepReadonly<JsonDeserialized<V>> | undefined;

Parameters​

ParameterTypeDescription
keyK

Returns​

Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

Return type: DeepReadonly<JsonDeserialized<V>> | undefined

has​

Checks if an element with the specified key exists in the StateMap.

Signature​

has(key: K): boolean;

Parameters​

ParameterTypeDescription
keyK

Returns​

boolean indicating whether an element with the specified key exists or not.

Return type: boolean

keys​

Returns an iterable of keys in the map.

Signature​

keys(): IterableIterator<K>;

Returns​

Return type: IterableIterator<K>

set​

Adds a new element with a specified key and value to the StateMap. If an element with the same key already exists, the element will be updated. The value will be transmitted to all other connected clients.

Signature​

set(key: K, value: JsonSerializable<V>): this;

Remarks​

Manager assumes ownership of the value and its references. Make a deep clone before setting, if needed. No comparison is done to detect changes; all sets are transmitted.

Parameters​

ParameterTypeDescription
keyK
valueJsonSerializable<V>

Returns​

Return type: this