Raxol.Animation.StateManager (Raxol v2.0.1)
View SourceRefactored StateManager that delegates to GenServer implementation.
This module provides the same API as the original Animation.StateManager but uses a supervised GenServer instead of the Process dictionary for state management.
Migration Notice
This module is a drop-in replacement for Raxol.Animation.StateManager.
All functions maintain backward compatibility while providing improved
fault tolerance and functional programming patterns.
Benefits over Process Dictionary
- Supervised state management with fault tolerance
- Pure functional transformations
- Better debugging and testing capabilities
- Clear separation of concerns
- No global state pollution
- Support for batch operations for better performance
Summary
Functions
Batch updates multiple active animations at once.
Clears all animation state (used primarily for testing or reset).
Gets the count of active animations across all elements.
Ensures the Animation StateServer is started. Called automatically when using any function.
Retrieves a specific active animation instance for a given element and animation name.
Retrieves all active animations.
Retrieves an animation definition by name.
Gets all animations for a specific element.
Retrieves the animation framework settings.
Checks if an element has any active animations.
Initializes the animation state storage.
Lists all element IDs that have active animations.
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 animations for a specific element.
Functions
Batch updates multiple active animations at once.
This is more efficient than multiple individual calls when updating many animations in a single frame.
Parameters
updates: A list of update operations, each being either:{:put, element_id, animation_name, instance}to add/update an animation{:remove, element_id, animation_name}to remove an animation
Example
StateManager.batch_update_active_animations([
{:put, "elem1", "fade", %{opacity: 0.5}},
{:put, "elem2", "slide", %{x: 100}},
{:remove, "elem3", "rotate"}
])
Clears all animation state (used primarily for testing or reset).
WARNING: This will remove all animation definitions and active animations. Use with caution in production environments.
Gets the count of active animations across all elements.
Ensures the Animation StateServer is started. Called automatically when using any function.
Retrieves a specific active animation instance for a given element and animation name.
Returns nil if no matching animation is found.
Retrieves all active animations.
Returns a map of {element_id, %{animation_name => instance}}.
Retrieves an animation definition by name.
Returns nil if no animation with the given name exists.
Gets all animations for a specific element.
Returns a map of animation_name => instance for the given element, or an empty map if the element has no active animations.
Retrieves the animation framework settings.
Returns the current animation settings from the GenServer state.
Checks if an element has any active animations.
Initializes the animation state storage.
This function provides backward compatibility with the original StateManager. It delegates to the GenServer implementation.
Lists all element IDs that have active animations.
Stores an active animation instance for a given element.
Parameters
element_id: The ID of the element being animatedanimation_name: The name of the animationinstance: The animation instance data
Stores an animation definition.
The animation must have a name field which will be used as the key.
Removes a completed or stopped animation instance for a specific element.
This is typically called when an animation completes or is cancelled.
Removes all animations for a specific element.
This is useful when an element is being destroyed or reset.