@frondruntime/sorus-core
v0.3.1
Published
Sorus's glitch-free reactive graph, with no runtime dependencies.
Maintainers
Readme
@frondruntime/sorus-core
The reactive graph under Sorus, a glitch-free reactive state library for applications. It emphasizes:
- Glitch-free by construction. A write pushes marks; a read pulls and validates. A derived value checks its sources' versions, in read order, before it recomputes, so no reader sees a half-applied write.
- No runtime dependencies. The graph imports nothing, so it can be ported.
- A small surface. Cells, derived values, atoms, watchers, and reactions, with reads and writes as plain functions.
An application installs @frondruntime/sorus, not this package: the graph
has no realm, no Realm.update, and no models, collections, views, or
stages. This package is for code that builds on the graph itself;
@frondruntime/sorus builds its boxes on it, and
@frondruntime/sorus-react its hooks. Sorus is before 1.0: any release may
change the API. It was called Pinna through 0.2.1.
Packages
| Package | Purpose |
| --- | --- |
| @frondruntime/sorus | The main package: realms, boxes, computed values, atoms, keyed collections, models, views, stages, atomic updates, and watchers. No Effect. |
| @frondruntime/sorus-react | React hooks: useValue, useValues, useSelect. React 19 or later. |
| @frondruntime/sorus-effect | Opt-in, for an application already on Effect: boxes that check an Effect Schema on every write, models decoded from the wire, and Effect programs that react to state. effect 4.1 or a later 4.x. |
| @frondruntime/sorus-core | The raw reactive graph (cells, derived values, atoms, watchers, reactions) with no runtime dependencies, for code that builds on the graph itself. |
Quick start
| Package manager | Command |
| --- | --- |
| Bun | bun add @frondruntime/sorus-core |
| npm | npm install @frondruntime/sorus-core |
| pnpm | pnpm add @frondruntime/sorus-core |
| Yarn | yarn add @frondruntime/sorus-core |
import { Graph, readCell, readDerived, writeCell } from "@frondruntime/sorus-core";
const graph = new Graph();
const $count = graph.cell(1);
const $double = graph.derived(() => readCell($count) * 2);
const seen: Array<number> = [];
const stop = graph.watch(
() => readDerived($double),
(value) => {
seen.push(value);
},
);
writeCell($count, 2); // seen is [4]
stop();Exports
| Kind | Exports |
| --- | --- |
| Classes | Graph, Reaction, Capture |
| Reads and writes | readCell, readDerived, readAtom, peekCell, peekDerived, writeCell, setCell, restoreCell, touchSource |
| Memory | forgetValue, heldValue |
| Inspection | dependenciesOf, sourcesOf, observersOf, observerCount, lastReason, hasRun, kindOf, computeOf, isAtom, isDerived |
| Errors | SorusError, SorusUsageError, isSorusError, sorusErrorKey, reportUncaught |
| Places | nextPlace, placeKindOf, and the place* words: where a read or a write runs, for @frondruntime/sorus and @frondruntime/sorus-react |
| Types | AtomNode, CellNode, DerivedNode, Node, NodeKind, PlaceKind, Source, Equals, and the error types |
