@solidjs/signals 2.0.0-rc.2 → 2.0.0-rc.20

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 (198) hide show
  1. package/dist/dev-shared.js +6505 -0
  2. package/dist/dev.attribution.js +3484 -0
  3. package/dist/dev.js +10227 -9508
  4. package/dist/observe/affects-marks.js +86 -0
  5. package/dist/observe/affects.js +112 -0
  6. package/dist/observe/attribution.js +7 -0
  7. package/dist/observe/boundaries.js +696 -0
  8. package/dist/observe/core/action.js +182 -0
  9. package/dist/observe/core/async.js +824 -0
  10. package/dist/observe/core/attribution-costs.js +66 -0
  11. package/dist/observe/core/attribution-feedback.js +280 -0
  12. package/dist/observe/core/attribution-hooks.js +83 -0
  13. package/dist/observe/core/attribution-queries.js +43 -0
  14. package/dist/observe/core/attribution.js +3079 -0
  15. package/dist/observe/core/constants.js +269 -0
  16. package/dist/observe/core/context.js +63 -0
  17. package/dist/observe/core/copies.js +10 -0
  18. package/dist/observe/core/core.js +1707 -0
  19. package/dist/observe/core/dev.js +394 -0
  20. package/dist/observe/core/effect.js +193 -0
  21. package/dist/observe/core/error-hooks.js +71 -0
  22. package/dist/observe/core/error.js +82 -0
  23. package/dist/observe/core/external.js +97 -0
  24. package/dist/observe/core/graph.js +162 -0
  25. package/dist/observe/core/heap.js +124 -0
  26. package/dist/observe/core/identities.js +62 -0
  27. package/dist/observe/core/invariants.js +12 -0
  28. package/dist/observe/core/lanes.js +972 -0
  29. package/dist/observe/core/owner.js +371 -0
  30. package/dist/observe/core/scheduler.js +1157 -0
  31. package/dist/observe/core/truth.js +47 -0
  32. package/dist/observe/core/verdict.js +470 -0
  33. package/dist/observe/deferred.js +186 -0
  34. package/dist/observe/flatten.js +79 -0
  35. package/dist/observe/from.js +248 -0
  36. package/dist/observe/index.js +71 -0
  37. package/dist/observe/map.js +593 -0
  38. package/dist/observe/reveal.js +212 -0
  39. package/dist/observe/signals.js +717 -0
  40. package/dist/observe/store/affects.js +142 -0
  41. package/dist/observe/store/edges.js +39 -0
  42. package/dist/observe/store/hooks.js +16 -0
  43. package/dist/observe/store/index.js +47 -0
  44. package/dist/observe/store/optimistic.js +713 -0
  45. package/dist/observe/store/projection.js +345 -0
  46. package/dist/observe/store/reconcile.js +281 -0
  47. package/dist/observe/store/store.js +2127 -0
  48. package/dist/observe/store/storePath.js +103 -0
  49. package/dist/observe/store/target.js +46 -0
  50. package/dist/observe/store/types.js +83 -0
  51. package/dist/observe/store/utils.js +1063 -0
  52. package/dist/prod/affects-marks.js +86 -0
  53. package/dist/prod/affects.js +98 -112
  54. package/dist/prod/attribution.js +45 -0
  55. package/dist/prod/boundaries.js +578 -468
  56. package/dist/prod/core/action.js +92 -59
  57. package/dist/prod/core/async.js +522 -336
  58. package/dist/prod/core/attribution-hooks.js +3 -0
  59. package/dist/prod/core/constants.js +168 -44
  60. package/dist/prod/core/context.js +12 -16
  61. package/dist/prod/core/copies.js +10 -0
  62. package/dist/prod/core/core.js +1345 -627
  63. package/dist/prod/core/dev.js +123 -1
  64. package/dist/prod/core/effect.js +113 -80
  65. package/dist/prod/core/error-hooks.js +71 -0
  66. package/dist/prod/core/error.js +18 -4
  67. package/dist/prod/core/external.js +6 -7
  68. package/dist/prod/core/graph.js +119 -72
  69. package/dist/prod/core/heap.js +85 -109
  70. package/dist/prod/core/identities.js +62 -0
  71. package/dist/prod/core/invariants.js +1 -32
  72. package/dist/prod/core/lanes.js +931 -132
  73. package/dist/prod/core/owner.js +192 -129
  74. package/dist/prod/core/scheduler.js +948 -642
  75. package/dist/prod/core/truth.js +47 -0
  76. package/dist/prod/core/verdict.js +409 -420
  77. package/dist/prod/deferred.js +184 -0
  78. package/dist/prod/flatten.js +77 -0
  79. package/dist/prod/from.js +248 -0
  80. package/dist/prod/index.js +40 -16
  81. package/dist/prod/map.js +481 -211
  82. package/dist/prod/reveal.js +212 -0
  83. package/dist/prod/signals.js +401 -84
  84. package/dist/prod/store/affects.js +142 -0
  85. package/dist/prod/store/edges.js +39 -0
  86. package/dist/prod/store/hooks.js +16 -0
  87. package/dist/prod/store/index.js +27 -18
  88. package/dist/prod/store/optimistic.js +707 -0
  89. package/dist/prod/store/projection.js +331 -0
  90. package/dist/prod/store/reconcile.js +281 -0
  91. package/dist/prod/store/store.js +1952 -267
  92. package/dist/prod/store/storePath.js +1 -1
  93. package/dist/prod/store/target.js +43 -0
  94. package/dist/prod/store/types.js +83 -0
  95. package/dist/prod/store/utils.js +997 -138
  96. package/dist/types/affects-marks.d.ts +14 -0
  97. package/dist/types/affects.d.ts +12 -30
  98. package/dist/types/attribution.d.ts +19 -0
  99. package/dist/types/attribution.prod.d.ts +22 -0
  100. package/dist/types/boundaries.d.ts +99 -124
  101. package/dist/types/carved.d.ts +1 -0
  102. package/dist/types/core/action.d.ts +23 -9
  103. package/dist/types/core/async.d.ts +34 -6
  104. package/dist/types/core/attribution-costs.d.ts +35 -0
  105. package/dist/types/core/attribution-feedback.d.ts +133 -0
  106. package/dist/types/core/attribution-hooks.d.ts +307 -8
  107. package/dist/types/core/attribution-queries.d.ts +24 -0
  108. package/dist/types/core/attribution.d.ts +802 -72
  109. package/dist/types/core/constants.d.ts +195 -38
  110. package/dist/types/core/copies.d.ts +54 -0
  111. package/dist/types/core/core.d.ts +295 -65
  112. package/dist/types/core/dev.d.ts +509 -22
  113. package/dist/types/core/effect.d.ts +1 -1
  114. package/dist/types/core/error-hooks.d.ts +71 -0
  115. package/dist/types/core/error.d.ts +18 -1
  116. package/dist/types/core/graph.d.ts +40 -1
  117. package/dist/types/core/heap.d.ts +5 -5
  118. package/dist/types/core/identities.d.ts +17 -0
  119. package/dist/types/core/index.d.ts +11 -7
  120. package/dist/types/core/invariants.d.ts +1 -26
  121. package/dist/types/core/lanes.d.ts +74 -43
  122. package/dist/types/core/owner.d.ts +27 -9
  123. package/dist/types/core/scheduler.d.ts +353 -102
  124. package/dist/types/core/truth.d.ts +18 -0
  125. package/dist/types/core/types.d.ts +97 -71
  126. package/dist/types/core/verdict.d.ts +35 -0
  127. package/dist/types/deferred.d.ts +28 -0
  128. package/dist/types/flatten.d.ts +8 -0
  129. package/dist/types/from.d.ts +47 -0
  130. package/dist/types/index.d.ts +33 -7
  131. package/dist/types/map.d.ts +4 -2
  132. package/dist/types/reveal.d.ts +19 -0
  133. package/dist/types/signals.d.ts +196 -45
  134. package/dist/types/store/affects.d.ts +12 -0
  135. package/dist/types/store/edges.d.ts +9 -0
  136. package/dist/types/store/hooks.d.ts +62 -0
  137. package/dist/types/store/index.d.ts +42 -15
  138. package/dist/types/store/optimistic.d.ts +24 -45
  139. package/dist/types/store/projection.d.ts +17 -68
  140. package/dist/types/store/reconcile.d.ts +3 -46
  141. package/dist/types/store/store.d.ts +133 -136
  142. package/dist/types/store/storePath.d.ts +1 -1
  143. package/dist/types/store/target.d.ts +166 -0
  144. package/dist/types/store/types.d.ts +105 -0
  145. package/dist/types/store/utils.d.ts +188 -0
  146. package/package.json +31 -26
  147. package/dist/node.cjs +0 -8745
  148. package/dist/prod/core/optimistic.js +0 -265
  149. package/dist/prod/store/next/optimistic.js +0 -385
  150. package/dist/prod/store/next/projection.js +0 -172
  151. package/dist/prod/store/next/reconcile.js +0 -331
  152. package/dist/prod/store/next/store.js +0 -1499
  153. package/dist/prod/store/next/target.js +0 -20
  154. package/dist/types/core/optimistic.d.ts +0 -6
  155. package/dist/types/store/next/optimistic.d.ts +0 -20
  156. package/dist/types/store/next/projection.d.ts +0 -8
  157. package/dist/types/store/next/reconcile.d.ts +0 -3
  158. package/dist/types/store/next/store.d.ts +0 -77
  159. package/dist/types/store/next/target.d.ts +0 -117
  160. package/dist/types-cjs/affects.d.cts +0 -47
  161. package/dist/types-cjs/boundaries.d.cts +0 -175
  162. package/dist/types-cjs/core/action.d.cts +0 -64
  163. package/dist/types-cjs/core/async.d.cts +0 -21
  164. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -52
  165. package/dist/types-cjs/core/attribution.d.cts +0 -186
  166. package/dist/types-cjs/core/constants.d.cts +0 -97
  167. package/dist/types-cjs/core/context.d.cts +0 -36
  168. package/dist/types-cjs/core/core.d.cts +0 -163
  169. package/dist/types-cjs/core/dev.d.cts +0 -81
  170. package/dist/types-cjs/core/effect.d.cts +0 -30
  171. package/dist/types-cjs/core/error.d.cts +0 -47
  172. package/dist/types-cjs/core/external.d.cts +0 -15
  173. package/dist/types-cjs/core/graph.d.cts +0 -6
  174. package/dist/types-cjs/core/heap.d.cts +0 -22
  175. package/dist/types-cjs/core/index.d.cts +0 -13
  176. package/dist/types-cjs/core/invariants.d.cts +0 -59
  177. package/dist/types-cjs/core/lanes.d.cts +0 -44
  178. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  179. package/dist/types-cjs/core/owner.d.cts +0 -124
  180. package/dist/types-cjs/core/scheduler.d.cts +0 -180
  181. package/dist/types-cjs/core/types.d.cts +0 -192
  182. package/dist/types-cjs/core/verdict.d.cts +0 -2
  183. package/dist/types-cjs/index.d.cts +0 -10
  184. package/dist/types-cjs/map.d.cts +0 -69
  185. package/dist/types-cjs/package.json +0 -3
  186. package/dist/types-cjs/signals.d.cts +0 -624
  187. package/dist/types-cjs/store/index.d.cts +0 -19
  188. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  189. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  190. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  191. package/dist/types-cjs/store/next/store.d.cts +0 -77
  192. package/dist/types-cjs/store/next/target.d.cts +0 -117
  193. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  194. package/dist/types-cjs/store/projection.d.cts +0 -70
  195. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  196. package/dist/types-cjs/store/store.d.cts +0 -138
  197. package/dist/types-cjs/store/storePath.d.cts +0 -58
  198. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -0,0 +1,142 @@
1
+ import { GlobalQueue, releaseMarksHook } from "../core/scheduler.js";
2
+
3
+ import { optHooks, installAffectsHooks } from "./hooks.js";
4
+
5
+ import { lookupTarget, $OWNER } from "./target.js";
6
+
7
+ import { $TARGET } from "./types.js";
8
+
9
+ /**
10
+ * Store — the store half of `affects()` (plan sec. 29, plan sec. 37; A24 (4), #2882,
11
+ * #2893, #2904).
12
+ *
13
+ * A mark on a store is a mark on nodes (affects.ts: a count on the node, a
14
+ * dependency walk at probe time): `affects(record, key)` marks the slot's
15
+ * leaf; `affects(record)` marks a carrier (the record's `$AFFECTS` leaf)
16
+ * and every live node in the record's subtree — the edges existing readers
17
+ * subscribed through. Coverage is by RAW IDENTITY, not read path (#2882: a
18
+ * captured row proxy, a derived store sharing the source's raw, never read
19
+ * through the declaration's proxy): the identities reachable at the
20
+ * declaration are the mark's `scope`, so a node born inside the window on
21
+ * a covered record inherits the mark (released with the carrier's last),
22
+ * and an untracked probe through a record with no nodes is witnessed into
23
+ * the verdict. A mark declared on a draft (inside a setter) or over an
24
+ * optimistic family walks the view the writer sees.
25
+ *
26
+ * Imported by `affects()`, which installs it on its first store target
27
+ * (#3891, after #3912): a program with stores that never declares a mark
28
+ * carries none of it. It never imports store.ts — the engine's top level —
29
+ * so a program declaring marks without stores carries this module alone:
30
+ * the store's nodes and its wrappability test come through `GlobalQueue`
31
+ * (`_storeNode`, `_storeWrappable`), and node birth and the untracked traps
32
+ * reach back through `affectsHooks` (hooks.ts).
33
+ */
34
+ /** The keyless mark's carrier key: a leaf of the record no read serves. */ const $AFFECTS = Symbol(0);
35
+
36
+ const scopes = new Map;
37
+
38
+ function scopeOf(e, o) {
39
+ let n = scopes.get(e);
40
+ if (n === undefined) scopes.set(e, n = {
41
+ oo: new Set,
42
+ no: [],
43
+ gt: o
44
+ });
45
+ return n;
46
+ }
47
+
48
+ /** The nodes an `affects(store[, key])` declaration marks (affects.ts
49
+ * registers each). */ function storeMarks(e, o) {
50
+ const n = GlobalQueue.so(e, o === undefined ? $AFFECTS : o);
51
+ const t = scopeOf(n, o);
52
+ if (o === undefined) {
53
+ const o = [ n ];
54
+ walk(e.px, t, o, e.fam, new Set);
55
+ return o;
56
+ }
57
+ t.oo.add(e.v);
58
+ if (e.pb !== null) t.oo.add(e.pb);
59
+ return [ n ];
60
+ }
61
+
62
+ /** The identities reachable from `value` into the scope (the draft's and
63
+ * the committed backing both, when a draft is open; an optimistic family's
64
+ * view), every live node under each record into `found`. Untracked by
65
+ * construction: raws, never traps. */ function walk(e, o, n, t, s) {
66
+ if (!GlobalQueue.fo(e)) return;
67
+ const f = e[$TARGET] ?? lookupTarget(e, t);
68
+ let r = f !== undefined ? f.pb ?? f.v : e;
69
+ if (s.has(r)) return;
70
+ s.add(r);
71
+ o.oo.add(r);
72
+ if (f !== undefined) {
73
+ if (f.pb !== null) o.oo.add(f.v);
74
+ // The writer's view: the tick's own unflushed guesses are in motion too.
75
+ if (optHooks && f.fam?.opt === true) r = optHooks.view(f, r, true);
76
+ const e = f.n;
77
+ if (e !== null) for (const o of Reflect.ownKeys(e))
78
+ // Another mark's carrier is its own channel: counting it here would
79
+ // extend that scope's lifetime to this declaration's.
80
+ if (o !== $AFFECTS) n.push(e[o]);
81
+ const s = f.h;
82
+ if (s !== null) for (const e of Reflect.ownKeys(s)) n.push(s[e]);
83
+ if (f.k !== null) n.push(f.k);
84
+ if (f.dk !== null) n.push(f.dk);
85
+ t = f.fam ?? t;
86
+ }
87
+ for (const e of Reflect.ownKeys(r)) if (e !== $OWNER) {
88
+ const f = Object.getOwnPropertyDescriptor(r, e);
89
+ if (f.get === undefined) walk(f.value, o, n, t, s);
90
+ }
91
+ }
92
+
93
+ /** A live scope covering `t`'s identity (keyed: for `key`). Chained
94
+ * backings (§7b): a view's backing is another store's proxy — marks cover
95
+ * the BASE raw, so every identity along the chain is checked. */ function covering(e, o, n) {
96
+ for (const [t, s] of scopes) {
97
+ if (t === n || s.gt !== undefined && s.gt !== o) continue;
98
+ for (let o = e.v; ;) {
99
+ if (s.oo.has(o)) return t;
100
+ const e = o?.[$TARGET];
101
+ if (e === undefined) break;
102
+ const n = e.pb ?? e.v;
103
+ if (n === o) break;
104
+ o = n;
105
+ }
106
+ }
107
+ return null;
108
+ }
109
+
110
+ /** The store's side: node birth and the untracked traps call it (store.ts,
111
+ * through `affectsHooks`) — with no live mark too: an empty scope map is
112
+ * no work. */ const hooks = {
113
+ // A node born on a record a live mark covers inherits it (released with
114
+ // the carrier's last registration).
115
+ ro(e, o, n) {
116
+ if (scopes.size === 0 || n === $AFFECTS) return;
117
+ const t = covering(e, n, o);
118
+ if (!t) return;
119
+ GlobalQueue.N(o);
120
+ scopes.get(t).no.push(o);
121
+ },
122
+ // An untracked probe (`isPending(() => s.x)` with no observer) reading a
123
+ // record a live mark covers: no node carries the mark for it — the
124
+ // verdict is told directly.
125
+ io(e, o) {
126
+ if (e.n?.[$AFFECTS]?.T?.I || covering(e, o)) GlobalQueue.bt();
127
+ }
128
+ };
129
+
130
+ /** `affects()` calls it before a store-targeted declaration (idempotent). */ function installStoreAffects() {
131
+ installAffectsHooks(hooks);
132
+ }
133
+
134
+ /** The carrier's last mark released (affects.ts): its scope dies, and the
135
+ * nodes that inherited the mark release theirs. */ function releaseMarkScope(e) {
136
+ const o = scopes.get(e);
137
+ if (o === undefined) return;
138
+ scopes.delete(e);
139
+ releaseMarksHook(o.no);
140
+ }
141
+
142
+ export { installStoreAffects, releaseMarkScope, storeMarks };
@@ -0,0 +1,39 @@
1
+ import { CONFIG_SLOT_NODE } from "../core/constants.js";
2
+
3
+ import { signalName } from "../core/identities.js";
4
+
5
+ import { $TARGET } from "./types.js";
6
+
7
+ /**
8
+ * Deferred hydration, dependency edges for stores. Only the frames client
9
+ * imports this module, so nothing here ships without it.
10
+ *
11
+ * A plain store root (`createStore` over an object) is named like a plain
12
+ * signal (core/identities.ts: `<owner id>~<n>`, on the same count), and the
13
+ * whole store goes by that one name: the server records it for any read of
14
+ * the store, at any depth, and a setter call on the store — on its root or
15
+ * on a proxy nested in it — is a write to it. Its readers mount at the
16
+ * setter's entry, before the draft runs, as a plain signal's do.
17
+ */
18
+ /**
19
+ * @internal The name of the store `x` belongs to — `x` a store proxy (a
20
+ * setter's entry) or one of its property nodes (the setter notifying it) —
21
+ * or undefined when it has none or it cannot be placed: a projection or
22
+ * optimistic family, a store chained over another store's proxy, a root
23
+ * named twice, or a proxy reached through a store other than the one it
24
+ * was named as the root of.
25
+ */ function storeName(e) {
26
+ if (e === undefined) return undefined;
27
+ let n = e.l & CONFIG_SLOT_NODE ? e.O : e[$TARGET];
28
+ if (n === undefined) return undefined;
29
+ // Up to the root; a target on the way named as a root of its own is one
30
+ // object in two stores.
31
+ while (n.u !== null) {
32
+ if (n.fam !== null || n.ch || signalName(n) !== undefined) return undefined;
33
+ n = n.u;
34
+ }
35
+ if (n.fam !== null || n.ch) return undefined;
36
+ return signalName(n) || undefined;
37
+ }
38
+
39
+ export { storeName };
@@ -0,0 +1,16 @@
1
+ // Set before any family is optimistic (`fam.opt`): a call site checks the
2
+ // hooks first, so a build that does not import optimistic.ts folds the arm
3
+ // away.
4
+ let optHooks = null;
5
+
6
+ function installOptHooks(o) {
7
+ optHooks = o;
8
+ }
9
+
10
+ let affectsHooks = null;
11
+
12
+ function installAffectsHooks(o) {
13
+ affectsHooks = o;
14
+ }
15
+
16
+ export { affectsHooks, installAffectsHooks, installOptHooks, optHooks };
@@ -0,0 +1,47 @@
1
+ import { createStore as createStore$1, deep as deep$1, snapshot as snapshot$1 } from "./store.js";
2
+
3
+ export { storeHasFamily, storeHasOptimisticFamily, storeIsShallow } from "./store.js";
4
+
5
+ export { createOptimisticStore } from "./optimistic.js";
6
+
7
+ import { createStoreDerived } from "./projection.js";
8
+
9
+ export { createProjection } from "./projection.js";
10
+
11
+ import { reconcileState } from "./reconcile.js";
12
+
13
+ import "../core/verdict.js";
14
+
15
+ import "../core/core.js";
16
+
17
+ import "../core/dev.js";
18
+
19
+ import "../core/scheduler.js";
20
+
21
+ import "../core/effect.js";
22
+
23
+ import "../core/lanes.js";
24
+
25
+ function createStore(e, r, t) {
26
+ if (typeof e === "function") return createStoreDerived(e, r, t);
27
+ return createStore$1(e, r);
28
+ }
29
+
30
+ /**
31
+ * A setter transform that reconciles `value` into the store by key
32
+ * (`"id"` by default; `null` positional), preserving store identity for
33
+ * surviving rows.
34
+ */ function reconcile(e, r = "id") {
35
+ return t => reconcileState(e, t, r);
36
+ }
37
+
38
+ /** Non-tracking snapshot of a store's current value (source identity for
39
+ * unmodified subtrees). */ function snapshot(e) {
40
+ return snapshot$1(e);
41
+ }
42
+
43
+ /** Tracking snapshot: subscribes to every reachable record. */ function deep(e) {
44
+ return deep$1(e);
45
+ }
46
+
47
+ export { createStore, deep, reconcile, snapshot };