@gluonjs/core


@gluonjs/core / src / defineAtom

Function: defineAtom()

defineAtom<Props>(render, displayName?, styles?): Component<Props>

Adds immutable layer: 'atom' and displayName metadata to a stateless render function. It does not add lifecycle, registration, styling, prop validation, accessibility semantics, state ownership, or cleanup.

Type Parameters

Props

Props

Parameters

render

(props) => TemplateResult

displayName?

string

styles?

readonly ComponentStyleDependency[]

Returns

Component<Props>

Example

Label a small reusable rendering function as an Atom while preserving its exact typed props:

ts
import {
  defineAtom,
  defineMolecule,
  defineOrganism,
  html,
  type Component,
} from '@gluonjs/core';

const Price: Component<{ amount: number }> = defineAtom(
  ({ amount }) => html`<data value=${amount}>€${amount}</data>`,
  'Price',
);
const ProductCard = defineMolecule(
  ({ name, price }: { name: string; price: number }) =>
    html`<article><h2>${name}</h2>${Price({ amount: price })}</article>`,
  'ProductCard',
);
const Catalog = defineOrganism(
  ({ products }: { products: readonly { name: string; price: number }[] }) =>
    html`<main>${products.map(ProductCard)}</main>`,
  'Catalog',
);
console.log(Price.layer, ProductCard.layer, Catalog({ products: [] }));