StateBag
Defined in: client/api.d.ts:5494
Arbitrary key/value state attached to one replicated entity, reached as entity.state. Keys set on the server replicate to every client that can currently see the entity.
Methods
Section titled “Methods”get(
key):any
Defined in: client/api.d.ts:5502
Reads one key from this entity’s state.
Parameters
Section titled “Parameters”string
Key to read.
Returns
Section titled “Returns”any
The stored value, or undefined when the key is not set.
has(
key):boolean
Defined in: client/api.d.ts:5509
Checks whether this entity’s state holds a key.
Parameters
Section titled “Parameters”string
Key to test.
Returns
Section titled “Returns”boolean
True when the key is set.
keys()
Section titled “keys()”keys():
string[]
Defined in: client/api.d.ts:5515
Lists the keys this entity’s state holds, sorted.
Returns
Section titled “Returns”string[]
Every key currently set, in ascending order.
onChange()
Section titled “onChange()”onChange(
key,handler):Function
Defined in: client/api.d.ts:5529
Watches this entity’s state. The filter is applied before the handler runs, so a listener watching one key of one entity is not woken by unrelated changes. The subscription is dropped when the registering resource stops.
Parameters
Section titled “Parameters”string | null
Only report this key, or null to report every key of this entity.
handler
Section titled “handler”Function
Called as (key: string, value: any, previous: any) with the changed key, its new value and the value before it. value is undefined when the key was removed and previous is undefined when it held nothing.
Returns
Section titled “Returns”Function
A zero-argument function that cancels this subscription.
toObject()
Section titled “toObject()”toObject():
Record<string,any>
Defined in: client/api.d.ts:5521
Copies this entity’s whole state into a plain object.
Returns
Section titled “Returns”Record<string, any>
Every key and value currently set. The copy does not track later changes.