SharedStateCollectionView¶
-
class
narupatools.state.view.collection_view.SharedStateCollectionView(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str, snapshot_type: Optional[Type[narupatools.state.serializable_object.SerializableObject]] = None)¶ View on a collection of items in a shared state with a given prefix.
Inheritance

Methods
Create a reference to a collection of items with a given prefix.
Insert a value into the shared state with an autogenerated key.
Remove all keys in this dictionary.
Get the current value, and apply changes after it is modified.
Insert a value into the shared state dictionary with the given key.
Return a snapshot of each of the current items in this collection.
Create a view of a set of keys with values of the specified type.
Create a view of a set of keys that does not assume any specific type.
Update a value by adding the provided key-value pairs.
-
__init__(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str, snapshot_type: Optional[Type[narupatools.state.serializable_object.SerializableObject]] = None)¶ Create a reference to a collection of items with a given prefix.
- Parameters
view – A view of the shared state dictionary that handles getting, updating and removing keys
prefix – The prefix that keys must have to be considered in this collection. For example, a prefix of ‘selection.’ matches all keys of the form ‘selection.*’
snapshot_type – The class that snapshots of its in this collection should implement
-
add(snapshot: Optional[TValue] = None, /, **kwargs: Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]) → narupatools.state.view.reference.SharedStateReference[TValue]¶ Insert a value into the shared state with an autogenerated key.
-
get(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
items() → a set-like object providing a view on D’s items¶
-
keys() → a set-like object providing a view on D’s keys¶
-
modify(key: str, /) → Generator[TValue, None, None]¶ Get the current value, and apply changes after it is modified.
-
set(key: str, snapshot: Optional[TValue] = None, /, **kwargs: Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]) → narupatools.state.view.reference.SharedStateReference[TValue]¶ Insert a value into the shared state dictionary with the given key.
This returns a reference to the item that was inserted into the shared state.
- Parameters
key – Key to modify.
snapshot – Value to set.
kwargs – Arbitrary key-value pairs to set on the value.
- Raises
ValueError – Can only use kwargs if this is a typed view.
-
classmethod
typed_collection(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str, snapshot_class: Type[TSpecificType]) → narupatools.state.view.collection_view.SharedStateCollectionView[TSpecificType]¶ Create a view of a set of keys with values of the specified type.
-
classmethod
untyped_collection(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str) → narupatools.state.view.collection_view.SharedStateCollectionView[Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]]¶ Create a view of a set of keys that does not assume any specific type.
-
update(key: str, /, **kwargs: Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]) → narupatools.state.view.reference.SharedStateReference[TValue]¶ Update a value by adding the provided key-value pairs.
This only works if the value supports keyword assignment.
- Parameters
key – Key to modify.
kwargs – Values to add to the value.
-
values() → an object providing a view on D’s values¶
-