Skip to main content

StateMap Interface

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

This API is provided as a beta preview and may change without notice.

To use, import via @fluidframework/presence/beta.

For more information about our API support guarantees, see here.

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 | number, V>

Type Parameters

ParameterConstraintDescription
Kstring | number
V

Properties

PropertyAlertsModifiersTypeDescription
sizeBetareadonlynumberThe number of elements in the StateMap.

Methods

MethodAlertsReturn TypeDescription
clear()Betavoid$delete(key)s all elements in the StateMap.
delete(key)BetabooleanRemoves the element with the specified key from the StateMap, if it exists.
forEach(callbackfn, thisArg)BetavoidExecutes a provided function once per each key/value pair in the StateMap, in arbitrary order.
get(key)BetaDeepReadonly<JsonDeserialized<V>> | undefinedReturns the element with the specified key from the StateMap, if it exists.
has(key)BetabooleanChecks if an element with the specified key exists in the StateMap.
keys()BetaIterableIterator<K>Returns an iterable of keys in the map.
set(key, value)BetathisAdds 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.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature

readonly size: number;

Type: number

Method Details

clear

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

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

Signature

clear(): void;

Remarks

This is not yet implemented.

delete

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

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

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.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

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.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

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.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

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.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

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.

This API is provided as a beta preview and may change without notice.

For more information about our API support guarantees, see here.

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