Base
provide.foundation.state.base
¶
TODO: Add module docstring.
Classes¶
ImmutableState
¶
Base class for immutable state objects.
All state in Foundation should inherit from this to ensure immutability and provide consistent state management.
Functions¶
with_changes
¶
Create a new state instance with the specified changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**changes
|
Any
|
Field updates to apply |
{}
|
Returns:
| Type | Description |
|---|---|
ImmutableState
|
New state instance with updated generation |
Source code in provide/foundation/state/base.py
StateMachine
¶
Bases: Generic[StateT, EventT], ABC
Abstract base class for state machines.
Provides thread-safe state transitions with guards and actions.
Source code in provide/foundation/state/base.py
Attributes¶
state_history
property
¶
Get the state transition history.
Functions¶
add_transition
¶
Add a state transition to the machine.
reset
abstractmethod
¶
transition
¶
Attempt to transition to a new state based on the event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
EventT
|
Event that triggers the transition |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if transition was successful, False otherwise |
Source code in provide/foundation/state/base.py
StateManager
¶
Thread-safe manager for immutable state objects.
Provides atomic updates and version tracking for state objects.
Attributes¶
Functions¶
add_observer
¶
Add a state change observer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observer
|
Callable[[ImmutableState, ImmutableState], None]
|
Function called with (old_state, new_state) on changes |
required |
Source code in provide/foundation/state/base.py
remove_observer
¶
Remove a state change observer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
observer
|
Callable[[ImmutableState, ImmutableState], None]
|
Observer function to remove |
required |
Source code in provide/foundation/state/base.py
replace_state
¶
Replace the entire state object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_state
|
ImmutableState
|
New state to set |
required |
Source code in provide/foundation/state/base.py
update_state
¶
Atomically update the state with the given changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**changes
|
Any
|
Field updates to apply |
{}
|
Returns:
| Type | Description |
|---|---|
ImmutableState
|
New state instance |