Aurora.Uix.ComponentsResolverHelper (Aurora UIX v0.1.5-rc.1)

Copy Markdown

Runtime helpers and the resolve_component_for/1 macro that power the Aurora UIX component override system.

How it works

Each overridable component in a module that uses Aurora.Uix.ComponentsResolver has:

  1. Default implementation clauses — matched on host_components: nil in assigns:

    def my_component(%{host_components: nil} = assigns), do: ...
  2. A public dispatch function — generated by resolve_component_for/1, placed after the default clauses. This is the entry point called by templates:

    resolve_component_for(:my_component)

The generated dispatch function checks Application.get_env(:aurora_uix, override_key) at call time. If an override module is configured and exports the function, the call is forwarded to that module. Otherwise, host_components: nil is injected into assigns and the default implementation clauses are called.

Partial overrides

Override modules only need to export the specific functions they want to replace. function_exported?/3 ensures missing functions fall back to the default implementation automatically.

host_components assign

The host_components assign is used as a sentinel. Without it, assigns will never match the host_components: nil default clauses, so every call enters the dispatch function first. The dispatch function then injects host_components: nil before delegating to the default implementation, ensuring correct clause dispatch even for multi-clause components (e.g., input with type: "checkbox", type: "select", etc.).

Summary

Functions

Checks for a configured override module and whether it exports the specified function. Returns the override module if valid, or nil to indicate the default implementation should be used.

Macro to generate a dispatch function for a component that checks for an override module at runtime. The generated function will

Functions

host_components(function, components_override)

@spec host_components(atom(), atom()) :: module() | nil

Checks for a configured override module and whether it exports the specified function. Returns the override module if valid, or nil to indicate the default implementation should be used.

Parameters

  • function (atom): The name of the component function to resolve.
  • components_override (atom): The application environment key for the override module.

Returns

  • module() if a valid override module is configured and exports the function, otherwise nil.

resolve_component_for(function)

(macro)

Macro to generate a dispatch function for a component that checks for an override module at runtime. The generated function will:

  1. Check for an override module configured under the specified application environment key.
  2. If an override module is found and exports the function, delegate the call to that module.
  3. If no valid override is found, inject host_components: nil into assigns and call the default implementation.

Parameters

  • function (atom): The name of the component function to generate.