Skip to content
Mercury

Hypergraph

Hypergraph, the state kernel

A scheduler and graph executor that runs a model's wiring to quiescence, glitch-free and batched, with fork scopes, effects and one observation surface.

Hypergraph is Mercury's state kernel: the package @fiberfx/hypergraph, version 4.0.0, with no dependencies. A model is a graph of units, and Hypergraph runs it.

What Hypergraph is

Hypergraph is a scheduler and graph executor. It runs a model's wiring to quiescence, glitch-free and batched, with fork scopes, effects and one observation surface. Three things set it apart:

The names

import { event, store } from "@fiberfx/hypergraph";

const increment = event<number>();
export const $count = store(0, { name: "$count" }).on(increment, (count, by) => count + by);

Subpaths

Two more subpaths are planned and not exported yet: /hyperscript, the bindings for Mercury Hyperscript (useUnit, Provider), and /hmr, hot replacement.

How an edit behaves under mx dev

Once mx dev delivers the swap, a saved edit to a model swaps its graph instead of reloading the page. An edit that changes only the bodies of functions is swapped in place, so the scope, its values and any effect in flight stay as they are. Any other edit loads a new generation of the graph, carries over every store whose sid and shape both match, and then retires the old generation with its watchers.

Every store that does not carry over is named, with a reason:

A store that only the new graph declares is new: it starts from its initial value and nothing was lost, so it is reported as information, not as a reset.

What is shipped

The kernel, its API and the swap are built inside @fiberfx/hypergraph. Version 4.0.0 is not published to a registry yet. mx dev does not deliver the swap yet: that is the next step, and until then an edit to a model reloads the page.