BaseNative currently exposes a small runtime/server surface and an intentionally constrained
expression model. The goal in `v0.x` is correctness and trust, not arbitrary template execution.
@basenative/* publishes to npmjs.org: the release pipeline
publishes there directly, using OIDC trusted publishing — no registry tokens and no
.npmrc redirect. A plain npm install @basenative/runtime gets the
current release line (2.3.0). The 0.2.x/0.3.x builds are
the old pre-1.0 line, not stale mirrors of current releases.
signal(initialValue)
core
Creates a reactive value. Call the accessor to read (and track); call .set() to
write. Subscribers re-run automatically.
import { signal } from'@basenative/runtime';
const count = signal(0);
// Read the current value (tracks in effects)count(); // → 0// Write a new value
count.set(5);
count.set(count() + 1);
// Read without tracking
count.peek(); // → 6
computed(fn)
core
Derives a new signal from others. Re-evaluates only when its dependencies change.
import { signal, effect } from'@basenative/runtime';
const name = signal('world');
effect(() => {
document.title = `Hello, ${name()}`;
});
name.set('BaseNative');
// document.title is now "Hello, BaseNative"
hydrate(root, context)
dom
Walks a DOM subtree, binding template directives (@if, @for,
@switch) and expression interpolation ({{ }}) to the given context.
Hydration diagnostics are available through optional callbacks.
Control flow lives in native <template> elements. Expressions use a safe
subset that favors property access, function calls, and simple operators over arbitrary
in-template program bodies. The complete directive list, including batch() and
registerDirective(), is in the
@basenative/runtime reference.
@if / @else
directive
Conditionally render content. The expression is re-evaluated reactively.
Bind attributes reactively with : prefix. Attach events with
@ prefix. Interpolate text with {{ }}. For complex event logic, call
a named function from the template instead of embedding control flow in the attribute string.
<!-- Reactive attribute --><img:src="imageUrl()"/><!-- Event handler --><button@click="incrementCount()">
Clicked {{ count() }} times
</button><!-- Text interpolation --><p>Hello, {{ name() }}</p>
Server Rendering
The SSR module evaluates all directives at request time. It can also emit hydratable markers for
diagnostics and future SSR hydration work.
render(html, context, options?)
server
Parses an HTML string containing BaseNative directives and returns resolved HTML. Optional
render diagnostics and hydratable markers are available through the third argument.
This page covers the runtime primitives and server render. Every package has a generated
reference under
docs/api/
in the repository; the ones you will reach for first: