@zakkster/lite-signal 1.6.0-preview → 1.6.0-preview.0
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.
- package/CHANGELOG.md +84 -0
- package/Signal.js +65 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,84 @@ All notable changes to `@zakkster/lite-signal` are documented here.
|
|
|
4
4
|
Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
5
|
This project follows [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.6.0] -- 2026-06-26 (preview)
|
|
8
|
+
|
|
9
|
+
The observability-and-lifecycle minor, shipping on the `preview` dist-tag while it
|
|
10
|
+
settles. Two additions: `stats()` gains a twelfth key, **`flushPasses`**, plus two
|
|
11
|
+
flush-profiling mutation-hook opcodes -- the flush/recompute dimension
|
|
12
|
+
lite-devtools 1.2 / lite-studio 1.2 read through `watchAllocations`; and
|
|
13
|
+
**`createScope(fn)`** (landed in `preview.0`), the disposable-owner counterpart to
|
|
14
|
+
`createRoot` that a keyed-list / scene reconciler needs for per-item teardown.
|
|
15
|
+
Drop-in over 1.5.0: the callable API and hot paths are unchanged, and the new
|
|
16
|
+
instrumentation is frozen and zero-cost unless a mutation-hook listener is attached.
|
|
17
|
+
|
|
18
|
+
### Added -- `flushPasses` on `stats()` + flush-profiling opcodes
|
|
19
|
+
|
|
20
|
+
`stats()` now returns **12 keys**: the 11 from 1.4.x plus `flushPasses`, a counter
|
|
21
|
+
that advances once per effect-flush drain pass. Two `onGraphMutation` opcodes back
|
|
22
|
+
the flush dimension:
|
|
23
|
+
|
|
24
|
+
- **`6` flush pass** -- `(passCount, effectsToRun)`, at the top of each drain pass.
|
|
25
|
+
- **`7` effect run in pass** -- `(id, 0)`, before each effect re-run inside a pass.
|
|
26
|
+
|
|
27
|
+
Both the counter bump and the opcode dispatch sit behind the existing
|
|
28
|
+
`if (mutationHook !== null)` gate, so when no profiler is attached they are inert:
|
|
29
|
+
`flushPasses` is frozen and the flush loop is byte-identical to 1.5.0. This is what
|
|
30
|
+
lets `watchAllocations` chart recompute/flush activity alongside the 1.4.0
|
|
31
|
+
allocation counters (`totalAllocations` / `poolGrowths` / `totalDisposals`), which
|
|
32
|
+
remain available from 1.4.0 on every engine -- only the flush series requires 1.6.
|
|
33
|
+
|
|
34
|
+
### Added -- `createScope(fn)` (disposable owner scope) [preview.0]
|
|
35
|
+
|
|
36
|
+
`createScope` runs `fn(dispose)` in a detached scope and returns whatever `fn`
|
|
37
|
+
returns, having handed `fn` a single `dispose` that **cascade-disposes every effect
|
|
38
|
+
and computed created inside `fn`**. It is the lifecycle complement to `createRoot`:
|
|
39
|
+
|
|
40
|
+
- `createRoot(fn)` only **detaches** -- nodes created inside are unowned and the
|
|
41
|
+
caller must dispose each one by hand (there is no owner to do it automatically).
|
|
42
|
+
Correct for spawning one known long-lived watcher (lite-query's pattern).
|
|
43
|
+
- `createScope(fn)` **adopts** -- it owns whatever `fn` builds, so one disposer tears
|
|
44
|
+
down a subtree of *unknown* shape. This is what a per-item scope in a keyed-list or
|
|
45
|
+
scene reconciler requires, where the item's reactive graph is the consumer's
|
|
46
|
+
`mapFn`, not something the reconciler can enumerate.
|
|
47
|
+
|
|
48
|
+
**Semantics.** `fn` runs once in a detached, untracked context: no ownership and no
|
|
49
|
+
dependency leak from `fn`'s direct body into the enclosing scope, and the scope owner
|
|
50
|
+
never re-runs. Reactive bindings belong in inner effect/computed bodies inside `fn`
|
|
51
|
+
(those track normally and are owned by the scope); direct-body reads are untracked.
|
|
52
|
+
Consistent with the 1.2.0 ownership rule, **plain signals created directly in `fn` are
|
|
53
|
+
not adopted** -- dispose those explicitly (the creator holds the handle) or let them
|
|
54
|
+
fall out of reference; computeds and effects are adopted and cascade.
|
|
55
|
+
|
|
56
|
+
**Implementation.** The scope owner is backed by a never-re-running effect node, so it
|
|
57
|
+
counts as one effect in `stats()` and its disposer is the same gen-guarded, ABA-safe,
|
|
58
|
+
introspection-stamped handle `effect()` returns (`describe` / `nodeId` / `forEachOwned`
|
|
59
|
+
resolve it to the owner). No new node kind, flag, or `stats()` key -- the pinned
|
|
60
|
+
`signals + computeds + effects === activeNodes` invariant is untouched. The API
|
|
61
|
+
(`fn => dispose`) is the stable contract; a future engine may swap in a lighter
|
|
62
|
+
pure-owner node transparently.
|
|
63
|
+
|
|
64
|
+
Exported as a registry method and a top-level helper bound to the default registry,
|
|
65
|
+
mirroring `createRoot`.
|
|
66
|
+
|
|
67
|
+
### Verified
|
|
68
|
+
|
|
69
|
+
- **`createScope` behavior** (4 tests, `node --expose-gc`): returns `fn`'s value and
|
|
70
|
+
runs the owner exactly once even when `fn` reads signals in its direct body
|
|
71
|
+
(untracked); inner effects/computeds track and update; `dispose()` cascade-disposes
|
|
72
|
+
the owned subtree (effects + computeds) while an un-adopted signal correctly
|
|
73
|
+
survives; a disposed scope's inner effects stop firing; **a scope created inside a
|
|
74
|
+
consumer effect survives that consumer's re-run** (the reconciler-critical detach
|
|
75
|
+
property); `dispose()` is an idempotent no-op on the second call; the disposer is
|
|
76
|
+
introspection-stamped to its owner effect; and `totalAllocations - totalDisposals
|
|
77
|
+
=== activeNodes` holds after teardown. Plus a smoke confirming signal -> computed ->
|
|
78
|
+
effect is unaffected by the additive change.
|
|
79
|
+
- **Instrumentation is zero-cost when unobserved**: `flushPasses` advances and opcodes
|
|
80
|
+
6/7 fire only while a mutation-hook listener is attached; with none, the flush path
|
|
81
|
+
is unchanged from 1.5.0.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
7
85
|
## [1.5.0] -- 2026-06-XX
|
|
8
86
|
|
|
9
87
|
The API-surface minor: two new **non-callable, allocation-light** reactive
|
|
@@ -135,6 +213,8 @@ survives consumer re-runs.
|
|
|
135
213
|
|
|
136
214
|
|
|
137
215
|
|
|
216
|
+
## [1.4.0] -- 2026-06-XX
|
|
217
|
+
|
|
138
218
|
The observability minor: `stats()` gains **three cumulative lifecycle counters**
|
|
139
219
|
(`totalAllocations`, `totalDisposals`, `poolGrowths`) -- the surface reserved for
|
|
140
220
|
1.4.0 in the 1.2.x and 1.3.0 notes, now delivered. This is what lite-devtools /
|
|
@@ -209,6 +289,8 @@ as before (the reset keeps the arena warm); only the cumulative counts reset.
|
|
|
209
289
|
|
|
210
290
|
|
|
211
291
|
|
|
292
|
+
## [1.3.0] -- 2026-06-XX
|
|
293
|
+
|
|
212
294
|
The pool minor: the node and link pools become **growable and incrementally
|
|
213
295
|
populated**, the propagation mark phase moves to an **intrusive linked-list
|
|
214
296
|
stack**, and a small **registry config surface** (`prealloc`,
|
|
@@ -303,6 +385,8 @@ in 1.3.0.
|
|
|
303
385
|
|
|
304
386
|
|
|
305
387
|
|
|
388
|
+
## [1.2.2] -- 2026-06-XX
|
|
389
|
+
|
|
306
390
|
A code-deletion ship: a `createNode` audit removes ten redundant field-writes
|
|
307
391
|
that defended against a state the engine cannot produce on a clean free-list.
|
|
308
392
|
No public surface change, no semantic change, no new tests required for new
|
package/Signal.js
CHANGED
|
@@ -1482,6 +1482,66 @@ export function createRegistry(config) {
|
|
|
1482
1482
|
}
|
|
1483
1483
|
}
|
|
1484
1484
|
|
|
1485
|
+
/**
|
|
1486
|
+
* Create a DISPOSABLE reactive scope: an owner that ADOPTS the effects and
|
|
1487
|
+
* computeds created inside `fn`, so a single returned `dispose` tears the
|
|
1488
|
+
* whole subtree down at once. Where `createRoot` only DETACHES (leaving the
|
|
1489
|
+
* caller to dispose each created node by hand -- "there is no owner to do it
|
|
1490
|
+
* automatically"), `createScope` hands back one disposer that cascade-disposes
|
|
1491
|
+
* everything `fn` built. This is the lifecycle primitive a keyed list / scene
|
|
1492
|
+
* reconciler needs for per-item scopes of unknown internal shape.
|
|
1493
|
+
*
|
|
1494
|
+
* `fn` receives `dispose` and runs ONCE in a detached, untracked context: no
|
|
1495
|
+
* ownership and no dependency leak from `fn`'s direct body into the enclosing
|
|
1496
|
+
* scope, and the scope owner itself never re-runs. Put reactive bindings in
|
|
1497
|
+
* inner effect / computed bodies inside `fn` -- those establish their own
|
|
1498
|
+
* tracking scopes AND are owned by this scope, so they update normally and are
|
|
1499
|
+
* cascade-disposed on `dispose()`. Reads in `fn`'s direct body are untracked.
|
|
1500
|
+
* Returns whatever `fn` returns.
|
|
1501
|
+
*
|
|
1502
|
+
* Plain signals created directly in `fn` are NOT adopted -- the engine never
|
|
1503
|
+
* owner-adopts signals (the lazy-alloc rule, 1.2.0) -- so dispose those
|
|
1504
|
+
* explicitly (the creator holds the handle) or let them fall out of reference.
|
|
1505
|
+
* Computeds and effects ARE adopted and cascade.
|
|
1506
|
+
*
|
|
1507
|
+
* Implementation: the scope owner is backed by a never-re-running effect node,
|
|
1508
|
+
* so it counts as one effect in stats() and its disposer is the same
|
|
1509
|
+
* gen-guarded handle effect() returns -- ABA-safety and introspection match
|
|
1510
|
+
* effects exactly. The API (`fn => dispose`) is the stable contract; a future
|
|
1511
|
+
* engine may swap in a lighter pure-owner node transparently.
|
|
1512
|
+
*
|
|
1513
|
+
* @template T
|
|
1514
|
+
* @param {(dispose: () => void) => T} fn
|
|
1515
|
+
* @returns {T}
|
|
1516
|
+
*/
|
|
1517
|
+
function createScope(fn) {
|
|
1518
|
+
let stop;
|
|
1519
|
+
let result;
|
|
1520
|
+
// Forward-referenced disposer: `stop` is assigned only after effect()
|
|
1521
|
+
// returns, but `fn` runs synchronously DURING effect(). Callers stash this
|
|
1522
|
+
// and invoke it later, by which point `stop` is set. (Disposing the scope
|
|
1523
|
+
// synchronously from inside `fn` is a no-op -- not a supported pattern.)
|
|
1524
|
+
const dispose = function dispose() { if (stop !== undefined) stop(); };
|
|
1525
|
+
// createRoot detaches owner+observer+tracking; inside it effect() creates a
|
|
1526
|
+
// ROOT owner effect (unowned -> survives the enclosing scope's re-runs).
|
|
1527
|
+
// untrack keeps `fn`'s direct reads from handing the owner any dependency,
|
|
1528
|
+
// so the owner runs exactly once; `fn`'s inner effects/computeds are owned
|
|
1529
|
+
// by it and cascade on dispose.
|
|
1530
|
+
createRoot(function () {
|
|
1531
|
+
stop = effect(function scopeOwner() {
|
|
1532
|
+
untrack(function () { result = fn(dispose); });
|
|
1533
|
+
});
|
|
1534
|
+
});
|
|
1535
|
+
// Stamp the wrapper so describe / nodeId / forEachOwned resolve it to the
|
|
1536
|
+
// owner effect, matching the first-class-handle contract effects gained in
|
|
1537
|
+
// 1.2.1. (`stop` carries the symbols once effect() has returned.)
|
|
1538
|
+
if (stop !== undefined && stop[NODE_PTR] !== undefined) {
|
|
1539
|
+
dispose[NODE_PTR] = stop[NODE_PTR];
|
|
1540
|
+
dispose[NODE_GEN] = stop[NODE_GEN];
|
|
1541
|
+
}
|
|
1542
|
+
return result;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1485
1545
|
/**
|
|
1486
1546
|
* Register a function to run when the enclosing effect/computed re-runs or
|
|
1487
1547
|
* is disposed. Cascade order on disposal is inside-out: an effect's owned
|
|
@@ -1710,7 +1770,7 @@ export function createRegistry(config) {
|
|
|
1710
1770
|
while (l !== null) { const nx = l.nextDep; fn(describeNode(l.source)); l = nx; }
|
|
1711
1771
|
}
|
|
1712
1772
|
|
|
1713
|
-
return {signal, computed, effect, signalBox, computedBox, dispose, batch, untrack, createRoot, onCleanup, stats, destroy, isTracking, hasObservers, observeObservers, forEachObserver, forEachSource, forEachOwned, ownerOf, nodeId, describe, onGraphMutation};
|
|
1773
|
+
return {signal, computed, effect, signalBox, computedBox, dispose, batch, untrack, createRoot, createScope, onCleanup, stats, destroy, isTracking, hasObservers, observeObservers, forEachObserver, forEachSource, forEachOwned, ownerOf, nodeId, describe, onGraphMutation};
|
|
1714
1774
|
}
|
|
1715
1775
|
|
|
1716
1776
|
// -----------------------------------------------------------------
|
|
@@ -1758,6 +1818,10 @@ export function createRoot(fn) {
|
|
|
1758
1818
|
return defaultRegistry.createRoot(fn);
|
|
1759
1819
|
}
|
|
1760
1820
|
|
|
1821
|
+
export function createScope(fn) {
|
|
1822
|
+
return defaultRegistry.createScope(fn);
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1761
1825
|
/**
|
|
1762
1826
|
* True iff a read RIGHT NOW would record a dependency on the default registry.
|
|
1763
1827
|
* See {@link createRegistry} for the per-registry version.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakkster/lite-signal",
|
|
3
|
-
"version": "1.6.0-preview",
|
|
3
|
+
"version": "1.6.0-preview.0",
|
|
4
4
|
"description": "Zero-GC reactive graph. Monomorphic object pool, versioned push-pull propagation, 32-bit modular versioning. Built for hot paths and long-running processes.",
|
|
5
5
|
"author": "Zahary Shinikchiev <shinikchiev@yahoo.com>",
|
|
6
6
|
"license": "MIT",
|