Raxol.Core.Behaviours.StateManager behaviour (Raxol v2.0.1)
View SourceBehaviour for state management systems.
Defines the callbacks that state manager implementations must provide for managing application and component state.
Summary
Callbacks
Cleans up state management resources.
Removes a key from the state.
Gets a value from the state.
Initializes state management system.
Initializes plugin-specific state.
Sets a value in the state.
Updates plugin state (legacy interface).
Updates state using a function.
Types
Callbacks
@callback cleanup(state()) :: :ok
Cleans up state management resources.
Parameters
- state: Current state
Returns
- :ok on successful cleanup
Removes a key from the state.
Parameters
- state: Current state
- key: Key to remove
Returns
{:ok, new_state}on success
@callback get_state(state(), state_key()) :: {:ok, state_value()} | {:error, :not_found}
Gets a value from the state.
Parameters
- state: Current state
- key: Key to retrieve
Returns
{:ok, value}if key exists{:error, :not_found}if key doesn't exist
Initializes state management system.
Returns
{:ok, initial_state}on success{:error, reason}on failure
@callback initialize_plugin_state(plugin_module(), plugin_config()) :: {:ok, state()} | {:error, term()}
Initializes plugin-specific state.
Parameters
- plugin_module: The plugin module
- config: Plugin configuration
Returns
{:ok, initial_plugin_state}on success{:error, reason}on failure
@callback set_state(state(), state_key(), state_value()) :: {:ok, state()} | {:error, term()}
Sets a value in the state.
Parameters
- state: Current state
- key: Key to set
- value: Value to set
Returns
{:ok, new_state}on success{:error, reason}on failure
@callback update_plugin_state_legacy(plugin_id(), state(), plugin_config()) :: {:ok, state()} | {:error, term()}
Updates plugin state (legacy interface).
Parameters
- plugin_id: Plugin identifier
- state: Plugin state
- config: Plugin configuration
Returns
{:ok, updated_state}on success{:error, reason}on failure
@callback update_state(state(), state_key(), (state_value() -> state_value())) :: {:ok, state()} | {:error, term()}
Updates state using a function.
Parameters
- state: Current state
- key: Key to update
- update_fn: Function to apply to the current value
Returns
{:ok, new_state}on success{:error, reason}on failure