Component Context
The Component Context is the object passed to your factory function in defineComponent. It provides all the tools needed to build reactive components.
Properties & Methods
Section titled “Properties & Methods”The component’s root element (the element with data-lume).
Type: HTMLElement
part(name)
Section titled “part(name)”Finds a single element with data-lume-part="name" inside the root.
Throws if the element is not found.
parts(name)
Section titled “parts(name)”Finds all elements with data-lume-part="name" inside the root.
Returns an empty array if no elements match.
template(name)
Section titled “template(name)”Returns a factory function that clones a <template data-lume-part="name"> element.
Returns: () => DocumentFragment
signal<T>(initial)
Section titled “signal<T>(initial)”Creates a reactive signal with an initial value.
Returns: SignalGetter<T> — a callable object with .set() and .update() methods.
effect(fn)
Section titled “effect(fn)”Runs a function immediately and re-runs it whenever any signal it reads changes.
The function may return a cleanup function:
on(target, event, handler, options?)
Section titled “on(target, event, handler, options?)”Adds an event listener that is automatically removed on unmount.
| Parameter | Type | Description |
|---|---|---|
target | EventTarget | Any event target (element, window, etc.) |
event | string | Event name |
handler | EventListener | Event handler function |
options | AddEventListenerOptions | Optional listener options |
cleanup(fn)
Section titled “cleanup(fn)”Registers a function to be called when the component unmounts.
emit(name, detail?)
Section titled “emit(name, detail?)”Emits a local event within the app.
listen(name, handler)
Section titled “listen(name, handler)”Listens to local app events. Automatically cleaned up on unmount.
global
Section titled “global”Object for global (cross-app) events.