zerolith
Import from zerolith. Generated from the source; every signature below is what the published types declare.
Functions
onDiagnostic
function onDiagnostic(listener: DiagnosticListener): () => voidSubscribes to warnings, deprecations, and info diagnostics. Returns an unsubscribe function.
Source: packages/zerolith/src/diagnostics.ts:174
batch
function batch<T>(fn: () => T): TApplies several writes and runs the affected effects once, after fn returns.
Source: packages/zerolith/src/signals.ts:850
computed
function computed<T>(fn: () => T, options?: SignalOptions<T>): ReadableSignal<T>Creates a lazily evaluated, memoized value derived from other signals. The function must not write signals.
Source: packages/zerolith/src/signals.ts:805
effect
function effect(fn: EffectFunction): () => voidRuns fn now and again whenever a signal it read changes. A returned
function is called before the next run and on dispose. Returns the
dispose function; the effect is also disposed with its enclosing effect
or scope.
Source: packages/zerolith/src/signals.ts:818
onDispose
function onDispose(fn: () => void): voidRegisters fn to run when the enclosing effect re-runs or is disposed, or when the enclosing scope is disposed.
Source: packages/zerolith/src/signals.ts:963
scope
function scope<T>(fn: () => T): Scope<T>Runs fn untracked as the owner of every effect and scope created inside
it, so they can be disposed together.
Source: packages/zerolith/src/signals.ts:940
signal
function signal<T>(initial: T, options?: SignalOptions<T>): Signal<T>Creates a writable signal.
Source: packages/zerolith/src/signals.ts:780
untracked
function untracked<T>(fn: () => T): TRuns fn without subscribing the running computed value or effect to the signals it reads.
Source: packages/zerolith/src/signals.ts:868
resource
function resource<P, T>(options: ResourceOptions<P, T>): Resource<T>Creates a resource owned by the current effect or scope. The resource is
a read-only signal of its value, so it binds in a template and drives
when and each like any other signal, with its request state beside it.
Source: packages/zerolith/src/resource.ts:48
each
function each<T>(items: ReadableSignal<readonly T[]> | readonly T[], key: KeyOf<T>, row: RowOf<T>): ViewRenders one row per item, keyed, updating rows in place when their key survives and moving the fewest nodes when the order changes. The row function receives the item as a signal and, when it declares a second parameter, the position as a signal.
Source: packages/zerolith/src/render.ts:1670
html
function html(strings: TemplateStringsArray, ...values: unknown[]): ViewDescribes markup with live bindings. Values are bound as content or inside attribute values.
Source: packages/zerolith/src/render.ts:157
hydrate
function hydrate(view: unknown, target: MountTarget): HydrateResultAttaches a view to markup the server rendered into target, an element
or a selector for one, with renderToString, reusing the nodes and
binding signals, listeners, properties, and refs. Any disagreement is
repaired on the client and returned in mismatches. Without
server-rendered markup it falls back to render. As with render, a
function that returns the view is called inside the root's owner.
Source: packages/zerolith/src/render.ts:1103
render
function render(view: unknown, target: MountTarget): RootRenders a view at the end of target, an element or a selector for one,
and returns a handle to dispose it. Given a function that returns the
view, as in render(() => App(), "#app"), it calls the function inside
the root's owner, so effects and onDispose cleanups the component
registers belong to the root and end with dispose().
Source: packages/zerolith/src/render.ts:1059
unsafeHtml
function unsafeHtml(markup: string): ViewMarks a string as markup to insert without escaping. This is the one way to put HTML you already trust into a view, for example content rendered from Markdown you wrote. Never pass user input.
Source: packages/zerolith/src/render.ts:121
when
function when(condition: unknown, then: () => unknown, otherwise?: () => unknown): ViewRenders then() while the condition is truthy and otherwise() while
it is not. The condition is a signal, such as a computed value, or a
plain value; a function fails with when_condition_function, since it
would always count as true. Branches are created lazily and disposed
when hidden.
Source: packages/zerolith/src/render.ts:1775
css
function css(strings: TemplateStringsArray, ...values: ReadonlyArray<number | Styles>): StylesDeclares scoped component styles. Values may be numbers or other css
results; strings are rejected so untrusted text can never become CSS.
Source: packages/zerolith/src/css.ts:100
isProblem
function isProblem(value: unknown): value is ProblemTrue for an object that carries at least one problem details member with the right type.
Source: packages/zerolith/src/problem.ts:32
Classes
ZerolithError
class ZerolithError extends ErrorAn error thrown by zerolith. The diagnostic carries the machine-readable detail.
constructor(record: Diagnostic): Builds the message from the record's code, cause, fix, and URL, leaving out a cause or fix that is empty, as both are in production builds.readonly diagnostic: Diagnostic: The record the error was built from, for tools that read its code and arguments as data instead of parsing the message.
Source: packages/zerolith/src/diagnostics.ts:145
Interfaces
Diagnostic
interface DiagnosticA diagnostic as emitted by any part of zerolith.
code: string: Stable snake_case identifier, for examplesignal_written_inside_computed. Codes are public API; message text is not.severity: DiagnosticSeverity: The diagnostic's weight; the runtime throws anerroras aZerolithErrorand passes every other severity to theonDiagnosticlisteners.cause: string: One sentence naming what happened. Empty in production builds.fix: string: One sentence naming what to do about it. Empty in production builds.url: string: Documentation page for the code, with the arguments encoded in the query string.location?: DiagnosticLocation: Where the diagnostic points, when the emitter knows: a position in the source or a node in the page.suggestion?: DiagnosticSuggestion: A change that would resolve the diagnostic, when the emitter can name one.args?: DiagnosticArgs: The values the diagnostic is about, such as the name of a refused attribute, kept apart so a tool can word its own text;urlcarries them in its query string.
Source: packages/zerolith/src/diagnostics.ts:50
DiagnosticLocation
interface DiagnosticLocationWhere a diagnostic points. Source positions are 1-based; selector locates a DOM node at runtime.
file?: string: The source file the diagnostic points into.line?: number: The 1-based line withinfile.column?: number: The 1-based column withinline.selector?: string: A CSS selector that finds the node in the page the diagnostic is about, for a diagnostic raised at runtime.
Source: packages/zerolith/src/diagnostics.ts:23
DiagnosticSuggestion
interface DiagnosticSuggestionA concrete change that would resolve the diagnostic.
description: string: One sentence describing the change.replacement?: string: The replacement source text, when the change is textual.applicability: Applicability: Whether a tool may make the change unreviewed:machine_applicablesays it may, whilemaybe_incorrectandhas_placeholdersneed a person to check or complete it.
Source: packages/zerolith/src/diagnostics.ts:36
DiagnosticText
interface DiagnosticTextThe text of one catalog entry.
cause: string: One sentence naming what happened, used as the diagnostic'scauseand on the code's documentation page.fix: string: One sentence naming what to do about it, used as the diagnostic'sfixand on the code's documentation page.
Source: packages/zerolith/src/diagnostics.ts:71
ReadableSignal
interface ReadableSignal<T>A value that can be read and tracked.
get(): T: Returns the current value and subscribes the running computed value or effect to it.
Source: packages/zerolith/src/signals.ts:40
Scope
interface Scope<T>The result of scope().
readonly value: T: The value the scope function returned.dispose(): void: Disposes every effect and nested scope created inside, in reverse order of creation.
Source: packages/zerolith/src/signals.ts:57
Signal
interface Signal<T> extends ReadableSignal<T>A value that can be read, tracked, and written.
set(value: T): void: Stores a new value and queues the effects that depend on it. Writes are not allowed inside computed functions.
Source: packages/zerolith/src/signals.ts:47
SignalOptions
interface SignalOptions<T>Options accepted by signal() and computed().
equals?: Equals<T>: Defaults toObject.is.name?: string: A label for the dev tools;zerolith devand the Vite plugin also keep a named signal's value across an edit.
Source: packages/zerolith/src/signals.ts:31
LoaderContext
interface LoaderContext<P>What the loader receives.
params: P: The valueparamsreturned; never undefined, because undefined skips loading.abort: AbortSignal: Aborted when the params change, on reload, and when the owning scope is disposed.
Source: packages/zerolith/src/resource.ts:11
Resource
interface Resource<T> extends ReadableSignal<T | undefined>An async value and its request state.
readonly status: ReadableSignal<ResourceStatus>: The latest request's state:idlewhileparamsreturnsundefined,pendingwhile the loader runs, thenresolvedorerror.readonly pending: ReadableSignal<boolean>: True while a request is in flight.readonly error: ReadableSignal<unknown>: The rejection of the latest request, or undefined.get(): T | undefined: The last resolved value; kept while a newer request is pending.reload(): void: Runs the loader again with the current params.
Source: packages/zerolith/src/resource.ts:29
ResourceOptions
interface ResourceOptions<P, T>What resource() takes: a tracked params function and an untracked loader.
params: () => P | undefined: Tracked: the signals it reads decide when the loader re-runs. Returning undefined puts the resource in the idle state.loader: (context: LoaderContext<P>) => Promise<T>: Untracked: fetches the value for the given params.
Source: packages/zerolith/src/resource.ts:20
HydrateResult
interface HydrateResult extends RootThe handle returned by hydrate().
readonly mismatches: readonly HydrationMismatch[]: Every disagreement found; each one was repaired by rendering on the client.
Source: packages/zerolith/src/render.ts:47
HydrationMismatch
interface HydrationMismatchOne place where the server-rendered markup and the view disagreed.
kind: "text" | "missing" | "extra" | "structure" | "root":text: a text node differed;missing: expected nodes were absent;extra: unexpected nodes were present;structure: a template's nodes did not line up;root: no server-rendered part was found.expected?: string: What was expected, when known.found?: string: What was found, when known.
Source: packages/zerolith/src/render.ts:36
Root
interface RootThe handle returned by render().
readonly container: Element | DocumentFragment: The element or fragment the view was rendered into.dispose(): void: Removes everything rendered and disposes every effect it created.
Source: packages/zerolith/src/render.ts:27
View
interface ViewA description of UI produced by html, each, or when, or by a component function.
readonly VIEW: true: The brand, alwaystrue. The package does not export its symbol key, so aViewcomes only fromhtml,each,when, orunsafeHtml, never from an object literal.
Source: packages/zerolith/src/render.ts:20
Styles
interface StylesA stylesheet produced by css. Bind it to a root element's class attribute.
readonly scope: string: The generated class that selects this component's roots.readonly text: string: The full stylesheet text including the @scope wrapper, for server rendering.toString(): string: The class names to put on a root element: the shared marker plusscope.
Source: packages/zerolith/src/css.ts:15
Problem
interface ProblemAn RFC 9457 problem details document with the fields extension.
type?: string: A URI identifying the problem type;about:blankwhen the status says it all.title?: string: A short human-readable summary.status?: number: The HTTP status code.detail?: string: A human-readable explanation specific to this occurrence.instance?: string: A URI identifying this occurrence.fields?: FieldErrors: Validation messages per field name.
Source: packages/zerolith/src/problem.ts:12
Types
Applicability
type Applicability = "machine_applicable" | "maybe_incorrect" | "has_placeholders" | "unspecified"How safely a suggestion can be applied without a human reading it, following the grades rustc uses for its own suggestions.
Source: packages/zerolith/src/diagnostics.ts:13
DiagnosticArgs
type DiagnosticArgs = Readonly<Record<string, string | number | boolean>>Values interpolated into a diagnostic's text, kept separately so tools can render their own.
Source: packages/zerolith/src/diagnostics.ts:47
DiagnosticCode
type DiagnosticCode = "signal_written_inside_computed" | "computed_cycle" | "effect_cycle" | "effect_loop" | "on_dispose_outside_scope" | "binding_in_tag_position" | "binding_in_comment" | "binding_in_raw_text" | "binding_not_single" | "script_in_template" | "template_unclosed_tag" | "unsafe_property_binding" | "unsafe_attribute_binding" | "unsafe_url_blocked" | "unrenderable_value" | "each_items_function" | "event_handler_not_function" | "when_condition_function" | "mount_component_uncalled" | "each_key_undefined" | "each_key_duplicate" | "css_value_not_allowed" | "ref_not_assignable" | "hydration_mismatch" | "jsx_not_lowered" | "template_frozen_read" | "image_without_alt" | "button_without_name" | "frame_without_title" | "mount_target_missing" | "template_not_prepared" | "lazy_module_not_split" | "package_version_mismatch"The codes the runtime can emit. Every code has exactly one catalog entry.
Source: packages/zerolith/src/diagnostics.ts:83
DiagnosticListener
type DiagnosticListener = (diagnostic: Diagnostic) => voidReceives every non-throwing diagnostic the runtime reports.
Source: packages/zerolith/src/diagnostics.ts:169
DiagnosticSeverity
type DiagnosticSeverity = "error" | "warning" | "deprecation" | "info"The weight of a diagnostic. Deprecations are their own class so tooling can count them separately.
Source: packages/zerolith/src/diagnostics.ts:20
EffectFunction
type EffectFunction = () => void | (() => void)The function run by effect(); it may return a cleanup function.
Source: packages/zerolith/src/signals.ts:54
Equals
type Equals<T> = (previous: T, next: T) => booleanDecides whether a new value counts as a change.
Source: packages/zerolith/src/signals.ts:28
ResourceStatus
type ResourceStatus = "idle" | "pending" | "resolved" | "error"The lifecycle of a resource's current request.
Source: packages/zerolith/src/resource.ts:8
KeyOf
type KeyOf<T> = (item: T, index: number) => string | number | bigint | boolean | symbol | objectThe key function for each().
Source: packages/zerolith/src/render.ts:1173
MountTarget
type MountTarget = Element | DocumentFragment | stringWhere a view mounts: an element or fragment, or a CSS selector for one element in the document.
Source: packages/zerolith/src/render.ts:1013
RowOf
type RowOf<T> = (item: ReadableSignal<T>, index: ReadableSignal<number>) => unknownThe row renderer for each(). The item is a signal that updates in place; the index is a signal too, created only when the function declares a second parameter.
Source: packages/zerolith/src/render.ts:1176
FieldErrors
type FieldErrors = Readonly<Record<string, readonly string[]>>Messages per field name, the fields extension member of a problem.
Source: packages/zerolith/src/problem.ts:9
Constants
DIAGNOSTIC_URL
const DIAGNOSTIC_URL: stringBase of every diagnostic URL; the code is appended as the path.
Source: packages/zerolith/src/diagnostics.ts:80
diagnosticCatalog
const diagnosticCatalog: Readonly<Partial<Record<DiagnosticCode, DiagnosticText>>>The message text for every diagnostic code. The documentation pages for
the codes are generated from this table, so an entry here is the single
source of truth for both the message and the docs. Production builds
ship an empty catalog, so look entries up with ?..
Source: packages/zerolith/src/catalog.ts:10
PROBLEM_MEDIA_TYPE
const PROBLEM_MEDIA_TYPE: stringThe media type of a problem details document.
Source: packages/zerolith/src/problem.ts:29