Raxol.Core.Behaviours.StateManager behaviour (Raxol v2.0.1)

View Source

Behaviour 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

plugin_config()

@type plugin_config() :: map()

plugin_id()

@type plugin_id() :: String.t()

plugin_module()

@type plugin_module() :: module()

state()

@type state() :: term()

state_key()

@type state_key() :: term()

state_value()

@type state_value() :: term()

Callbacks

cleanup(state)

@callback cleanup(state()) :: :ok

Cleans up state management resources.

Parameters

  • state: Current state

Returns

  • :ok on successful cleanup

delete_state(state, state_key)

@callback delete_state(state(), state_key()) :: {:ok, state()}

Removes a key from the state.

Parameters

  • state: Current state
  • key: Key to remove

Returns

  • {:ok, new_state} on success

get_state(state, state_key)

@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

init()

@callback init() :: {:ok, state()} | {:error, term()}

Initializes state management system.

Returns

  • {:ok, initial_state} on success
  • {:error, reason} on failure

initialize_plugin_state(plugin_module, plugin_config)

@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

set_state(state, state_key, state_value)

@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

update_plugin_state_legacy(plugin_id, state, plugin_config)

@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

update_state(state, state_key, function)

@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