Noizu.Tessera.Component.LitCodegen (Noizu.Tessera v0.2.0)

Copy Markdown View Source

SPIKE (spike/elixir-to-lit): emits the Lit element module for a spec that declared state / template ~TSR / action (docs/notes/spike-elixir-to-lit.md §codegen).

Output (colocated with the component's .ex):

  • <tag>.element.generated.mjs — a LitElement subclass mixed with TesseraElement (CONTRACT.md §4): reactive properties from state + attrs + props (with Lit property options — attribute rename/disable, reflect, typed converters incl. Array for :list), a render() built from the template, one method per action (running the JS translated at compile time), one method per declared lifecycle hook (shouldUpdate/willUpdate/firstUpdated/updated), emit routed through @noizu/tessera-core's emit (so the data-tsr-on Hologram bridge keeps working), and an exported register().
  • <snake>.mjs — the :js entry wrapper (register(); top-level — load-bearing for Hologram page bundles, CONTRACT.md §5). Written only when it does not exist, so a hand-written element .mjs is never clobbered.

Deterministic: same spec in, same bytes out (golden fixtures pin it).

Summary

Functions

The <tag>.element.generated.mjs text for a template-bearing spec.

Path of the generated element module under dir. Takeover layers are keyed by the BASE tag like their merged specs — the stem carries the declaring module so sibling layers don't clobber each other's artifacts (§5.8/§5.9).

The generated :js entry wrapper for Hologram hosts (top-level register(), CONTRACT.md §5).

Write-if-changed element_module/1 (returns :written | :unchanged | {:error, reason}).

Write the wrapper only when it does not exist (a hand-written element .mjs is never clobbered). Returns :written | :exists | {:error, reason}.

Functions

element_module(spec)

@spec element_module(Noizu.Tessera.Spec.t()) :: String.t()

The <tag>.element.generated.mjs text for a template-bearing spec.

element_path(spec, dir)

@spec element_path(Noizu.Tessera.Spec.t(), String.t()) :: String.t()

Path of the generated element module under dir. Takeover layers are keyed by the BASE tag like their merged specs — the stem carries the declaring module so sibling layers don't clobber each other's artifacts (§5.8/§5.9).

wrapper_module(spec)

@spec wrapper_module(Noizu.Tessera.Spec.t()) :: String.t()

The generated :js entry wrapper for Hologram hosts (top-level register(), CONTRACT.md §5).

write_element_module(spec, dir)

@spec write_element_module(Noizu.Tessera.Spec.t(), String.t()) ::
  :written | :unchanged | {:error, term()}

Write-if-changed element_module/1 (returns :written | :unchanged | {:error, reason}).

write_wrapper_module(spec, dir)

@spec write_wrapper_module(Noizu.Tessera.Spec.t(), String.t()) ::
  :written | :exists | {:error, term()}

Write the wrapper only when it does not exist (a hand-written element .mjs is never clobbered). Returns :written | :exists | {:error, reason}.