@aihu/reactive
v0.2.2
Published
Fine-grained Proxy-backed deep reactive trees on aihu signals — lazy per-(object,key) tracking nodes, plain-assignment writes, mutate/reconcile.
Readme
@aihu/reactive
Aihu — agentic discovery and interaction, for human purpose.
Fine-grained Proxy-backed deep reactive trees on aihu signals — lazy per-(object,key) tracking nodes, plain-assignment writes, mutate/reconcile.
Design: docs/plans/2026-07-24-deep-reactivity.md.
A Solid-shaped node model (lazily allocated per-(object, key) tracking cells,
allocated on first proxy touch — tracked or not) with Vue-shaped write
ergonomics (plain obj.key = value assignment, no setStore(...) path
tuples). Built entirely on the public @aihu/signals API — @aihu/signals
is external, so this package adds zero bytes to the signals core row.
import { isReactive, reactive, mutate, unwrap } from '@aihu/reactive'
import { computed, effect } from '@aihu/signals'
const user = reactive({ name: 'Ada', address: { city: 'London' }, tags: ['math'] })
effect(() => console.log(user.address.city)) // tracks node(user,'address') + node(addr,'city')
user.address.city = 'Cambridge' // one flush → logs
mutate(user, (u) => {
// ONE flush for three writes
u.name = 'Ada L.'
u.address.city = 'Bletchley'
u.tags.push('crypto')
})
const initials = computed(() => user.name.split(' ').map((s) => s[0]).join(''))
// initials does NOT recompute when address.city changes.
localStorage.setItem('user', JSON.stringify(unwrap(user)))
isReactive(user) // true
isReactive(unwrap(user)) // false — the raw object is not a proxyreconcile(target, next, { key? }) merges a fresh payload (e.g. a hydration
snapshot or a refetch) into target in place — unchanged nested values keep
their proxy identity and notify nobody; only genuinely-changed paths flush.
key controls array-item matching (default: index; pass a property name or a
function for keyed reordering, e.g. { key: 'id' }).
@aihu/reactive/helpers bridges the tree ↔ tuple worlds: toSignal/
toSignals lens reactive properties as Signal tuples, toReactive goes the
other way (a Signal<object> viewed as a reactive-looking object),
reactivePick/reactiveOmit are read-through views (no copies), and
reactiveComputed(fn) keeps a reactive object in sync with fn() via an
effect + reconcile — consumers reading one key only re-run when THAT key's
value actually changes.
Non-wrappable values pass through unchanged: Date, Map, Set,
RegExp, class instances, DOM nodes, and frozen objects are stored raw and
are replace-only — reactive() does not attempt to make them deeply
reactive (see the design doc §8.8/§8.9 for the reasoning).
Nothing shipped elsewhere changes: signal/computed/effect, and every
composable in @aihu/use, keep their existing contracts verbatim. This is a
purely additive new import, not new behavior on an old one.
Install
npm install @aihu/reactive
# or
bun add @aihu/reactiveAuto-generated against @aihu/[email protected].
Package facts
| | |
|---|---|
| Version | 0.2.2 |
| Tier | G — State — fine-grained Proxy-backed deep reactive trees (lazy per-key nodes, plain-assignment writes) |
| Bundle size | 1.28 kB (gz) — limit 1900 B |
| Published files | 3 entries |
| License | MIT |
Auto-generated against @aihu/[email protected].
Exports
| Subpath | ESM | CJS |
|---|---|---|
| . | ./dist/index.js | — |
| ./helpers | ./dist/helpers.js | — |
Auto-generated against @aihu/[email protected].
Dependencies
Dependencies:
@aihu/signals—^0.5.2
Auto-generated against @aihu/[email protected].
See also
Auto-generated against @aihu/[email protected].
License
MIT — see LICENSE.
Auto-generated against @aihu/[email protected].
