@solidjs/signals 2.0.0-rc.6 → 2.0.0-rc.8

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 (131) hide show
  1. package/dist/dev-shared.js +5243 -0
  2. package/dist/dev.attribution.js +2333 -0
  3. package/dist/dev.js +1758 -6621
  4. package/dist/observe/affects.js +127 -0
  5. package/dist/observe/attribution.js +1 -0
  6. package/dist/observe/boundaries.js +586 -0
  7. package/dist/observe/core/action.js +167 -0
  8. package/dist/observe/core/async.js +736 -0
  9. package/dist/observe/core/attribution-hooks.js +60 -0
  10. package/dist/observe/core/attribution.js +2318 -0
  11. package/dist/{types-cjs/core/constants.d.cts → observe/core/constants.js} +135 -71
  12. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  13. package/dist/observe/core/core.js +1289 -0
  14. package/dist/observe/core/dev.js +232 -0
  15. package/dist/observe/core/effect.js +179 -0
  16. package/dist/observe/core/error.js +80 -0
  17. package/dist/observe/core/external.js +98 -0
  18. package/dist/observe/core/graph.js +155 -0
  19. package/dist/observe/core/heap.js +147 -0
  20. package/dist/observe/core/invariants.js +43 -0
  21. package/dist/observe/core/lanes.js +168 -0
  22. package/dist/observe/core/optimistic.js +438 -0
  23. package/dist/observe/core/owner.js +308 -0
  24. package/dist/observe/core/scheduler.js +1190 -0
  25. package/dist/observe/core/verdict.js +551 -0
  26. package/dist/observe/index.js +55 -0
  27. package/dist/observe/map.js +482 -0
  28. package/dist/{types-cjs/signals.d.cts → observe/signals.js} +305 -317
  29. package/dist/observe/store/index.js +38 -0
  30. package/dist/observe/store/next/optimistic.js +651 -0
  31. package/dist/observe/store/next/projection.js +242 -0
  32. package/dist/observe/store/next/reconcile.js +373 -0
  33. package/dist/observe/store/next/store.js +2213 -0
  34. package/dist/observe/store/next/target.js +51 -0
  35. package/dist/observe/store/store.js +323 -0
  36. package/dist/observe/store/storePath.js +103 -0
  37. package/dist/observe/store/utils.js +210 -0
  38. package/dist/prod/attribution.js +32 -0
  39. package/dist/prod/boundaries.js +3 -1
  40. package/dist/prod/core/action.js +52 -32
  41. package/dist/prod/core/async.js +177 -128
  42. package/dist/prod/core/attribution-hooks.js +3 -0
  43. package/dist/prod/core/constants.js +32 -1
  44. package/dist/prod/core/context.js +10 -16
  45. package/dist/prod/core/core.js +505 -286
  46. package/dist/prod/core/dev.js +2 -0
  47. package/dist/prod/core/effect.js +72 -43
  48. package/dist/prod/core/external.js +2 -2
  49. package/dist/prod/core/graph.js +40 -36
  50. package/dist/prod/core/heap.js +50 -51
  51. package/dist/prod/core/lanes.js +43 -22
  52. package/dist/prod/core/optimistic.js +224 -80
  53. package/dist/prod/core/owner.js +43 -39
  54. package/dist/prod/core/scheduler.js +347 -232
  55. package/dist/prod/core/verdict.js +71 -74
  56. package/dist/prod/index.js +9 -5
  57. package/dist/prod/map.js +311 -150
  58. package/dist/prod/signals.js +52 -38
  59. package/dist/prod/store/next/optimistic.js +127 -131
  60. package/dist/prod/store/next/projection.js +3 -3
  61. package/dist/prod/store/next/reconcile.js +149 -294
  62. package/dist/prod/store/next/store.js +694 -380
  63. package/dist/prod/store/next/target.js +32 -10
  64. package/dist/prod/store/store.js +12 -14
  65. package/dist/prod/store/utils.js +36 -27
  66. package/dist/types/attribution.d.ts +15 -0
  67. package/dist/types/attribution.prod.d.ts +13 -0
  68. package/dist/types/core/async.d.ts +1 -1
  69. package/dist/types/core/attribution-hooks.d.ts +183 -6
  70. package/dist/types/core/attribution.d.ts +435 -24
  71. package/dist/types/core/constants.d.ts +31 -0
  72. package/dist/types/core/core.d.ts +19 -3
  73. package/dist/types/core/dev.d.ts +165 -26
  74. package/dist/types/core/effect.d.ts +8 -1
  75. package/dist/types/core/heap.d.ts +5 -3
  76. package/dist/types/core/index.d.ts +2 -1
  77. package/dist/types/core/invariants.d.ts +1 -1
  78. package/dist/types/core/lanes.d.ts +17 -0
  79. package/dist/types/core/scheduler.d.ts +69 -4
  80. package/dist/types/core/types.d.ts +29 -9
  81. package/dist/types/index.d.ts +9 -2
  82. package/dist/types/map.d.ts +2 -0
  83. package/dist/types/signals.d.ts +10 -0
  84. package/dist/types/store/index.d.ts +4 -6
  85. package/dist/types/store/next/optimistic.d.ts +4 -2
  86. package/dist/types/store/next/reconcile.d.ts +5 -12
  87. package/dist/types/store/next/store.d.ts +8 -9
  88. package/dist/types/store/next/target.d.ts +56 -55
  89. package/dist/types/store/store.d.ts +14 -9
  90. package/dist/types/store/utils.d.ts +7 -0
  91. package/package.json +21 -16
  92. package/dist/node.cjs +0 -11121
  93. package/dist/prod/store/next/patch-hooks.js +0 -13
  94. package/dist/prod/store/next/patch.js +0 -614
  95. package/dist/types/store/next/patch-hooks.d.ts +0 -41
  96. package/dist/types/store/next/patch.d.ts +0 -91
  97. package/dist/types-cjs/affects.d.cts +0 -47
  98. package/dist/types-cjs/boundaries.d.cts +0 -175
  99. package/dist/types-cjs/core/action.d.cts +0 -64
  100. package/dist/types-cjs/core/async.d.cts +0 -23
  101. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -63
  102. package/dist/types-cjs/core/attribution.d.cts +0 -239
  103. package/dist/types-cjs/core/core.d.cts +0 -176
  104. package/dist/types-cjs/core/dev.d.cts +0 -95
  105. package/dist/types-cjs/core/effect.d.cts +0 -30
  106. package/dist/types-cjs/core/error.d.cts +0 -56
  107. package/dist/types-cjs/core/external.d.cts +0 -15
  108. package/dist/types-cjs/core/graph.d.cts +0 -28
  109. package/dist/types-cjs/core/heap.d.cts +0 -22
  110. package/dist/types-cjs/core/index.d.cts +0 -13
  111. package/dist/types-cjs/core/invariants.d.cts +0 -59
  112. package/dist/types-cjs/core/lanes.d.cts +0 -44
  113. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  114. package/dist/types-cjs/core/owner.d.cts +0 -124
  115. package/dist/types-cjs/core/scheduler.d.cts +0 -231
  116. package/dist/types-cjs/core/types.d.cts +0 -204
  117. package/dist/types-cjs/core/verdict.d.cts +0 -2
  118. package/dist/types-cjs/index.d.cts +0 -10
  119. package/dist/types-cjs/map.d.cts +0 -69
  120. package/dist/types-cjs/package.json +0 -3
  121. package/dist/types-cjs/store/index.d.cts +0 -21
  122. package/dist/types-cjs/store/next/optimistic.d.cts +0 -23
  123. package/dist/types-cjs/store/next/patch-hooks.d.cts +0 -41
  124. package/dist/types-cjs/store/next/patch.d.cts +0 -91
  125. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  126. package/dist/types-cjs/store/next/reconcile.d.cts +0 -17
  127. package/dist/types-cjs/store/next/store.d.cts +0 -127
  128. package/dist/types-cjs/store/next/target.d.cts +0 -192
  129. package/dist/types-cjs/store/store.d.cts +0 -138
  130. package/dist/types-cjs/store/storePath.d.cts +0 -58
  131. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,91 +0,0 @@
1
- import type { Owner } from "../../core/types.js";
2
- import { type StoreNextTarget } from "./target.js";
3
- export type PatchFn = (next: any, prev: any, force?: boolean) => void;
4
- interface PatchEntry {
5
- fn: PatchFn;
6
- owner: Owner | null;
7
- }
8
- /**
9
- * Emit a record's visibility transition. Callers gate on `hasPatches()` and
10
- * `t.d` cheaply; this function re-checks and walks ancestors (§4b).
11
- */
12
- export declare function emitPatch(t: StoreNextTarget, next: any, prev: any): void;
13
- /** Emission for sites that already stand at the record with both sides in
14
- * hand and have already handled ancestors (the adoption walk descends —
15
- * parents were visited first), so no bubbling walk. */
16
- export declare function emitPatchLocal(t: StoreNextTarget, next: any, prev: any): void;
17
- export declare function emitPatchOptimistic(t: StoreNextTarget, next: any, prev: any): void;
18
- /** Row-ops emission at OPTIMISTIC (lane) timing: user drafts on an
19
- * optimistic family must show structure IN FLIGHT — bypassing the
20
- * transition stash exactly like emitPatchOptimistic. Two forms:
21
- * - `ops` given (write site): `nextRows` is the draft's intended visible
22
- * list, ops the identity diff against the pre-write optimistic view.
23
- * - `ops === null` (revert site): RESYNC — the consumer rebuilds retention
24
- * by row identity against the live post-revert view, resolved from the
25
- * target at drain time (overrides are gone by then, so `pb ?? v` IS the
26
- * committed truth). */
27
- export declare function emitRowOpsOptimistic(t: StoreNextTarget, nextRows: any[] | null, ops: RowOps | null): void;
28
- /** Test-only accounting probe: the live registration count must return to
29
- * baseline across register/unbind/demote cycles. @internal */
30
- export declare function patchCountForTests(): number;
31
- export declare function hasPatches(): boolean;
32
- export declare function registerPatch(record: any, fn: PatchFn): () => void;
33
- /** Dual-driver bind probe (compiler runtime contract): when `record` is a
34
- * patchable store record, returns its CURRENT raw backing (the driver's
35
- * initial force-apply reads it directly — no proxy traffic, no tracking);
36
- * returns undefined otherwise (driver falls back to the effect path).
37
- * Not patchable: non-records, non-proxies, accessor-bearing records
38
- * (patches read raw — getters need tracked evaluation), broken chains. */
39
- export declare function patchableRaw(record: any): Record<PropertyKey, any> | undefined;
40
- /** Accessor demotion (design §5): a record that acquires an accessor after
41
- * registration stops being patchable — reads must go through tracked
42
- * evaluation. Clears patches and repairs the global count; callers re-drive
43
- * the pulled bodies (demoteToEffects). */
44
- export declare function demotePatches(t: StoreNextTarget): PatchEntry[] | null;
45
- /** The demotion re-drive (re-audit blocker 3): each pulled body becomes the
46
- * SAME dual-driver effect fallback the web runtime would have chosen had the
47
- * record carried the accessor at bind — a tracked compute pass (next === prev
48
- * short-circuits every compare into a pure read THROUGH THE PROXY, so getter
49
- * dependencies track) plus an untracked force-apply at effect timing.
50
- *
51
- * Creation is DEFERRED to the effect phase: the trap that discovers the
52
- * accessor runs mid-draft, and an effect's initial pass must not read
53
- * through the proxy inside the write window. The record's own transition
54
- * for that draft is covered by the new effect's initial force-apply.
55
- *
56
- * Known edge (documented): a demoted LIST-ROW body re-drives under its
57
- * registering owner (the list owner), so per-row severing on removal is
58
- * lost for demoted rows — the effect lives until the LIST disposes. Rows
59
- * only demote when user code defines an accessor on a row record at
60
- * runtime. */
61
- export declare function demoteToEffects(t: StoreNextTarget): void;
62
- /** Structural ops for one keyed-array transition. `prefix` rows key-matched
63
- * in place; for each later index i (absolute), `sources[i - prefix]` is the
64
- * OLD index its row retained from, or -1 for a new row. `removed` holds the
65
- * dropped old row values (unbind/teardown handles). Aligned value ticks emit
66
- * NOTHING — ops exist only when structure changed. */
67
- export interface RowOps {
68
- prefix: number;
69
- sources: number[];
70
- removed: any[];
71
- }
72
- /** `ops === null` is the RESYNC form (optimistic revert): the consumer
73
- * rebuilds retention by row identity against `next` (the live view). */
74
- export type RowOpsFn = (next: any[], ops: RowOps | null) => void;
75
- /** Register a structural-ops consumer on a keyed store array (the list
76
- * container's channel — what `For` consumes through the seam). */
77
- export declare function registerRowOps(array: any, fn: RowOpsFn): () => void;
78
- /** Slot patches (shallow arrays) ride the same apply queue: the walk emits
79
- * per aligned value-replaced slot; application happens at effect phase under
80
- * the registration owner's lifetime. */
81
- export declare function emitSlotPatch(t: StoreNextTarget, index: number, next: any, prev: any): void;
82
- /** Slot patch for shallow arrays: the reconcile walk emits (index, next,
83
- * prev) for KEY-ALIGNED value-replaced slots (structure rides row ops), and
84
- * the emission queues through the patch apply queue — effect-phase timing,
85
- * transition stamping, disposed-owner drop — like every other channel. */
86
- export declare function registerSlotPatchNext(arr: any, fn: (index: number, next: any, prev: any) => void): () => void;
87
- /** Row-ops ride the SAME apply queue/timing as record patches: transition-
88
- * stamped, applied at effect phase, in emission order (structure before the
89
- * new rows' own patches can exist; retained rows' value patches commute). */
90
- export declare function emitRowOps(t: StoreNextTarget, next: any[], ops: RowOps): void;
91
- export {};
@@ -1,47 +0,0 @@
1
- import type { Accessor } from "./signals.cjs";
2
- import { type Store } from "./store/store.cjs";
3
- /**
4
- * Declares that in-flight work will change the targeted data: the named
5
- * slot(s) — and everything DERIVED from them — read as pending
6
- * (`isPending` → `true`) from the declaration until the surrounding
7
- * transaction settles or reverts. A mark lives on its own channel — a
8
- * refcount on the marked node plus dep-graph reachability in the verdict
9
- * layer — so the marked values themselves stay readable (a mark is a promise
10
- * of change, not an absence of value), no reader ever suspends on one, and
11
- * completion/settlement accounting never sees one. This is the declaration
12
- * verb of the pending model — additive only. A mark can turn pending ON for
13
- * data the graph can't see changing yet; nothing can turn pending OFF while
14
- * a real change is in flight — a quiet `refresh()` re-ask under a mark still
15
- * reads pending (declaring the reload is what makes it a real question).
16
- *
17
- * Targets:
18
- * - `affects(store)` — a store proxy (any record, root or nested): every
19
- * record reachable from it at declaration time reads pending, including
20
- * through captured child proxies (e.g. `<For>` rows). Siblings are
21
- * untouched; records added after the declaration are not covered.
22
- * - `affects(record, key)` — exactly the named slot of the record. One key
23
- * per call (keys do NOT form a path — target the owning record directly).
24
- * - `affects(accessor)` — a source accessor (signal or memo): the source
25
- * reads pending.
26
- *
27
- * Typically called at the top of an `action` alongside optimistic writes —
28
- * both are up-front declarations about the same mutation. Outside any
29
- * transaction the mark is released at the end of the current flush.
30
- *
31
- * @example
32
- * ```ts
33
- * const send = action(function* (text: string) {
34
- * setState(s => { s.messages.push({ text, status: "sending" }); });
35
- * affects(state.messages.at(-1)!, "status"); // this slot pends until settle
36
- * yield api.send(text);
37
- * });
38
- *
39
- * const reload = action(function* () {
40
- * affects(thing); // the whole store pends…
41
- * refresh(thing); // …over this otherwise-quiet re-ask
42
- * yield api.done();
43
- * });
44
- * ```
45
- */
46
- export declare function affects(target: Accessor<unknown> | Store<object>): void;
47
- export declare function affects<T extends object>(target: Store<T>, key: keyof T): void;
@@ -1,175 +0,0 @@
1
- import { Queue, type Computed, type Effect } from "./core/index.cjs";
2
- import type { Signal } from "./core/index.cjs";
3
- import { type Accessor } from "./signals.cjs";
4
- export interface BoundaryComputed<T> extends Computed<T> {
5
- _propagationMask: number;
6
- }
7
- type RevealSlot = CollectionQueue | RevealController;
8
- type BoolAccessor = () => boolean;
9
- export type RevealOrder = "sequential" | "together" | "natural";
10
- type OrderAccessor = () => RevealOrder;
11
- export declare class RevealController {
12
- _orderAccessor: OrderAccessor;
13
- _collapsedAccessor: BoolAccessor;
14
- _slots: RevealSlot[];
15
- _parentController?: RevealController;
16
- _disabled: Signal<boolean>;
17
- _collapsed: Signal<boolean>;
18
- _ready: boolean;
19
- _minimallyReady: boolean;
20
- _evaluating: boolean;
21
- constructor(order: OrderAccessor, collapsed: BoolAccessor);
22
- _forEachOwnedSlot(fn: (slot: RevealSlot) => boolean | void): boolean;
23
- _isReady(): boolean;
24
- /**
25
- * "Minimally ready" = this group has something visible to show under its own policy.
26
- * Used by an enclosing `together` group to decide when it can release.
27
- * - `together`: every direct slot is minimally ready.
28
- * - `sequential`: the first owned slot is minimally ready (frontier can advance).
29
- * - `natural`: any owned slot is minimally ready.
30
- */
31
- _isMinimallyReady(): boolean;
32
- _register(slot: RevealSlot): void;
33
- _unregister(slot: RevealSlot): void;
34
- _evaluate(disabledOverride?: boolean, collapsedOverride?: boolean): void;
35
- }
36
- export declare class CollectionQueue extends Queue {
37
- _collectionType: number;
38
- _sources: Set<Computed<any>>;
39
- _tree?: BoundaryComputed<any>;
40
- _pending: boolean;
41
- _disabled: Signal<boolean>;
42
- _error?: Signal<unknown>;
43
- _collapsed: Signal<boolean>;
44
- _revealController?: RevealController;
45
- _initialized: boolean;
46
- _onFn: (() => any) | undefined;
47
- _prevOn: any;
48
- constructor(type: number);
49
- run(type: number): void;
50
- notify(node: Effect<any>, type: number, flags: number, error?: any): boolean;
51
- _checkSources(): void;
52
- }
53
- /**
54
- * Lower-level primitive that backs the `<Loading>` flow control. Catches
55
- * pending async reads inside `fn` and renders `fallback` until they settle.
56
- *
57
- * App code should use `<Loading fallback={...}>` instead — reach for this only
58
- * when authoring custom boundary components.
59
- *
60
- * @param fn the tracked subtree
61
- * @param fallback the fallback shown while async reads in `fn` are unresolved
62
- * @param options `on` — accessor whose value scopes the boundary; when set,
63
- * transitions caused by writes to other reactive sources are *not* caught
64
- *
65
- * @example
66
- * ```tsx
67
- * // Custom boundary component built on top of the primitive.
68
- * function MyLoading(props: { fallback: JSX.Element; children: JSX.Element }) {
69
- * return createLoadingBoundary(
70
- * () => props.children,
71
- * () => props.fallback
72
- * ) as unknown as JSX.Element;
73
- * }
74
- * ```
75
- */
76
- export declare function createLoadingBoundary<T, U>(fn: () => T, fallback: () => U, options?: {
77
- on?: () => any;
78
- }): Accessor<T | U>;
79
- /**
80
- * Lower-level primitive that backs the `<Errored>` flow control. Catches
81
- * thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
82
- * `error` is an accessor for the latest captured error; `reset()` recomputes
83
- * the failing sources so the boundary can attempt to recover.
84
- *
85
- * App code should use `<Errored fallback={...}>` instead — reach for this only
86
- * when authoring custom boundary components.
87
- *
88
- * @example
89
- * ```tsx
90
- * // Custom boundary that wraps the primitive and adds telemetry.
91
- * function TracedErrored(props: { fallback: (e: () => unknown) => JSX.Element; children: JSX.Element }) {
92
- * return createErrorBoundary(
93
- * () => props.children,
94
- * (err, reset) => {
95
- * reportError(err());
96
- * return props.fallback(err);
97
- * }
98
- * ) as unknown as JSX.Element;
99
- * }
100
- * ```
101
- */
102
- export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error: Accessor<unknown>, reset: () => void) => U): Accessor<T | U>;
103
- /**
104
- * Coordinate the reveal timing of sibling loading boundaries.
105
- *
106
- * Accepts reactive accessors:
107
- * - `order`: `"sequential"` (default) | `"together"` | `"natural"`.
108
- * - `"sequential"` — classic frontier reveal: siblings reveal in registration order
109
- * as each resolves; later siblings stay hidden until earlier ones complete.
110
- * - `"together"` — every direct slot stays on its fallback until the whole group
111
- * is "minimally ready" (each direct slot has produced its own first visible
112
- * content under its own order), then the whole group releases at once.
113
- * - `"natural"` — children reveal independently (as each resolves). At the top
114
- * level this is a no-op compared to not using `createRevealOrder`; the mode
115
- * exists for nesting, where the group registers as a single composite slot to
116
- * any enclosing `createRevealOrder`.
117
- * - `collapsed`: only meaningful when `order === "sequential"`. When set, tail siblings
118
- * past the frontier suppress their own fallback output. Ignored under `"together"`
119
- * and `"natural"` — those orders have no frontier.
120
- *
121
- * Nested `createRevealOrder` groups compose: the inner controller registers as a
122
- * single slot in the outer controller and is held on its fallbacks until the outer
123
- * releases that slot. Once released, the inner controller runs its own order locally
124
- * over anything still pending. There is no opt-out from an outer hold.
125
- *
126
- * "Minimally ready" is what an order considers its first visible content:
127
- * - `sequential` — frontier-0 is minimally ready (leaf: on resolve; nested: via its
128
- * own minimal signal).
129
- * - `together` — every direct slot is minimally ready.
130
- * - `natural` — any direct slot has visible content (leaves on resolve; nested
131
- * composites via their own minimal signal).
132
- *
133
- * @example
134
- * ```ts
135
- * // Primitive form of `<Reveal>` — coordinate sibling loading boundaries
136
- * // programmatically. App code uses the JSX `<Reveal>` component instead.
137
- * // Both options are accessors so they can react to state changes.
138
- * createRevealOrder(
139
- * () => renderSiblings(),
140
- * { order: () => mode(), collapsed: () => true }
141
- * );
142
- * ```
143
- */
144
- export declare function createRevealOrder<T>(fn: () => T, options?: {
145
- order?: OrderAccessor;
146
- collapsed?: BoolAccessor;
147
- }): T;
148
- /**
149
- * Resolves a children value to its renderable form: unwraps zero-arg functions
150
- * (accessors), recursively flattens arrays, and optionally skips
151
- * non-rendering values (`null`, `undefined`, `true`, `false`, `""`).
152
- *
153
- * Used internally by flow components and by the renderer to walk a children
154
- * tree. App code rarely needs this directly — see `children()` in `solid-js`
155
- * for the user-facing helper that memoizes the result.
156
- *
157
- * @param children value or array of values to flatten
158
- * @param options
159
- * - `skipNonRendered` — drop values that won't render
160
- * - `doNotUnwrap` — leave function children as-is (caller will resolve)
161
- *
162
- * @example
163
- * ```ts
164
- * // Custom renderer walking a children tree manually. Most authors should
165
- * // use `children()` from solid-js, which memoizes the resolved value.
166
- * function renderChildren(value: unknown): unknown {
167
- * return flatten(value, { skipNonRendered: true });
168
- * }
169
- * ```
170
- */
171
- export declare function flatten(children: any, options?: {
172
- skipNonRendered?: boolean;
173
- doNotUnwrap?: boolean;
174
- }): any;
175
- export {};
@@ -1,64 +0,0 @@
1
- /**
2
- * The primitive for mutations: imperative async workflows whose *writes span
3
- * an async gap* — optimistic write, server round-trip, reconciling write —
4
- * where intermediate state must not leak and failure must revert cleanly
5
- * (pair with `createOptimistic` / `createOptimisticStore`).
6
- *
7
- * Navigation-shaped updates do not need an action. A plain setter call is
8
- * enough: reads pull the async, and downstream async computeds hold their
9
- * previous values per-node until the new ones are ready (`isPending` /
10
- * `latest` expose the in-flight state). Reach for `action` only when writes
11
- * happen *after* async work, not merely upstream of it.
12
- *
13
- * Framework-level actions (router form actions, server actions) are
14
- * specializations of this primitive: they are actions in exactly this sense —
15
- * the same transactional semantics — with form binding, serialization, and
16
- * submission tracking layered on top. The shared name is deliberate.
17
- *
18
- * Wraps a generator function so each invocation runs as a single transaction
19
- * (a "transition") that batches every signal/store write between yields. The
20
- * surrounding UI sees one atomic update per yielded step; nothing is committed
21
- * until the action either completes or the next `yield` resolves.
22
- *
23
- * `yield` is the transaction-safe suspension point: the action waits for a
24
- * yielded promise and re-enters the transaction before running the code after
25
- * it. A plain `await` does NOT — the runtime has no hook into an async
26
- * generator's internal await continuations, so writes to fresh signals
27
- * between an `await` and the next `yield` escape the transaction and commit
28
- * immediately. `await` is still the ergonomic choice for typed results; just
29
- * put a bare `yield` before any writes that follow it:
30
- *
31
- * ```ts
32
- * const saved = await api.createTodo(text); // typed result
33
- * yield; // re-enter the transaction before writing
34
- * setTodos(t => { ... });
35
- * ```
36
- *
37
- * (For the same reason, don't call `flush()` inside an action body — it
38
- * drains the transaction mid-step.)
39
- *
40
- * Each call returns a `Promise` that resolves with the generator's return
41
- * value, or rejects if it throws. Pair with `createOptimistic` /
42
- * `createOptimisticStore` to apply tentative writes that auto-revert if the
43
- * action fails.
44
- *
45
- * @example
46
- * ```ts
47
- * const [todos, setTodos] = createOptimisticStore<Todo[]>([]);
48
- *
49
- * const addTodo = action(async function* (text: string) {
50
- * const tempId = crypto.randomUUID();
51
- * setTodos(t => { t.push({ id: tempId, text, pending: true }); }); // optimistic
52
- * const saved = await api.createTodo(text); // network round-trip, typed
53
- * yield; // re-enter the transaction
54
- * setTodos(t => {
55
- * const i = t.findIndex(x => x.id === tempId);
56
- * if (i >= 0) t[i] = saved;
57
- * });
58
- * return saved;
59
- * });
60
- *
61
- * await addTodo("buy milk");
62
- * ```
63
- */
64
- export declare function action<Args extends any[], Y, R>(genFn: (...args: Args) => Generator<Y, R, any> | AsyncGenerator<Y, R, any>): (...args: Args) => Promise<R>;
@@ -1,23 +0,0 @@
1
- import { NotReadyError } from "./error.cjs";
2
- import { type OptimisticLane } from "./lanes.cjs";
3
- import type { Computed, Link } from "./types.cjs";
4
- export declare function addPendingSource(el: Computed<any>, source: Computed<any>): boolean;
5
- /**
6
- * A loading-window node hit an unready source (sync throw in recompute, or a
7
- * NotReadyError-rejected flight): register for the source's settle — the
8
- * settlePendingSource walk runs off `_pendingSources` + `_blocked` alone —
9
- * with NO read-visible pending status, no downstream propagation, no
10
- * transition, no lane registration. Commit #0 keeps serving.
11
- */
12
- export declare function parkLoadingWindow(el: Computed<any>, e: NotReadyError): void;
13
- export declare function setPendingError(el: Computed<any>, source?: Computed<any>, error?: any): void;
14
- export declare function forEachDependent(el: Computed<any>, fn: (node: Computed<any>, link: Link) => void): void;
15
- export declare function releaseSettledDependents(el: Computed<any>): void;
16
- export declare function settleErroredDependents(el: Computed<any>, error: any): void;
17
- export declare function settlePendingSource(el: Computed<any>): void;
18
- export declare function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T>;
19
- /** Fire and clear a node's iterator-flight cancellation hook (#3122). */
20
- export declare function releaseFlightTeardown(el: Computed<any>): void;
21
- export declare function handleAsync<T>(el: Computed<T>, result: T | PromiseLike<T> | AsyncIterable<T>, setter?: (value: T) => void): T;
22
- export declare function clearStatus(el: Computed<any>, clearUninitialized?: boolean): void;
23
- export declare function notifyStatus(el: Computed<any>, status: number, error: any, blockStatus?: boolean, lane?: OptimisticLane): void;
@@ -1,63 +0,0 @@
1
- import type { Computed, Signal } from "./types.cjs";
2
- /**
3
- * Dev-only observability hook points for the reactive core.
4
- *
5
- * Core's obligation is to call these with true facts at the moments they
6
- * happen; ALL attribution semantics (stamps, cause chains, timings, warnings)
7
- * live in the engine that installs them (attribution.ts — same pattern as the
8
- * GlobalQueue._* feature slots). `attrHooks` is null unless an engine is
9
- * installed, so the disabled cost is one null check per site, and prod builds
10
- * fold every site out behind __DEV__.
11
- *
12
- * IMPORTANT for implementers of call sites: a hook call must never sit inside
13
- * a `try` block — rollup's tryCatchDeoptimization retains functions referenced
14
- * inside `try` even behind a folded __DEV__ guard, which re-couples the dev
15
- * engine into prod bundles (#2883 harness). Set a local flag inside the try
16
- * and call the hook after the catch.
17
- */
18
- export interface AttributionHooks {
19
- /**
20
- * A recompute is starting; `el._deps` still holds the previous run's links.
21
- * Always paired with `recomputeEnd` (recompute has no early returns).
22
- */
23
- recomputeStart(el: Computed<any>, create: boolean): void;
24
- /**
25
- * The recompute finished. `changed` = committed a changed value (false for
26
- * errored runs); `optimistic` = ran under an optimistic lane / lane-dirty
27
- * posture; `transition` = a transition was active or owns this node;
28
- * `held` = the value went to `_pendingValue` (a transition hold) rather
29
- * than committing directly — its reveal happens later on the transition's
30
- * own schedule.
31
- */
32
- recomputeEnd(el: Computed<any>, create: boolean, changed: boolean, optimistic: boolean, transition: boolean, held: boolean): void;
33
- /** A non-effect computed committed a changed value during a re-run. */
34
- derivedChanged(el: Computed<any>): void;
35
- /** A signal write committed (value passed the equality gate). */
36
- write(el: Signal<any> | Computed<any>, prev: unknown, value: unknown): void;
37
- /** refresh() invalidated this node (self-invalidation, no dep changed). */
38
- refreshed(el: Computed<any>): void;
39
- /**
40
- * A new async flight entered the system (`_inFlight` was just assigned
41
- * during a recompute of `el`). Always fired inside the owning recompute —
42
- * both call paths (core's recompute and the projection self-registration)
43
- * run within one — so the engine can read the current frame stack to link
44
- * the flight to the change that caused it (waterfall chaining). `flight`
45
- * is the registered thenable/iterable itself: the engine keys a first-seen
46
- * origin registry on its identity, so shared and preloader-marked promises
47
- * carry their true start time instead of the moment the graph saw them.
48
- */
49
- flightStart(el: Computed<any>, flight: object): void;
50
- /** An async landing is about to apply its value (before any branch). */
51
- asyncStart(el: Computed<any>): void;
52
- /**
53
- * The async landing finished. `direct` = the landing applies the value
54
- * itself (lane/override paths); false = it went through setSignal, whose
55
- * own `write` hook already saw any committed change. Fired whether or not
56
- * the landing committed — call sites cannot carry that fact out of their
57
- * try blocks (see the try rule above), so the engine derives committed-ness
58
- * from the node's state against its asyncStart snapshot.
59
- */
60
- asyncEnd(el: Computed<any>, prev: unknown, value: unknown, direct: boolean): void;
61
- }
62
- export declare let attrHooks: AttributionHooks | null;
63
- export declare function setAttributionHooks(hooks: AttributionHooks | null): void;