Share via


StatePropertyAccessor interface

Interface for accessing a property in state storage with type safety.

The interface defines standard methods for working with persisted state properties, allowing property access with strong typing to reduce errors when working with complex state objects.

Methods

delete(TurnContext)

Deletes the persisted property from its backing storage object.

get(TurnContext)

Reads a persisted property from its backing storage object.

get(TurnContext, T)

Reads a persisted property from its backing storage object.

set(TurnContext, T)

Assigns a new value to the properties backing storage object.

Method Details

delete(TurnContext)

Deletes the persisted property from its backing storage object.

function delete(context: TurnContext): Promise<void>

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

Returns

Promise<void>

Remarks

The properties backing storage object SHOULD be loaded into memory on first access.

await myProperty.delete(context);

get(TurnContext)

Reads a persisted property from its backing storage object.

function get(context: TurnContext): Promise<undefined | T>

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

Returns

Promise<undefined | T>

Remarks

The properties backing storage object SHOULD be loaded into memory on first access.

If the property does not currently exist on the storage object and a defaultValue has been specified, a clone of the defaultValue SHOULD be copied to the storage object. If a defaultValue has not been specified then a value of undefined SHOULD be returned.

const value = await myProperty.get(context, { count: 0 });

get(TurnContext, T)

Reads a persisted property from its backing storage object.

function get(context: TurnContext, defaultValue: T): Promise<T>

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

defaultValue

T

(Optional) default value to copy to the backing storage object if the property isn't found.

Returns

Promise<T>

set(TurnContext, T)

Assigns a new value to the properties backing storage object.

function set(context: TurnContext, value: T): Promise<void>

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

value

T

Value to assign.

Returns

Promise<void>

Remarks

The properties backing storage object SHOULD be loaded into memory on first access.

Depending on the state systems implementation, an additional step may be required to persist the actual changes to disk.

await myProperty.set(context, value);