Raxol.Animation.StateServer (Raxol v2.0.1)

View Source

GenServer implementation for animation state management in Raxol.

This server provides a pure functional approach to animation state management, eliminating Process dictionary usage and implementing proper OTP patterns.

Features

  • Centralized animation settings management
  • Animation definition storage and retrieval
  • Active animation instance tracking
  • Supervised state management with fault tolerance
  • Concurrent-safe operations

State Structure

The server maintains state with the following structure:

%{
  settings: map(),
  animations: %{animation_name => animation_definition},
  active_animations: %{element_id => %{animation_name => instance}}
}

Performance Considerations

This implementation uses ETS for read-heavy operations when performance is critical, while maintaining GenServer for write operations and state consistency.

Summary

Functions

Batch updates multiple active animations at once for performance.

Returns a specification to start this module under a supervisor.

Clears all animation state (used primarily for testing or reset).

Retrieves a specific active animation instance for a given element and animation name.

Retrieves all active animations. Returns a map of {element_id, %{animation_name => instance}}.

Retrieves all animation definitions.

Retrieves an animation definition by name.

Retrieves the animation framework settings.

Gets the current state (for debugging/testing).

Initializes the animation state storage with the given settings.

Stores an active animation instance for a given element.

Stores an animation definition.

Removes a completed or stopped animation instance for a specific element.

Removes all active animations for a specific element.

Updates the animation framework settings.

Functions

batch_update_active_animations(server \\ __MODULE__, updates)

Batch updates multiple active animations at once for performance.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_all(server \\ __MODULE__)

Clears all animation state (used primarily for testing or reset).

get_active_animation(server \\ __MODULE__, element_id, animation_name)

Retrieves a specific active animation instance for a given element and animation name.

get_active_animations(server \\ __MODULE__)

Retrieves all active animations. Returns a map of {element_id, %{animation_name => instance}}.

get_all_animations(server \\ __MODULE__)

Retrieves all animation definitions.

get_animation(server \\ __MODULE__, animation_name)

Retrieves an animation definition by name.

get_settings(server \\ __MODULE__)

Retrieves the animation framework settings.

get_state(server \\ __MODULE__)

Gets the current state (for debugging/testing).

handle_manager_cast(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_cast/2.

handle_manager_info(msg, state)

Callback implementation for Raxol.Core.Behaviours.BaseManager.handle_manager_info/2.

init_state(server \\ __MODULE__, settings)

Initializes the animation state storage with the given settings.

put_active_animation(server \\ __MODULE__, element_id, animation_name, instance)

Stores an active animation instance for a given element.

put_animation(server \\ __MODULE__, animation)

Stores an animation definition.

remove_active_animation(server \\ __MODULE__, element_id, animation_name)

Removes a completed or stopped animation instance for a specific element.

remove_element_animations(server \\ __MODULE__, element_id)

Removes all active animations for a specific element.

start_link(init_opts \\ [])

update_settings(server \\ __MODULE__, settings)

Updates the animation framework settings.