const mixinafEfanXtra::EfanLibrary
afEfanXtra::EfanLibrary
A library of efan components for a specific Pod
.
Libraries are created dynamically at runtime, and each one is injected into every efan component. They give templates an easy means to render other components.
Libraries are created / defined by contributing to EfanLibraries
in your AppModule
. As a library represents all components in a specific pod
, you contribute the pod
with a given name.
Example, here the pod afPies
is contributed with the name pies
:
using afIoc using afEfanExtra class AppModule { @Contribute { serviceType=EfanLibraries# } static Void contributeEfanLibs(Configuration config) { config["pies"] = Pod.find("afPies") } }
If the pod afPies
defines a component named CreamPie
:
const mixin CreamPie : EfanComponent { @InitRender Void initRender(Str x, Int y) { ... } }
Then the pies
library would dynamically define the method:
Str renderCreamPie(Str x, Int y, |->|? bodyFunc := null) { ... }
Every library is injected into every efan component as a field. The field has the same name as the library contribution. This means that any component can render a creamPie
in it's template with the efan code:
<% pies.renderCreamPie("jam", 7) %>
This makes it very easy to nest / render components inside other components.
Libraries are a great way to group / namespace components in pods and distribute them as 3rd Party libraries.