@hile/reactivity
Compose Hile micro topics, dynamic config, and runtime reloader state as refs with explicit async watch strategies.Choose This Package When
Use When
Use@hile/reactivity when Hile service code needs to compose micro topics, dynamic config, or runtime reloader state as refs instead of manual callback chains.
Do Not Use When
- Do not use it to replace
@hile/micro; it adaptspublish()andsubscribe()but does not change RPC or pub/sub semantics. - Do not use it to replace
@hile/reloader; usereactiveReloader()when callers need refs forcurrent,state, anderror. - Do not use it as an event log. Refs model current state; use a queue for durable event processing.
- Do not use
watchLatestfor side effects that must all run. UsewatchQueuefor every-event handling. - Do not rely on AbortSignal to kill non-cooperative async work. It prevents stale writes only when handlers respect the signal or check
isCurrent().
Install
Imports
Copy-Paste Example
Reactive config topics feeding a reloadable runtime:More Examples
Subscribe to one topic as a readonly ref:Runtime And Lifecycle Notes
topicRef()subscribes once, stores the latest payload in a readonly ref, marksreadyafter the first payload, and unsubscribes onstop().publishRef()publishes the initial ref value, then watches later changes with serial latest-wins updates.stop()drops pending values that have not started, waits for the activepublisher.update()to settle, then callspublisher.unpublish().reactiveConfig()usescreateConfigAggregator()internally, so required keys, defaults, debounce, signatures, and listener error semantics stay aligned with@hile/reloader.reactiveConfig().stop()attempts every subscribed cleanup before reporting unsubscribe failures. Failed cleanup remains retryable, andonErrorcan receivestage: 'unsubscribe'.reactiveReloader()wrapscreateRuntimeReloader()and exposes readonly refs forcurrent,state, anderror.watchLatest()aborts stale work and reports errors only for the latest non-aborted run.watchSerialLatest()never runs handlers concurrently and collapses pending changes to the latest value.watchQueue()never runs handlers concurrently and processes every observed value in order.@vue/reactivityis a peer dependency. Import refs and watch helpers from@hile/reactivity, or ensure the application resolves a single physical copy of@vue/reactivity.- Register every returned
stop()with Hile shutdown.
Anti-Patterns
- Starting async work inside a raw
watch()without choosing latest-wins, serial latest-wins, or queue semantics. - Updating a micro topic directly from multiple uncoordinated watchers.
- Creating refs from a second physical copy of
@vue/reactivity; cross-instance refs can be recognized as refs but not tracked by this package’s watchers. - Passing large mutable objects through deep reactive proxies. Prefer
shallowReffor Hile runtime/config snapshots. - Forgetting to stop topic subscriptions or publisher bindings during service shutdown.
Verification Checklist
- Unit-test async watcher behavior with overlapping updates.
- Verify
topicRef().stop()unsubscribes and later topic pushes do not mutate the ref. - Verify
publishRef()skips superseded pending values and callsunpublish()on stop. - Verify
reactiveConfig()does not emit until required topics are present. - Verify
reactiveConfig()preserves subscribe failures even when best-effort cleanup also fails, and that failed stop cleanup can be retried. - Verify
reactiveReloader()preserves@hile/reloaderfailure behavior and exposes current runtime after successful update.
Related Recipes
Stable Runtime Reload
Complete Example
Runtime Dynamic Config
Complete Example
Package-Local AI Guide
This package also shipsAI.md in npm so agents can read accurate examples after installation.