@ecopages/signals 0.3.0-alpha.18 → 0.3.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +109 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # Ecopages Signals
2
+
3
+ `@ecopages/signals` is a renderer-agnostic signals package that can be used standalone or underneath Radiant.
4
+
5
+ Its core model is based on the [TC39 Signals proposal](https://github.com/tc39/proposal-signals/tree/main), with a smaller surface area and a few convenience helpers for application code today.
6
+
7
+ 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.
8
+
9
+ ## Current Scope
10
+
11
+ This package currently provides:
12
+
13
+ - `State<T>` for writable values
14
+ - `Computed<T>` for lazily derived values
15
+ - `currentComputed()` for advanced derived helpers that need the active computed context
16
+ - `effect(...)` for reactive side effects with scheduled re-execution
17
+ - `watch(...)` for observing derived values with previous-value access
18
+ - `untrack(...)` and `peek(...)` for non-tracking reads
19
+ - `subtle.Watcher` plus `watched` and `unwatched` hooks for low-level invalidation workflows
20
+ - `createStore(...)` for deep reactive object and array state
21
+ - `isStore(...)` for detecting signal-backed store proxies
22
+ - `snapshot(...)` for materializing plain nested data
23
+ - automatic dependency discovery during `Computed` evaluation
24
+ - subscription support for renderer or framework adapters
25
+
26
+ ## Source Layout
27
+
28
+ The package is organized around a stable public barrel and smaller implementation files:
29
+
30
+ - `index.ts` re-exports the public API and exposes `subtle`
31
+ - `src/types.ts` defines the public contracts, options, and low-level symbols
32
+ - `src/state.ts` implements writable `State` signals
33
+ - `src/computed.ts` implements lazy derived `Computed` signals and active-computation helpers
34
+ - `src/effect.ts` and `src/watch.ts` implement effect scheduling and derived-value observation
35
+ - `src/watcher.ts` implements proposal-shaped low-level watchers
36
+ - `src/tracking.ts` contains non-tracking read helpers
37
+ - `src/store.ts` contains deep store proxying and snapshot materialization
38
+
39
+ ## Design Position
40
+
41
+ This package is renderer-agnostic.
42
+
43
+ - It does not know about JSX.
44
+ - It does not know about Radiant components.
45
+ - It is meant to work both as a standalone package and underneath adapters in those packages.
46
+
47
+ ## TC39 Relationship
48
+
49
+ This package is based on the current TC39 Signals proposal and tracks the same broad model around:
50
+
51
+ - `State` and `Computed` signal classes
52
+ - lazy pull-based recomputation with cached values
53
+ - automatic dependency discovery during computed evaluation
54
+ - custom equality functions for writable and computed signals
55
+ - untracked reads as an escape hatch
56
+
57
+ It is not a drop-in implementation of the current proposal draft.
58
+
59
+ It is best understood as proposal-aligned in its core semantics, but not yet fully API-compatible with the draft surface.
60
+
61
+ - It exposes convenience helpers such as `effect(...)`, `watch(...)`, `createStore(...)`, and `snapshot(...)` directly.
62
+ - It currently exposes manual `subscribe(...)` hooks for adapter and library integration.
63
+ - It exposes a proposal-shaped `subtle.Watcher` API, while still keeping the existing convenience helpers.
64
+ - Its `subtle.Watcher` follows the proposal-style re-arm behavior, where calling `watch(...)` resets the pending set and notification latch for the next invalidation cycle.
65
+ - It does not yet expose the full TC39 subtle introspection surface.
66
+
67
+ ## API Notes
68
+
69
+ - `subscribe(...)` is intended for adapter-style push integration. Application-level derived work is usually better expressed with `Computed`, `effect(...)`, or `watch(...)`.
70
+ - `watch(...)` is built on top of a computed signal plus an effect, so it inherits computed equality behavior and effect scheduling.
71
+ - `subtle.Watcher` reports staleness rather than recalculated values. Calling `watch(...)` is both registration and reset.
72
+ - `createStore(...)` wraps nested plain objects and arrays, while `snapshot(...)` detaches the current plain value graph for logging, serialization, or comparison.
73
+
74
+ ## Example
75
+
76
+ ```ts
77
+ import { Computed, State, createStore, effect, watch } from '@ecopages/signals';
78
+
79
+ const count = new State(0);
80
+ const parity = new Computed(() => ((count.get() & 1) === 0 ? 'even' : 'odd'));
81
+ const store = createStore({ profile: { name: 'Ada' } });
82
+
83
+ const dispose = effect(() => {
84
+ console.log(parity.get(), store.profile.name);
85
+ });
86
+
87
+ const stopWatching = watch(
88
+ () => store.profile.name,
89
+ (nextName, previousName) => {
90
+ console.log(previousName, '->', nextName);
91
+ },
92
+ );
93
+
94
+ count.set(1);
95
+ store.profile.name = 'Grace';
96
+ dispose();
97
+ stopWatching();
98
+ ```
99
+
100
+ ## Limits
101
+
102
+ This implementation is still smaller than the current TC39 proposal draft.
103
+
104
+ - no full TC39 `Watcher` and subtle semantics surface yet
105
+ - no full proposal-style subtle introspection helpers yet
106
+ - no batching or transaction model
107
+ - no framework-owned disposal tree or component ownership integration yet
108
+
109
+ Those omissions are deliberate. The goal is to keep a small, useful standalone package while leaving room to align further as the proposal evolves.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecopages/signals",
3
- "version": "0.3.0-alpha.18",
3
+ "version": "0.3.0-alpha.19",
4
4
  "description": "Renderer-agnostic signal primitives based on the TC39 Signals proposal",
5
5
  "repository": {
6
6
  "type": "git",