Business rules in the model
Events describe what happened. Stores hold state. Effects run external work. Reactions connect behavior.
Describe application rules outside the UI and run the same model wherever it is needed.
import { event, reaction, store } from "@virentia/core";
export function createCounterModel() {
const incremented = event<void>();
const count = store(0);
reaction({
on: incremented,
run() {
count.value += 1;
},
});
return { count, incremented };
}import { component } from "@virentia/react";
import { createCounterModel } from "./model";
export const Counter = component({
model: createCounterModel,
view({ model }) {
const increment = () => model.incremented();
return <button onClick={increment}>{model.count}</button>;
},
});