system library

A dependency graph and propagation engine for custom reactive primitives.

Extend ReactiveSystem to supply update, scheduling, and cleanup behavior. Use ReactiveNode and Link to represent the graph. Value storage, active-subscriber tracking, and callback execution belong to your layer.

This manual graph demonstrates linking, notification, and unlinking:

// A manual graph that queues notifications for the caller to process.
class ManualSystem extends ReactiveSystem {
  final pending = <ReactiveNode>[];

  // This graph has no lazily computed values to update.
  @override
  bool update(ReactiveNode node) => false;

  @override
  void notify(ReactiveNode node) => pending.add(node);

  // These nodes own no external resources to release.
  @override
  void unwatched(ReactiveNode node) {}
}
final system = ManualSystem();
final source = ReactiveNode(flags: .mutable);
final watcher = ReactiveNode(flags: .watching);
system.link(source, watcher, 0);

system.propagate(source.subs!);
system.propagate(source.subs!); // Already pending; no duplicate notification.
print(system.pending.length); // 1

// Process the queued work, then make the watcher ready for another change.
for (final node in system.pending) {
  print(node.flags & ReactiveFlags.pending != ReactiveFlags.none); // true
  node.flags = .watching;
}
system.pending.clear();

system.unlink(watcher.deps!, watcher);
print(source.subs == null); // true; the graph is disconnected.

Classes

Represents a dependency relationship between two reactive nodes.
ReactiveNode
Base class for all reactive nodes in the dependency tracking system.
ReactiveSystem
Abstract base class for implementing a reactive system.

Extension Types

ReactiveFlags
Bit flags that represent the state of reactive nodes in the system.