Regor API
Find the API by purpose, try it live, and inspect the code behind its behavior.
This section contains the function-level reference for Regor.
Use this page as an index, then open each API page for signature details and examples.
Start with an app and writable state. Then choose the APIs for derivation, observation, composition, and cleanup.
Try it live
Three read-only values, three ways to specify their dependencies.
import { computed, computeMany, computeRef, html, ref } from 'regor'
export function createDerived(interactive = false) {
const seats = ref(4)
const price = ref(25)
return {
interactive,
seats,
price,
total: computed(() => seats() * price()),
double: computeRef(seats, (value) => value * 2),
combined: computeMany([seats, price], (count, cost) => count + cost),
}
}
export const derivedTemplate = html` <div class="guide-demo">
<div class="guide-filter">
<label
>Seats · {{ seats }}<input
type="range"
min="1"
max="12"
r-model.number="seats"
:value="seats"
:disabled="!interactive" /></label
><label
>Price · {{ price }}<input
type="range"
min="10"
max="50"
step="5"
r-model.number="price"
:value="price"
:disabled="!interactive"
/></label>
</div>
<div class="guide-metrics">
<div>
<output class="api-derived-total">{{ total }}</output
><span>computed · seats × price</span>
</div>
<div><output>{{ double }}</output><span>computeRef · seats × 2</span></div>
<div>
<output>{{ combined }}</output><span>computeMany · seats + price</span>
</div>
</div>
<p class="guide-hint">
Three read-only values, three ways to specify their dependencies.
</p>
</div>` import { createApp, RegorConfig, useScope } from 'regor'
import { apiExamples } from './examples'
const element = document.getElementById('api-demo')
const name = element?.dataset.example
if (element && name && Object.hasOwn(apiExamples, name)) {
const example = apiExamples[name as keyof typeof apiExamples]
const scope = useScope<object>(() => example.create(true))
const config =
'config' in scope.context && scope.context.config instanceof RegorConfig
? scope.context.config
: undefined
createApp(scope, { element, template: example.template }, config)
} Move either slider. The three read-only outputs use computed, computeRef, and computeMany.
App and Components
createApp
Mount a context on existing DOM or supply a template for a reactive island.
Explore createAppdefineComponent
Define a reusable template with a context factory, props, and slots.
Explore defineComponenttoJsonTemplate
Convert DOM elements into JSON templates for inspection or later rendering.
Explore toJsonTemplateRegorConfig
Configure an app’s directives, global context, interpolation, and validation policy.
Explore regorConfigReactivity
ref
Create writable state and recursively convert nested object and array fields to refs.
Explore refentangle
Link two writable refs in both directions and return a function to disconnect them.
Explore entangleComputed and Effects
watchEffect
Run an effect immediately, then rerun it when the refs it reads change.
Explore watchEffectcollectRefs
Run an action and return both its result and the refs collected during its reads.
Explore collectRefsObservation and Batch
observeMany
Subscribe to multiple refs and receive their current values in one callback.
Explore observeManyLifecycle and Scope
ContextRegistry
Register context instances and resolve them by their runtime class.
Explore contextRegistryCleanup and Unbind
Utilities
Logging
warningHandler
Customize Regor’s warning handling and retain a way to restore the previous handler.
Explore warningHandlerRecommendation
Start with: