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

Copy Markdown 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.

Sets a value in the state.

Updates state using a function.

Types

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

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_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