bireactive 0.2.4 → 0.3.1
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/dist/animation/anim.js +4 -0
- package/dist/automerge/doc-cell.d.ts +20 -0
- package/dist/automerge/doc-cell.js +80 -0
- package/dist/automerge/index.d.ts +3 -0
- package/dist/automerge/index.js +12 -0
- package/dist/automerge/reconcile.d.ts +5 -0
- package/dist/automerge/reconcile.js +63 -0
- package/dist/coll.d.ts +7 -7
- package/dist/core/_counts.d.ts +48 -0
- package/dist/core/_counts.js +58 -0
- package/dist/core/cell.d.ts +182 -123
- package/dist/core/cell.js +1140 -721
- package/dist/core/debug.d.ts +25 -0
- package/dist/core/debug.js +121 -0
- package/dist/core/index.d.ts +9 -14
- package/dist/core/index.js +9 -14
- package/dist/core/lenses/aggregates.d.ts +1 -1
- package/dist/core/lenses/aggregates.js +4 -3
- package/dist/core/lenses/closed-form-policies.js +14 -9
- package/dist/core/lenses/decompositions.js +3 -3
- package/dist/core/lenses/domain-aggregates.js +5 -5
- package/dist/core/lenses/geometry.d.ts +1 -1
- package/dist/core/lenses/geometry.js +6 -7
- package/dist/core/lenses/index.d.ts +1 -0
- package/dist/core/lenses/index.js +1 -0
- package/dist/core/lenses/memory.d.ts +2 -2
- package/dist/core/lenses/memory.js +3 -3
- package/dist/core/lenses/snap.d.ts +18 -0
- package/dist/core/lenses/snap.js +145 -0
- package/dist/core/lenses/typed-factor.js +4 -3
- package/dist/core/optic.d.ts +13 -0
- package/dist/core/optic.js +44 -0
- package/dist/core/optics.d.ts +10 -0
- package/dist/core/optics.js +30 -0
- package/dist/core/store.d.ts +10 -0
- package/dist/core/store.js +85 -0
- package/dist/core/traits.d.ts +1 -0
- package/dist/core/values/audio.js +4 -5
- package/dist/core/values/box.js +7 -7
- package/dist/core/values/canvas.js +15 -18
- package/dist/core/values/color.js +5 -5
- package/dist/core/values/field.d.ts +70 -0
- package/dist/core/values/field.js +230 -0
- package/dist/core/values/gpu.d.ts +4 -2
- package/dist/core/values/gpu.js +11 -4
- package/dist/core/values/matrix.js +7 -7
- package/dist/core/values/num.d.ts +1 -1
- package/dist/core/values/num.js +1 -1
- package/dist/core/values/pose.js +4 -4
- package/dist/core/values/range.js +6 -6
- package/dist/core/values/str.js +8 -8
- package/dist/core/values/template.d.ts +1 -1
- package/dist/core/values/template.js +2 -1
- package/dist/core/values/transform.js +7 -7
- package/dist/core/values/tri.js +3 -3
- package/dist/core/values/vec.js +8 -12
- package/dist/ext/timeline.js +2 -2
- package/dist/formats/cst.d.ts +127 -0
- package/dist/formats/cst.js +280 -0
- package/dist/formats/edn.d.ts +2 -0
- package/dist/formats/edn.js +301 -0
- package/dist/formats/index.d.ts +6 -0
- package/dist/formats/index.js +8 -0
- package/dist/formats/json.d.ts +2 -0
- package/dist/formats/json.js +332 -0
- package/dist/formats/lens.d.ts +8 -0
- package/dist/formats/lens.js +51 -0
- package/dist/formats/toml.d.ts +2 -0
- package/dist/formats/toml.js +526 -0
- package/dist/formats/yaml.d.ts +2 -0
- package/dist/formats/yaml.js +661 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.js +5 -0
- package/dist/jsx-runtime.d.ts +54 -0
- package/dist/jsx-runtime.js +219 -0
- package/dist/learn/data.d.ts +49 -0
- package/dist/learn/data.js +181 -0
- package/dist/learn/index.d.ts +3 -0
- package/dist/learn/index.js +6 -0
- package/dist/learn/lens-net.d.ts +63 -0
- package/dist/learn/lens-net.js +219 -0
- package/dist/learn/mlp.d.ts +77 -0
- package/dist/learn/mlp.js +292 -0
- package/dist/propagators/csp.d.ts +13 -0
- package/dist/propagators/csp.js +52 -0
- package/dist/propagators/flex.d.ts +31 -0
- package/dist/propagators/flex.js +189 -0
- package/dist/propagators/graph.d.ts +73 -0
- package/dist/propagators/graph.js +543 -0
- package/dist/propagators/index.d.ts +8 -6
- package/dist/propagators/index.js +15 -6
- package/dist/propagators/lattice.d.ts +45 -0
- package/dist/propagators/lattice.js +113 -0
- package/dist/propagators/layout.d.ts +1 -27
- package/dist/propagators/layout.js +6 -175
- package/dist/propagators/numeric.d.ts +17 -0
- package/dist/propagators/numeric.js +93 -0
- package/dist/propagators/solver.d.ts +51 -0
- package/dist/propagators/solver.js +175 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +3 -0
- package/dist/schema/lens.d.ts +121 -0
- package/dist/schema/lens.js +429 -0
- package/dist/shapes/annular-sector.js +4 -4
- package/dist/shapes/button.js +1 -1
- package/dist/shapes/circle.js +1 -1
- package/dist/shapes/drag-behaviors.d.ts +56 -0
- package/dist/shapes/drag-behaviors.js +102 -0
- package/dist/shapes/drag-spec.d.ts +52 -0
- package/dist/shapes/drag-spec.js +112 -0
- package/dist/shapes/handle.js +2 -2
- package/dist/shapes/index.d.ts +3 -1
- package/dist/shapes/index.js +3 -1
- package/dist/shapes/interaction.d.ts +2 -3
- package/dist/shapes/interaction.js +77 -56
- package/dist/shapes/label.js +7 -1
- package/dist/shapes/layout.d.ts +47 -1
- package/dist/shapes/layout.js +60 -2
- package/dist/shapes/rect.js +7 -7
- package/dist/shapes/shape.js +8 -8
- package/dist/web/diagram.js +2 -2
- package/package.json +24 -2
- package/dist/propagators/network.d.ts +0 -52
- package/dist/propagators/network.js +0 -185
- package/dist/propagators/propagator.d.ts +0 -12
- package/dist/propagators/propagator.js +0 -16
- package/dist/propagators/range.d.ts +0 -45
- package/dist/propagators/range.js +0 -147
- package/dist/propagators/relations.d.ts +0 -60
- package/dist/propagators/relations.js +0 -343
package/dist/core/cell.d.ts
CHANGED
|
@@ -17,58 +17,66 @@ interface Link {
|
|
|
17
17
|
prevDep: Link | undefined;
|
|
18
18
|
nextDep: Link | undefined;
|
|
19
19
|
}
|
|
20
|
+
interface LensLink {
|
|
21
|
+
index: number;
|
|
22
|
+
parent: Cell<unknown>;
|
|
23
|
+
child: Cell<unknown>;
|
|
24
|
+
/** Spliced into `parent.childEdges` yet? The down-list (`parentEdges`) is
|
|
25
|
+
* eager at construction; the up-list is lazy on first back-mark so the
|
|
26
|
+
* parent's child order is arm-order (co-writer resolution is last-write-wins). */
|
|
27
|
+
linked: boolean;
|
|
28
|
+
nextParent: LensLink | undefined;
|
|
29
|
+
prevChild: LensLink | undefined;
|
|
30
|
+
nextChild: LensLink | undefined;
|
|
31
|
+
}
|
|
20
32
|
/** Install a hook fired on every source value-change; returns a restore fn. */
|
|
21
33
|
export declare function setCellWriteHook(fn: ((cell: Cell<unknown>) => void) | undefined): () => void;
|
|
22
|
-
export
|
|
23
|
-
readonly identity: T;
|
|
24
|
-
combine(acc: T, x: T): T;
|
|
25
|
-
/** Optional inverse for incremental fold. */
|
|
26
|
-
remove?(acc: T, x: T): T;
|
|
27
|
-
}
|
|
28
|
-
export declare const DIRECT_SLOT: unique symbol;
|
|
34
|
+
export type MergeFold<T> = (values: readonly T[]) => T;
|
|
29
35
|
declare class MergeNode<T> {
|
|
30
|
-
readonly
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
acc: T;
|
|
35
|
-
constructor(parent: Cell<T>, policy: MergePolicy<T>);
|
|
36
|
-
receive(slot: unknown, next: T): void;
|
|
37
|
-
fold(): T;
|
|
38
|
-
reset(): void;
|
|
36
|
+
readonly foldFn: MergeFold<T> | undefined;
|
|
37
|
+
/** Contributions gathered as the cone resolves; folded and cleared in `foldMerge`. */
|
|
38
|
+
contributions: T[];
|
|
39
|
+
constructor(fold: MergeFold<T> | undefined);
|
|
39
40
|
}
|
|
40
41
|
declare class BwdSpec {
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* the engine in 1-arg form `put(target)`; a source-reading lens bakes
|
|
45
|
-
* `settled(parent)` into this closure at build time. Multi-output:
|
|
46
|
-
* returns a per-parent update array. Stateful: the spec's `bwd`. */
|
|
42
|
+
/** Lens `put` (dual of `getter`): `put(target)` for 1→1 / multi-out (a
|
|
43
|
+
* source-reading lens reads its parents at walk time), `put(target, sources, c)`
|
|
44
|
+
* for stateful. `undefined` for a merge (folds) or pin (absorbs). */
|
|
47
45
|
put: ((target: any, current?: any) => any) | undefined;
|
|
48
|
-
/**
|
|
46
|
+
/** Fold payload; present ⇒ a fan-in merge. */
|
|
49
47
|
merge: MergeNode<unknown> | undefined;
|
|
50
|
-
/** Complement
|
|
48
|
+
/** Complement state; present ⇒ a complement-carrying (stateful) lens. */
|
|
51
49
|
stateful: StatefulCore | undefined;
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
|
|
50
|
+
/** `put` yields a per-parent tuple (split / stateful) vs a scalar (1→1). The
|
|
51
|
+
* only discriminant not derivable from topology (a 1-parent split is a tuple). */
|
|
52
|
+
scatter: boolean;
|
|
55
53
|
}
|
|
56
|
-
/** Runtime state of a
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* complement and the closures that project from / advance it. */
|
|
54
|
+
/** Runtime state of a symmetric-lens complement, kept off `BwdSpec` so plain
|
|
55
|
+
* lenses don't carry its slots. See the stateful-lens header for the theory
|
|
56
|
+
* (symmetric/edit lenses) and the version-stamp provenance. */
|
|
60
57
|
declare class StatefulCore {
|
|
61
58
|
/** Engine-owned memory the view discards. */
|
|
62
59
|
complement: unknown;
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
60
|
+
/** Advance the complement: `step(sources, complement)`. Run only when the
|
|
61
|
+
* sources actually moved (the engine gates it; see the stateful header). */
|
|
62
|
+
step: (sources: any, complement: any) => any;
|
|
63
|
+
/** Sum of the parents' `version`s as of the last sync. Sources moved iff the
|
|
64
|
+
* live sum differs — the lazy own-vs-external provenance that replaces a value
|
|
65
|
+
* witness. A read syncs it after stepping; a back-write re-stamps it post-order
|
|
66
|
+
* (own writes don't re-step, so `bwd` must leave the complement consistent).
|
|
67
|
+
* Seeded to `-1` (sums are ≥ 0) so the first use always folds the sources in. */
|
|
68
|
+
stamp: number;
|
|
69
|
+
constructor(complement: unknown, step: (sources: any, complement: any) => any);
|
|
71
70
|
}
|
|
71
|
+
/** Multi-out / stateful back-write sentinel: "leave this parent untouched."
|
|
72
|
+
* Every non-`SKIP` slot is written verbatim, `undefined` included; a short array
|
|
73
|
+
* skips the trailing parents. (1→1 `put` always writes its one parent.) */
|
|
74
|
+
export declare const SKIP: unique symbol;
|
|
75
|
+
export type Skip = typeof SKIP;
|
|
76
|
+
/** Per-parent back-write result: any prefix of the update tuple, each slot a value
|
|
77
|
+
* or `SKIP` (so `[a]` / `[a, SKIP]` / `[]` all type against `[A, B]`, while a bare
|
|
78
|
+
* `undefined` in a non-undefined slot stays an error). */
|
|
79
|
+
export type BackUpdates<T extends readonly unknown[]> = number extends T["length"] ? T : T extends readonly [infer H, ...infer R] ? readonly [] | readonly [H, ...BackUpdates<R>] : readonly [];
|
|
72
80
|
/** Plain T or any read-shape; snapshot via `readNow`, close via `reader`. */
|
|
73
81
|
export type Val<T> = T | Read<T>;
|
|
74
82
|
/** Covariant read-only surface. */
|
|
@@ -89,6 +97,16 @@ export type Writable<R> = R & WritableBrand & {
|
|
|
89
97
|
};
|
|
90
98
|
/** Strict factory input: a literal, or an existing `Writable<Cls>`. */
|
|
91
99
|
export type Init<C extends Cell<any>> = Inner<C> | Writable<C>;
|
|
100
|
+
/** Per-position value types behind a tuple of read shapes (the tuple form of {@link Inner}). */
|
|
101
|
+
type ReadValues<P extends readonly Read<unknown>[]> = {
|
|
102
|
+
[K in keyof P]: Inner<P[K]>;
|
|
103
|
+
};
|
|
104
|
+
/** {@link ReadValues} with each slot also admitting `SKIP` — the per-parent back-update shape. */
|
|
105
|
+
type ReadValuesOrSkip<P extends readonly Read<unknown>[]> = {
|
|
106
|
+
[K in keyof P]: Inner<P[K]> | Skip;
|
|
107
|
+
};
|
|
108
|
+
/** Any `Cell` subclass constructor — the constraint for polymorphic-`this` statics. */
|
|
109
|
+
type AnyCellCtor = new (...args: never[]) => Cell<any>;
|
|
92
110
|
/** Snapshot a `Val<T>` to plain `T` (one-shot, no tracking). */
|
|
93
111
|
export declare function readNow<T>(v: Val<T>): T;
|
|
94
112
|
/** Resolve a `Val<T>` to a `() => T` closure that unwraps on each call. */
|
|
@@ -108,129 +126,176 @@ export interface CellOptions<T = unknown> {
|
|
|
108
126
|
unwatched?: () => void;
|
|
109
127
|
/** Per-instance value equality; defaults to `Object.is`. */
|
|
110
128
|
equals?: (a: T, b: T) => boolean;
|
|
129
|
+
/** Debug label; surfaces in cyclic-read errors and graph dumps (see debug.ts). */
|
|
130
|
+
name?: string;
|
|
131
|
+
}
|
|
132
|
+
/** A lens as a first-class value, unbound from any source: `get` projects A→B,
|
|
133
|
+
* `put` writes B back into an A. Apply with `cell.through(optic)`; build with
|
|
134
|
+
* `optic` / `iso` / `atKey` / `compose` (optic.ts). `readsSource` is `false`
|
|
135
|
+
* only for an `iso`, letting `through` bind a cheaper 1-arg backward. */
|
|
136
|
+
export interface Optic<A, B> {
|
|
137
|
+
readonly get: (a: A) => B;
|
|
138
|
+
readonly put: (b: B, a: A) => A;
|
|
139
|
+
readonly readsSource: boolean;
|
|
140
|
+
/** Compose with a following optic (this first, then `next`). */
|
|
141
|
+
through<C>(next: Optic<B, C>): Optic<A, C>;
|
|
111
142
|
}
|
|
112
143
|
export declare class Cell<T = unknown> implements ReactiveNode {
|
|
144
|
+
/** @internal */
|
|
113
145
|
flags: number;
|
|
146
|
+
/** @internal */
|
|
114
147
|
subs: Link | undefined;
|
|
148
|
+
/** @internal */
|
|
115
149
|
subsTail: Link | undefined;
|
|
150
|
+
/** @internal */
|
|
116
151
|
deps: Link | undefined;
|
|
152
|
+
/** @internal */
|
|
117
153
|
depsTail: Link | undefined;
|
|
118
|
-
/** Forward derivation (computed/lens/merge). `undefined` ⇒ source. */
|
|
154
|
+
/** @internal Forward derivation (computed/lens/merge). `undefined` ⇒ source. */
|
|
119
155
|
getter: (() => T) | undefined;
|
|
120
|
-
/** Per-instance equality
|
|
121
|
-
* construction) so hot paths call it without an `undefined` branch. */
|
|
156
|
+
/** @internal Per-instance equality; always defined (defaults to `Object.is`). */
|
|
122
157
|
_equals: (a: T, b: T) => boolean;
|
|
123
|
-
/** First-subscriber / last-subscriber lifecycle hooks. */
|
|
158
|
+
/** @internal First-subscriber / last-subscriber lifecycle hooks. */
|
|
124
159
|
_watched: (() => void) | undefined;
|
|
160
|
+
/** @internal */
|
|
125
161
|
_unwatchedHook: (() => void) | undefined;
|
|
126
|
-
/** Source:
|
|
127
|
-
* Getter cell: `currentValue` = last derived cache, `pendingValue`
|
|
128
|
-
* reused as the deferred backward target (see `set value`). The two
|
|
129
|
-
* roles never coexist, so two fields suffice for four. */
|
|
162
|
+
/** @internal Source: committed value + staged write. */
|
|
130
163
|
currentValue: T;
|
|
164
|
+
/** @internal */
|
|
131
165
|
pendingValue: T;
|
|
132
|
-
/** Backward sidecar
|
|
133
|
-
* `undefined` for a read-only cell (source or computed). Allocated only
|
|
134
|
-
* for writable derived cells, keeping the common node lean. Writability
|
|
135
|
-
* is exactly `_bwd !== undefined`. See `BwdSpec`. */
|
|
166
|
+
/** @internal Backward sidecar; `undefined` iff read-only. Writability is `_bwd !== undefined`. */
|
|
136
167
|
_bwd: BwdSpec | undefined;
|
|
168
|
+
/** @internal Lens-edges to my back-targets (down); dual of `deps`. `markDown`/
|
|
169
|
+
* `backResolve` descend this toward sources. Index-ordered. */
|
|
170
|
+
parentEdges: LensLink | undefined;
|
|
171
|
+
/** @internal */
|
|
172
|
+
parentEdgesTail: LensLink | undefined;
|
|
173
|
+
/** @internal Lens-edges to my lens-children (up); dual of `subs`. `resolveCone`
|
|
174
|
+
* ascends this toward the armed views. */
|
|
175
|
+
childEdges: LensLink | undefined;
|
|
176
|
+
/** @internal */
|
|
177
|
+
childEdgesTail: LensLink | undefined;
|
|
178
|
+
/** @internal Backward flag word (`BF`), dual of forward `flags`. */
|
|
179
|
+
bflags: number;
|
|
180
|
+
/** @internal Visit epoch for `backResolve`'s collect phase (dedups diamonds
|
|
181
|
+
* without a Set; compared against the global `backCycle`). */
|
|
182
|
+
bEpoch: number;
|
|
183
|
+
/** @internal Monotone committed-change counter. A stateful lens sums its
|
|
184
|
+
* parents' versions to detect "did my sources move since I last synced?" —
|
|
185
|
+
* the lazy provenance that replaces a value witness (see the stateful header). */
|
|
186
|
+
version: number;
|
|
187
|
+
/** Optional debug label (`cell(0, { name })`); used by errors and graph dumps. */
|
|
188
|
+
name: string | undefined;
|
|
137
189
|
constructor(initial: T, opts?: CellOptions<T>);
|
|
138
190
|
readonly value: T;
|
|
139
|
-
|
|
140
|
-
/** Source write (alien's signal setter). Self-excludes the active
|
|
141
|
-
* network so a body writing its own dep doesn't re-trigger itself. */
|
|
191
|
+
/** @internal Single write-commit point; self-excludes the active network. */
|
|
142
192
|
_writeSource(next: T): void;
|
|
193
|
+
/** @internal */
|
|
143
194
|
_update(): boolean;
|
|
195
|
+
/** @internal */
|
|
144
196
|
_notify(): void;
|
|
197
|
+
/** @internal */
|
|
145
198
|
_unwatched(): void;
|
|
146
199
|
peek(): T;
|
|
147
|
-
/** Guard: silent coercion to string/number is almost always a bug. */
|
|
148
|
-
[Symbol.toPrimitive](hint: string): never;
|
|
149
200
|
/** Endomorphic lens. A 2-arg `bwd(view, current)` consults the current
|
|
150
201
|
* source; a 1-arg `bwd(view)` reconstructs it from the view alone. */
|
|
151
202
|
lens(this: Cell<T>, fwd: (v: T) => T, bwd: (target: T, current: T) => T): this;
|
|
152
203
|
/** Read-only same-type view: the RO dual of the endo `.lens`. For a cross-type view use the typed static
|
|
153
204
|
* `Target.derive(src, fn)`. */
|
|
154
205
|
derive(this: Cell<T>, fn: (v: T) => T): this;
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
|
|
206
|
+
/** Apply optic value(s) as a writable lens: `c.through(o)` ≡ `lens(c, o.get,
|
|
207
|
+
* o.put)`; multiple optics compose left-to-right (`c.through(a, b)` = `a`
|
|
208
|
+
* then `b`). Cross-type, unlike the endomorphic instance `.lens`. */
|
|
209
|
+
through<B>(this: Cell<T>, o: Optic<T, B>): Writable<Cell<B>>;
|
|
210
|
+
through<B, C>(this: Cell<T>, o1: Optic<T, B>, o2: Optic<B, C>): Writable<Cell<C>>;
|
|
211
|
+
through<B, C, D>(this: Cell<T>, o1: Optic<T, B>, o2: Optic<B, C>, o3: Optic<C, D>): Writable<Cell<D>>;
|
|
212
|
+
/** Backward fan-in: forward the identity view of its parent, backward the point
|
|
213
|
+
* where N contributors fold into one value. `fold` defaults to last-writer-wins. */
|
|
214
|
+
merge(this: Cell<T>, fold?: MergeFold<T>): Cell<T>;
|
|
159
215
|
/** Read-only typed view. `Cls.derive(parent, fn)` (1-input),
|
|
160
216
|
* `Cls.derive(parents, fn)` (N-input), or `Cls.derive(fn)` (closure).
|
|
161
217
|
* Polymorphic-`this`: `Vec.derive(...)` → `Vec`. */
|
|
162
|
-
static derive<C extends
|
|
163
|
-
static derive<C extends
|
|
164
|
-
|
|
165
|
-
}) => Inner<InstanceType<C>>): InstanceType<C>;
|
|
166
|
-
static derive<C extends new (...args: never[]) => Cell<any>>(this: C, fn: () => Inner<InstanceType<C>>): InstanceType<C>;
|
|
218
|
+
static derive<C extends AnyCellCtor, P>(this: C, parent: Read<P>, fn: (v: P) => Inner<InstanceType<C>>): InstanceType<C>;
|
|
219
|
+
static derive<C extends AnyCellCtor, P extends readonly Read<unknown>[]>(this: C, parents: P, fn: (vals: ReadValues<P>) => Inner<InstanceType<C>>): InstanceType<C>;
|
|
220
|
+
static derive<C extends AnyCellCtor>(this: C, fn: () => Inner<InstanceType<C>>): InstanceType<C>;
|
|
167
221
|
/** Writable lens. `Cls.lens(parent, fwd, bwd)` for one input,
|
|
168
222
|
* `Cls.lens(parents, fwd, bwd)` for N; a 2-arg `bwd` reads the source,
|
|
169
223
|
* a 1-arg `bwd` reconstructs it. `Cls.lens(parent(s), spec)` builds a
|
|
170
224
|
* complement-carrying lens from `{ init, step, fwd, bwd }`. */
|
|
171
|
-
static lens<C extends
|
|
172
|
-
static lens<C extends
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
176
|
-
}) => {
|
|
177
|
-
[K in keyof P]?: P[K] extends Read<infer V> ? V : never;
|
|
178
|
-
}): Writable<InstanceType<C>>;
|
|
179
|
-
static lens<C extends new (...args: never[]) => Cell<any>, P, Cm>(this: C, parent: Read<P>, spec: StatefulLensSpec<readonly [P], Inner<InstanceType<C>>, Cm>): Writable<InstanceType<C>>;
|
|
180
|
-
static lens<C extends new (...args: never[]) => Cell<any>, P extends readonly Read<unknown>[], Cm>(this: C, parents: P, spec: StatefulLensSpec<{
|
|
181
|
-
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
182
|
-
}, Inner<InstanceType<C>>, Cm>): Writable<InstanceType<C>>;
|
|
225
|
+
static lens<C extends AnyCellCtor, P>(this: C, parent: Read<P>, fwd: (v: P) => Inner<InstanceType<C>>, bwd: (target: Inner<InstanceType<C>>, v: P) => P): Writable<InstanceType<C>>;
|
|
226
|
+
static lens<C extends AnyCellCtor, P extends readonly Read<unknown>[]>(this: C, parents: P, fwd: (vals: ReadValues<P>) => Inner<InstanceType<C>>, bwd: (target: Inner<InstanceType<C>>, vals: ReadValues<P>) => BackUpdates<ReadValuesOrSkip<P>>): Writable<InstanceType<C>>;
|
|
227
|
+
static lens<C extends AnyCellCtor, P, Cm>(this: C, parent: Read<P>, spec: StatefulLensSpec1<P, Inner<InstanceType<C>>, Cm>): Writable<InstanceType<C>>;
|
|
228
|
+
static lens<C extends AnyCellCtor, P extends readonly Read<unknown>[], Cm>(this: C, parents: P, spec: StatefulLensSpec<ReadValues<P>, Inner<InstanceType<C>>, Cm>): Writable<InstanceType<C>>;
|
|
183
229
|
/** Type predicate against this class: `Vec.is(x)` narrows `x` to `Vec`.
|
|
184
230
|
* Inherited static; works for any subclass via polymorphic `this`. */
|
|
185
|
-
static is<C extends
|
|
186
|
-
/**
|
|
231
|
+
static is<C extends AnyCellCtor>(this: C, v: unknown): v is InstanceType<C>;
|
|
232
|
+
/** Coerce `Val<Inner<Cls>>` → `Cls`: instance → identity, RO cell →
|
|
187
233
|
* tracked `derive`, literal → fresh seed. */
|
|
188
|
-
static
|
|
234
|
+
static coerce<C extends AnyCellCtor>(this: C, v: Val<Inner<InstanceType<C>>>): InstanceType<C>;
|
|
189
235
|
/** Writable-shaped constant: always reads `v`, absorbs writes
|
|
190
236
|
* (parentless sink lens), for APIs demanding bidirectionality. */
|
|
191
|
-
static pin<C extends
|
|
192
|
-
/** Typed field lens onto `parent.value[key]`. A read-only computed
|
|
193
|
-
* parent yields a RO derive view; any writable parent yields a
|
|
194
|
-
* bidirectional field lens with spread-replace `put`. */
|
|
195
|
-
static fieldOf<C extends new (...args: never[]) => Cell<any>>(parent: Cell<any>, key: string | number | symbol, Cls: C): InstanceType<C>;
|
|
237
|
+
static pin<C extends AnyCellCtor>(this: C, v: Inner<InstanceType<C>>): Writable<InstanceType<C>>;
|
|
196
238
|
}
|
|
239
|
+
/** Typed field lens onto `parent.value[key]`. RO parent → RO derive;
|
|
240
|
+
* writable parent → bidirectional lens with spread-replace `put`. */
|
|
241
|
+
export declare function fieldOf<C extends AnyCellCtor>(parent: Cell<any>, key: string | number | symbol, Cls: C): InstanceType<C>;
|
|
197
242
|
export interface StatefulBwd<S extends readonly unknown[], C> {
|
|
198
|
-
updates:
|
|
199
|
-
|
|
200
|
-
|
|
243
|
+
/** Per-parent updates: a value (written verbatim, `undefined` included) or
|
|
244
|
+
* `SKIP` to leave that parent. A short array skips the trailing parents. */
|
|
245
|
+
updates: BackUpdates<{
|
|
246
|
+
[K in keyof S]: S[K] | Skip;
|
|
247
|
+
}>;
|
|
201
248
|
complement: C;
|
|
202
249
|
}
|
|
203
250
|
export interface StatefulLensSpec<S extends readonly unknown[], V, C> {
|
|
204
251
|
init: (sources: S) => C;
|
|
205
|
-
|
|
252
|
+
/** Advance the complement on an outside change. Optional — defaults to `init`
|
|
253
|
+
* (the memoryless refresh); the engine runs it only when sources actually move. */
|
|
254
|
+
step?: (sources: S, complement: C) => C;
|
|
206
255
|
fwd: (sources: S, complement: C) => V;
|
|
207
256
|
bwd: (target: V, sources: S, complement: C) => StatefulBwd<S, C>;
|
|
208
257
|
}
|
|
258
|
+
/** Single-source `bwd` result: a scalar `update` (or `SKIP`) plus the complement. */
|
|
259
|
+
export interface StatefulBwd1<S, C> {
|
|
260
|
+
update: S | Skip;
|
|
261
|
+
complement: C;
|
|
262
|
+
}
|
|
263
|
+
/** Single-source stateful spec — the scalar fast-path of `StatefulLensSpec`: one
|
|
264
|
+
* parent, so `init`/`step`/`fwd`/`bwd` take the source value directly, not a tuple. */
|
|
265
|
+
export interface StatefulLensSpec1<S, V, C> {
|
|
266
|
+
init: (source: S) => C;
|
|
267
|
+
step?: (source: S, complement: C) => C;
|
|
268
|
+
fwd: (source: S, complement: C) => V;
|
|
269
|
+
bwd: (target: V, source: S, complement: C) => StatefulBwd1<S, C>;
|
|
270
|
+
}
|
|
209
271
|
/** Writable source; passes an existing `Writable` through (idempotent). */
|
|
210
272
|
export declare function cell<T>(initial: T | Writable<Cell<T>>, opts?: CellOptions<T>): Writable<Cell<T>>;
|
|
211
273
|
/** Untyped read-only view: `derive(parent, fn)`, `derive(parents, fn)`,
|
|
212
274
|
* or `derive(fn)` (closure). */
|
|
213
275
|
export declare function derive<P, R>(parent: Read<P>, fn: (v: P) => R): Cell<R>;
|
|
214
|
-
export declare function derive<P extends readonly Read<unknown>[], R>(parents: P, fn: (vals:
|
|
215
|
-
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
216
|
-
}) => R): Cell<R>;
|
|
276
|
+
export declare function derive<P extends readonly Read<unknown>[], R>(parents: P, fn: (vals: ReadValues<P>) => R): Cell<R>;
|
|
217
277
|
export declare function derive<R>(fn: () => R): Cell<R>;
|
|
218
278
|
/** Untyped lens, inferring `R` from the closures. A 2-arg `bwd` reads the
|
|
219
279
|
* source, a 1-arg `bwd` reconstructs it; `lens(parent(s), spec)` builds a
|
|
220
280
|
* complement-carrying lens. */
|
|
221
281
|
export declare function lens<P, R>(parent: Read<P>, fwd: (v: P) => R, bwd: (target: R, v: P) => P): Writable<Cell<R>>;
|
|
222
|
-
export declare function lens<P extends readonly Read<unknown>[], R>(parents: P, fwd: (vals:
|
|
223
|
-
|
|
282
|
+
export declare function lens<P extends readonly Read<unknown>[], R>(parents: P, fwd: (vals: ReadValues<P>) => R, bwd: (target: R, vals: ReadValues<P>) => ReadValuesOrSkip<P>): Writable<Cell<R>>;
|
|
283
|
+
export declare function lens<S extends Record<string, Read<unknown>>, R>(parents: S, fwd: (vals: {
|
|
284
|
+
[K in keyof S]: Inner<S[K]>;
|
|
224
285
|
}) => R, bwd: (target: R, vals: {
|
|
225
|
-
[K in keyof
|
|
226
|
-
}) => {
|
|
227
|
-
[K in keyof
|
|
228
|
-
}): Writable<Cell<R>>;
|
|
229
|
-
export declare function lens<P, R, C>(parent: Read<P>, spec:
|
|
230
|
-
export declare function lens<P extends readonly Read<unknown>[], R, C>(parents: P, spec: StatefulLensSpec<
|
|
231
|
-
[K in keyof P]: P[K] extends Read<infer V> ? V : never;
|
|
232
|
-
}, R, C>): Writable<Cell<R>>;
|
|
286
|
+
[K in keyof S]: Inner<S[K]>;
|
|
287
|
+
}) => Partial<{
|
|
288
|
+
[K in keyof S]: Inner<S[K]> | Skip;
|
|
289
|
+
}>): Writable<Cell<R>>;
|
|
290
|
+
export declare function lens<P, R, C>(parent: Read<P>, spec: StatefulLensSpec1<P, R, C>): Writable<Cell<R>>;
|
|
291
|
+
export declare function lens<P extends readonly Read<unknown>[], R, C>(parents: P, spec: StatefulLensSpec<ReadValues<P>, R, C>): Writable<Cell<R>>;
|
|
233
292
|
export declare function effect(fn: () => (() => void) | void): () => void;
|
|
293
|
+
/** Run all pending effects now, synchronously — the escape hatch for code that
|
|
294
|
+
* must observe effect side-effects before yielding. Reads never need it. */
|
|
295
|
+
export declare function settle(): void;
|
|
296
|
+
/** Group writes and flush effects synchronously at the end of `fn`. Effects
|
|
297
|
+
* coalesce on the microtask turn anyway; reach for `batch` only to run the woken
|
|
298
|
+
* effects before the call returns. */
|
|
234
299
|
export declare function batch<R>(fn: () => R): R;
|
|
235
300
|
export declare function untracked<R>(fn: () => R): R;
|
|
236
301
|
/** Handle to a `network` invocation. */
|
|
@@ -244,34 +309,28 @@ export interface Network {
|
|
|
244
309
|
/** Remove cells from the topology (idempotent; does NOT fire). */
|
|
245
310
|
unsubscribe(...cells: Cell<any>[]): void;
|
|
246
311
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* `flush()` from inside the body throws
|
|
252
|
-
*
|
|
253
|
-
export declare function network(deps: readonly Cell<any>[], body:
|
|
312
|
+
type NetworkBody = (dirty: ReadonlySet<Cell<unknown>>, handle: Network) => void;
|
|
313
|
+
/** Build a reactive sub-DAG. The body fires when any subscribed dep changes
|
|
314
|
+
* (`dirty` = the changed subset), self-excludes its own writes, and (auto mode)
|
|
315
|
+
* resolves synchronously. `manual: true` defers firing so only `flush()` advances;
|
|
316
|
+
* `flush()` from inside the body throws. Network-specific state (last-values,
|
|
317
|
+
* handle) lives in this closure, so the shared `Effect` carries none of it. */
|
|
318
|
+
export declare function network(deps: readonly Cell<any>[], body: NetworkBody, opts?: {
|
|
254
319
|
manual?: boolean;
|
|
255
320
|
}): Network;
|
|
256
|
-
/** Bidirectional field lens onto `parent.value[key]
|
|
257
|
-
*
|
|
258
|
-
* conditional: `Writable<Cls>` on a writable parent, bare `Cls` on RO.
|
|
321
|
+
/** Bidirectional field lens onto `parent.value[key]` (write spread-replaces),
|
|
322
|
+
* cached per (instance, key). `Writable<Cls>` on a writable parent, bare `Cls` on RO.
|
|
259
323
|
*
|
|
260
|
-
* get x() { return
|
|
261
|
-
export declare function
|
|
324
|
+
* get x() { return fieldLens(this, "x", Num); } */
|
|
325
|
+
export declare function fieldLens<S extends Cell<any>, K extends keyof Inner<S>, C extends new (...args: never[]) => Cell<Inner<S>[K]>>(parent: S, key: K, Cls: C): S extends WritableBrand ? Writable<InstanceType<C>> : InstanceType<C>;
|
|
262
326
|
/** Read-only derived view via `Cls.derive(parent, fn)`, memoized per
|
|
263
|
-
* (instance, key)
|
|
264
|
-
* getter form, not a new kind of cell.
|
|
327
|
+
* (instance, key). The cache is the point.
|
|
265
328
|
*
|
|
266
329
|
* get magnitude() {
|
|
267
330
|
* return cachedDerive(this, "magnitude", Num, v => Math.hypot(v.x, v.y));
|
|
268
331
|
* } */
|
|
269
|
-
export declare function cachedDerive<S extends Cell<any>, C extends
|
|
270
|
-
/** Every cell `s` transitively depends on, including itself
|
|
271
|
-
*
|
|
272
|
-
* peeking each Computed to populate deps; the `seen` set breaks cycles.
|
|
273
|
-
* Used by `Propagators` to expand declared reads into their transitive
|
|
274
|
-
* parent set. Inspection is safe: it only reads engine state and peeks
|
|
275
|
-
* `.value` (idempotent for lazy Computeds). */
|
|
332
|
+
export declare function cachedDerive<S extends Cell<any>, C extends AnyCellCtor>(parent: S, key: string | symbol, Cls: C, fn: (v: Inner<S>) => Inner<InstanceType<C>>): InstanceType<C>;
|
|
333
|
+
/** Every cell `s` transitively depends on, including itself (BFS, peeking each
|
|
334
|
+
* computed to populate deps; `seen` breaks cycles). */
|
|
276
335
|
export declare function transitiveDeps(s: Cell<unknown>): Set<Cell<unknown>>;
|
|
277
336
|
export {};
|