vasille-jsx
Version:
The same framework which is designed to build bulletproof frontends (JSX components)
42 lines (41 loc) • 1.1 kB
JavaScript
import { Fragment, App, reportError, Reactive } from "vasille";
export function view(renderer) {
return function (props, node, slot) {
const { callback } = props;
if (!node) {
throw new Error("Vasille: Component context is missing");
}
const frag = new Fragment(node.runner);
if (slot) {
props.slot = slot;
}
node.create(frag);
try {
const result = renderer(frag, props);
if (result !== undefined && result !== null && callback) {
callback(result);
}
}
catch (e) {
reportError(e);
}
};
}
export function store(fn) {
return fn(new Reactive());
}
export function model(fn) {
return (o, parent) => {
const ctx = new Reactive();
parent?.bind(ctx);
return fn(ctx, o);
};
}
export function mount(tag, view, runner, $) {
const root = new App(tag, runner);
const frag = new Fragment(runner);
root.create(frag, function () {
view($, frag);
});
return root;
}