Enumex.Component behaviour (Enumex v1.0.0)
View SourceProvides a generic Domain Specific Language (DSL) for building enum components.
Bindings
A keyword list containing the variables that will be bound during component expansion.
Bindings are different for both Enumex.Dynamic
and Enumex.Static
,
but always includes a component
key with a component module as a value,
which is useful for writing behaviours.
Options
A keyword list that specifies component dependencies and requirements.
A :depends
option specifies the other components that this component relies on.
The :requires
option specifies a keyword list where the key is the app name
and the value is a module, within the specified app, that this component relies on.
[
depends: [OtherComponent],
requires: [my_lib: MyLib.ModuleName]
]
Do block
A block containing the component implementation
defmodule MyApp.MyComponent do
@moduledoc """
A component documentation
"""
use Enumex.Component
@doc """
A callback documentation
"""
@callback my_func :: :ok
comp [component: component_module] do
@behaviour component_module
@impl component_module
def my_func, do: :ok
end
end
Summary
Main
Defines a component.
The type representing a data used in component bindings.
The type representing a component module.
Main
@spec comp( Enumex.macro_input(%{:component => t(), optional(atom()) => Macro.t()}), Enumex.macro_input([option]), keyword(Macro.t()) ) :: Macro.output() when option: {:depends, [t()]} | {:requires, keyword(module())}
Defines a component.
Examples
defmodule DependentComponent do
comp [key: value], depends: [OtherComponent], requires: [my_lib: MyLib.ModuleName] do
# component contents …
end
end
@type comp_binding_data() :: [ {:component, t()} | Enumex.Dynamic.comp_binding_data() | Enumex.Static.comp_binding_data() ]
The type representing a data used in component bindings.
@type t() :: module()
The type representing a component module.