Spark transformer that expands animated state fields into phase tracking state and calculations.
When a state field has animated: true or animated: [options], this transformer:
- Adds a
{field}_phaseephemeral state field (string, default "idle") - Adds a
{field}_visiblecalculation: phase != "idle" - Adds a
{field}_animatingcalculation: phase in ["entering", "exiting"] - If
async: :async_fieldoption is set, adds{field}_async_readycalculation
Phase State Machine
The phases are:
"idle"- closed/hidden state"entering"- animation in progress"loading"- waiting for async data (only when async option set)"visible"- fully open/visible"exiting"- close animation in progress
Options
async: :field_name- coordinate with async data loadingpreserve_dom: true- keep DOM alive during exit animationduration: 200- fallback timeout in ms
Example
state :product_id, :any, animated: [async: :product, preserve_dom: true]Expands to:
state :product_id, :any
state :product_id_phase, :string, from: :ephemeral, default: "idle"
calculate :product_id_visible, rx(@product_id_phase != "idle")
calculate :product_id_animating, rx(@product_id_phase == "entering" or @product_id_phase == "exiting")
calculate :product_id_async_ready, rx(@product_id_phase == "visible" or @product != nil)
Summary
Functions
Callback implementation for Spark.Dsl.Transformer.after?/1.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.
Transform the DSL state by expanding animated state fields.
Functions
Callback implementation for Spark.Dsl.Transformer.after?/1.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0.
Callback implementation for Spark.Dsl.Transformer.before?/1.
Transform the DSL state by expanding animated state fields.