Quick start
Mini Reactive components are functions that create DOM nodes. Read a signal inside a binding and the runtime updates that binding when the value changes.
Loading the example…
View source
import { mount, signal } from "min-reactive-framework";import type { Dispose } from "min-reactive-framework";import { button, div, output, span } from "min-reactive-framework/html";import type { DemoLanguage } from "../example-language.js";
export function run(target: HTMLElement, lang: DemoLanguage): Dispose { const count = signal(0); return mount(target, () => div( { class: "mr-demo-line" }, button( { type: "button", on: { click: () => { count.value++; }, }, }, lang === "ru" ? "Увеличить" : "Increment", ), span(lang === "ru" ? "Счётчик" : "Count"), output({ "aria-live": "polite" }, count), ), );}Get the browser files
Section titled “Get the browser files”The archive contains the ready-made library in dist/ and two pages in examples/plain/. Open classic.html directly from disk, or serve the extracted directory over HTTP and open examples/plain/ for the ESM example.
If you already have a project checkout, pnpm install --frozen-lockfile followed by pnpm build produces the same library files locally.
Create a page of your own
Section titled “Create a page of your own”Place the complete dist/ directory beside index.html. The ESM entry points use shared chunks, so keep their relative paths.
<!doctype html><html lang="en"> <meta charset="utf-8" /> <title>Mini Reactive counter</title> <main id="app"></main> <script type="module" src="./app.js"></script></html>import { mount, signal } from "./dist/index.js";import { button, p, section } from "./dist/html.js";
mount(document.getElementById("app"), () => { const count = signal(0); return section( p("Count ", count), button( { on: { click: () => { count.value++; }, }, }, "Increment", ), );});Serve the folder over HTTP, for example with python3 -m http.server 8000 from that directory.
Use the classic IIFE build for file://. Load the library before the application script and use the MiniReactive global.
<!doctype html><html lang="en"> <meta charset="utf-8" /> <title>Mini Reactive counter</title> <main id="app"></main> <script src="./dist/browser/min-reactive.iife.js"></script> <script> const { mount, signal, html: { button }, } = MiniReactive; mount(document.getElementById("app"), () => { const count = signal(0); return button( { on: { click: () => { count.value++; }, }, }, "Count ", count, ); }); </script></html>To install the package from a checkout, run pnpm pack in the Mini Reactive repository. Then install the resulting archive in your application:
pnpm add /path/to/min-reactive-framework-0.1.0.tgzimport { mount, signal } from "min-reactive-framework";import { button, p, section } from "min-reactive-framework/html";
function Counter({ label }: { label: string }): HTMLElement { const count = signal(0); return section( p(label, " ", count), button( { on: { click: () => { count.value++; }, }, }, "Increment", ), );}
const root = document.querySelector<HTMLElement>("#app");if (!root) throw new Error("Missing #app");mount(root, () => Counter({ label: "Count" }));The package has declarations for the root module, /html, and /svg. Use your app’s TypeScript tooling to compile main.ts. If you prefer to vendor the files, the browser archive also ships .d.ts files next to the ESM modules.
Read the value in the right place
Section titled “Read the value in the right place”With p(count), the text follows the signal. With p(() => count.value * 2), the runtime tracks the signals read by the expression. Passing p(count.value) captures the value during setup. Keep the disposer returned by mount if the application will be removed or replaced.
Continue with signals and effects or components and children.