@ecopages/signals
v0.3.0-alpha.25
Published
Renderer-agnostic signal primitives based on the TC39 Signals proposal
Maintainers
Readme
Ecopages Signals
@ecopages/signals is a renderer-agnostic signals package that can be used standalone or underneath Radiant.
Its core model is based on the TC39 Signals proposal, with a smaller surface area and a few convenience helpers for application code today.
The public entrypoint remains index.ts, while the implementation now lives in focused modules under src/ so the core runtime, effects, watcher support, and store logic can evolve independently.
Current Scope
This package currently provides:
State<T>for writable valuesComputed<T>for lazily derived valuescurrentComputed()for advanced derived helpers that need the active computed contexteffect(...)for reactive side effects with scheduled re-executionwatch(...)for observing derived values with previous-value accessuntrack(...)andpeek(...)for non-tracking readssubtle.Watcherpluswatchedandunwatchedhooks for low-level invalidation workflowscreateStore(...)for deep reactive object and array stateisStore(...)for detecting signal-backed store proxiessnapshot(...)for materializing plain nested data- automatic dependency discovery during
Computedevaluation - subscription support for renderer or framework adapters
Source Layout
The package is organized around a stable public barrel and smaller implementation files:
index.tsre-exports the public API and exposessubtlesrc/types.tsdefines the public contracts, options, and low-level symbolssrc/state.tsimplements writableStatesignalssrc/computed.tsimplements lazy derivedComputedsignals and active-computation helperssrc/effect.tsandsrc/watch.tsimplement effect scheduling and derived-value observationsrc/watcher.tsimplements proposal-shaped low-level watcherssrc/tracking.tscontains non-tracking read helperssrc/store.tscontains deep store proxying and snapshot materialization
Design Position
This package is renderer-agnostic.
- It does not know about JSX.
- It does not know about Radiant components.
- It is meant to work both as a standalone package and underneath adapters in those packages.
TC39 Relationship
This package is based on the current TC39 Signals proposal and tracks the same broad model around:
StateandComputedsignal classes- lazy pull-based recomputation with cached values
- automatic dependency discovery during computed evaluation
- custom equality functions for writable and computed signals
- untracked reads as an escape hatch
It is not a drop-in implementation of the current proposal draft.
It is best understood as proposal-aligned in its core semantics, but not yet fully API-compatible with the draft surface.
- It exposes convenience helpers such as
effect(...),watch(...),createStore(...), andsnapshot(...)directly. - It currently exposes manual
subscribe(...)hooks for adapter and library integration. - It exposes a proposal-shaped
subtle.WatcherAPI, while still keeping the existing convenience helpers. - Its
subtle.Watcherfollows the proposal-style re-arm behavior, where callingwatch(...)resets the pending set and notification latch for the next invalidation cycle. - It does not yet expose the full TC39 subtle introspection surface.
API Notes
subscribe(...)is intended for adapter-style push integration. Application-level derived work is usually better expressed withComputed,effect(...), orwatch(...).watch(...)is built on top of a computed signal plus an effect, so it inherits computed equality behavior and effect scheduling.subtle.Watcherreports staleness rather than recalculated values. Callingwatch(...)is both registration and reset.createStore(...)wraps nested plain objects and arrays, whilesnapshot(...)detaches the current plain value graph for logging, serialization, or comparison.
Example
import { Computed, State, createStore, effect, watch } from '@ecopages/signals';
const count = new State(0);
const parity = new Computed(() => ((count.get() & 1) === 0 ? 'even' : 'odd'));
const store = createStore({ profile: { name: 'Ada' } });
const dispose = effect(() => {
console.log(parity.get(), store.profile.name);
});
const stopWatching = watch(
() => store.profile.name,
(nextName, previousName) => {
console.log(previousName, '->', nextName);
},
);
count.set(1);
store.profile.name = 'Grace';
dispose();
stopWatching();Limits
This implementation is still smaller than the current TC39 proposal draft.
- no full TC39
Watcherand subtle semantics surface yet - no full proposal-style subtle introspection helpers yet
- no batching or transaction model
- no framework-owned disposal tree or component ownership integration yet
Those omissions are deliberate. The goal is to keep a small, useful standalone package while leaving room to align further as the proposal evolves.
