Signals — Mapanare

Reactive primitives with automatic dependency tracking and change propagation.

Overview

Signals hold a value and automatically propagate changes to dependents. They enable declarative, reactive dataflow without manual event wiring — no React, no RxJS, no state management library. Reactivity is a language feature.

Declaration

let mut count = signal(0)
let doubled = computed { count * 2 }
count.set(5)
print(doubled)  // 10

Dependency Tracking

The compiler tracks which signals are read during computed signal evaluation. When any dependency changes, the computed signal recomputes.

Change Streams

Every signal exposes a stream of its changes, bridging reactive and streaming models:

for change in temperature.changes() {
    print("Temperature changed to ${change}")
}

Batched Updates

batch {
    x.set(10)
    y.set(20)
    z.set(30)
}
// Dependents recompute once, not three times

Signals in Agents

Agents can expose signals as part of their interface.