@proto-kit/protocol • Docs
Documentation / @proto-kit/protocol / StateMap
Class: StateMap<KeyType, ValueType>
Map-like wrapper for state
Extends
WithPath<this> &WithStateServiceProvider<this>
Type Parameters
• KeyType
• ValueType
Constructors
new StateMap()
new StateMap<
KeyType,ValueType>(keyType,valueType):StateMap<KeyType,ValueType>
Parameters
• keyType: FlexibleProvablePure<KeyType>
• valueType: FlexibleProvablePure<ValueType>
Returns
StateMap<KeyType, ValueType>
Overrides
Mixin( WithPath, WithStateServiceProvider ).constructor
Defined in
packages/protocol/src/state/StateMap.ts:30
Properties
keyType
keyType:
FlexibleProvablePure<KeyType>
Defined in
packages/protocol/src/state/StateMap.ts:31
path?
optionalpath:Field
Inherited from
Mixin( WithPath, WithStateServiceProvider ).path
Defined in
packages/protocol/src/state/State.ts:15
stateServiceProvider?
optionalstateServiceProvider:StateServiceProvider
Inherited from
Mixin( WithPath, WithStateServiceProvider ).stateServiceProvider
Defined in
packages/protocol/src/state/State.ts:27
valueType
valueType:
FlexibleProvablePure<ValueType>
Defined in
packages/protocol/src/state/StateMap.ts:32
Methods
get()
get(
key):Promise<Option<ValueType>>
Obtains a value for the provided key in the current state map.
Parameters
• key: KeyType
Key to obtain the state for
Returns
Promise<Option<ValueType>>
Value for the provided key.
Defined in
packages/protocol/src/state/StateMap.ts:48
getPath()
getPath(
key):Field
Parameters
• key: KeyType
Returns
Field
Defined in
packages/protocol/src/state/StateMap.ts:37
hasPathOrFail()
hasPathOrFail():
asserts this is Object
Returns
asserts this is Object
Inherited from
Mixin( WithPath, WithStateServiceProvider ).hasPathOrFail
Defined in
packages/protocol/src/state/State.ts:17
hasStateServiceOrFail()
hasStateServiceOrFail():
asserts this is Object
Returns
asserts this is Object
Inherited from
Mixin( WithPath, WithStateServiceProvider ).hasStateServiceOrFail
Defined in
packages/protocol/src/state/State.ts:29
set()
set(
key,value):Promise<void>
Sets a value for the given key in the current state map.
Parameters
• key: KeyType
Key to store the value under
• value: ValueType
Value to be stored under the given key
Returns
Promise<void>
Defined in
packages/protocol/src/state/StateMap.ts:64
from()
staticfrom<KeyType,ValueType>(keyType,valueType):StateMap<KeyType,ValueType>
Create a new state map with the given key and value types
Type Parameters
• KeyType
• ValueType
Parameters
• keyType: FlexibleProvablePure<KeyType>
Type to be used as a key
• valueType: FlexibleProvablePure<ValueType>
Type to be stored as a value
Returns
StateMap<KeyType, ValueType>
State map with provided key and value types.