Skip to content

createLume

createLume() creates a new Lume application instance.

function createLume(): LumeApp;

A LumeApp object with the following methods:

Registers a component definition under a name.

app.component("disclosure", disclosure);
ParameterTypeDescription
namestringThe component name (matches data-lume attribute)
definitionComponentDefinitionThe result of defineComponent()

Returns: LumeApp (chainable)


Scans the DOM for [data-lume] elements and initializes matching components.

app.mount();           // Scans entire document
app.mount(container);  // Scans a specific element
ParameterTypeDefaultDescription
rootHTMLElement | DocumentdocumentThe root to scan

Returns: LumeApp (chainable)


Destroys all component instances, running cleanup functions and removing effects.

app.unmount();

Retrieves a component’s public API by its data-lume-id.

const menu = app.get<MenuApi>("main-menu");
if (menu) {
  menu.hide();
}

Returns: T | undefined


Like get(), but throws an error if the component is not found.

const menu = app.require<MenuApi>("main-menu");
menu.hide(); // guaranteed to exist

Returns: T (throws if not found)


Emits a local event within this app.

app.emit("notification", { message: "Saved!" });

Listens to local events within this app.

app.listen("notification", (detail) => {
  console.log(detail.message);
});

Emits a global event shared across all Lume apps.

app.global.emit("theme-changed", { theme: "dark" });

Listens to global events shared across all Lume apps.

app.global.listen("theme-changed", (detail) => {
  document.body.dataset.theme = detail.theme;
});

Applies a plugin to this app.

app.use(myPlugin);
ParameterTypeDescription
pluginPluginA function (app: LumeApp) => void

Returns: LumeApp (chainable)

import { createLume } from "@beardcoder/lume";
import { disclosure } from "./components/disclosure";
import { uiPlugin } from "./plugins/ui";

const app = createLume();

app
  .use(uiPlugin)
  .component("disclosure", disclosure)
  .mount();

// Access component APIs
const menu = app.require<{ toggle(): void }>("main-menu");

// App-level events
app.listen("menu-opened", () => console.log("Menu is open"));