@solidjs/signals 2.0.0-rc.14 → 2.0.0-rc.15

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 (66) hide show
  1. package/dist/dev-shared.js +248 -189
  2. package/dist/dev.attribution.js +124 -41
  3. package/dist/dev.js +553 -322
  4. package/dist/observe/affects.js +34 -31
  5. package/dist/observe/boundaries.js +166 -132
  6. package/dist/observe/core/async.js +90 -83
  7. package/dist/observe/core/attribution-queries.js +1 -1
  8. package/dist/observe/core/attribution.js +281 -197
  9. package/dist/observe/core/constants.js +7 -2
  10. package/dist/observe/core/context.js +3 -3
  11. package/dist/observe/core/core.js +277 -245
  12. package/dist/observe/core/dev.js +3 -3
  13. package/dist/observe/core/effect.js +21 -21
  14. package/dist/observe/core/external.js +2 -2
  15. package/dist/observe/core/graph.js +25 -25
  16. package/dist/observe/core/heap.js +9 -9
  17. package/dist/observe/core/lanes.js +206 -160
  18. package/dist/observe/core/owner.js +27 -27
  19. package/dist/observe/core/scheduler.js +92 -86
  20. package/dist/observe/core/verdict.js +66 -54
  21. package/dist/observe/map.js +35 -35
  22. package/dist/observe/reveal.js +24 -24
  23. package/dist/observe/signals.js +38 -28
  24. package/dist/observe/store/affects.js +75 -68
  25. package/dist/observe/store/hooks.js +13 -0
  26. package/dist/observe/store/index.js +0 -2
  27. package/dist/observe/store/optimistic.js +67 -34
  28. package/dist/observe/store/projection.js +37 -31
  29. package/dist/observe/store/reconcile.js +32 -30
  30. package/dist/observe/store/store.js +128 -85
  31. package/dist/prod/affects.js +34 -31
  32. package/dist/prod/boundaries.js +143 -109
  33. package/dist/prod/core/async.js +64 -67
  34. package/dist/prod/core/constants.js +7 -2
  35. package/dist/prod/core/context.js +3 -3
  36. package/dist/prod/core/core.js +302 -270
  37. package/dist/prod/core/effect.js +38 -38
  38. package/dist/prod/core/external.js +4 -4
  39. package/dist/prod/core/graph.js +27 -27
  40. package/dist/prod/core/heap.js +30 -30
  41. package/dist/prod/core/lanes.js +257 -211
  42. package/dist/prod/core/owner.js +39 -39
  43. package/dist/prod/core/scheduler.js +125 -119
  44. package/dist/prod/core/verdict.js +70 -58
  45. package/dist/prod/map.js +73 -73
  46. package/dist/prod/reveal.js +38 -38
  47. package/dist/prod/signals.js +30 -20
  48. package/dist/prod/store/affects.js +75 -68
  49. package/dist/prod/store/hooks.js +13 -0
  50. package/dist/prod/store/index.js +0 -2
  51. package/dist/prod/store/optimistic.js +114 -81
  52. package/dist/prod/store/projection.js +30 -24
  53. package/dist/prod/store/reconcile.js +32 -30
  54. package/dist/prod/store/store.js +136 -93
  55. package/dist/types/boundaries.d.ts +4 -0
  56. package/dist/types/core/attribution.d.ts +6 -2
  57. package/dist/types/core/constants.d.ts +5 -0
  58. package/dist/types/core/core.d.ts +33 -3
  59. package/dist/types/core/lanes.d.ts +10 -0
  60. package/dist/types/core/scheduler.d.ts +12 -6
  61. package/dist/types/core/types.d.ts +0 -6
  62. package/dist/types/store/affects.d.ts +11 -0
  63. package/dist/types/store/hooks.d.ts +48 -0
  64. package/dist/types/store/index.d.ts +0 -1
  65. package/dist/types/store/store.d.ts +3 -38
  66. package/package.json +1 -1
@@ -18,7 +18,7 @@ import { wrap, nameStore, storeSetter, runDirect } from "./store.js";
18
18
 
19
19
  import { setLookup } from "./target.js";
20
20
 
21
- import { $TARGET, markRawIngest, setWriteOverride } from "./types.js";
21
+ import { $TARGET, markRawIngest, setWriteOverride, isWrappable } from "./types.js";
22
22
 
23
23
  /**
24
24
  * Store — projections (plan sec. 31, S3; INTERNALS §7/§7b).
@@ -178,33 +178,33 @@ function forEachFamilyNode(e, t) {
178
178
  const s = e[$TARGET];
179
179
  const c = s.fam;
180
180
  const u = c.run = (c.run || 0) + 1;
181
- let a;
181
+ let l;
182
182
  // Open loading window (seedLoadingValue): the observable store IS commit #0
183
183
  // for the whole first flight — the derive works a detached shadow of the
184
184
  // seed so draft writes cannot tear through to readers (#2988). Every
185
185
  // commit point reconciles the shadow through the normal commit path.
186
- const l = i._e ? cloneState(s.v, s.s) : null;
186
+ const a = i.De ? cloneState(s.v, s.s) : null;
187
187
  // The question a write of this run answers: inside a slice, the slice's
188
188
  // (the sync pass); in a continuation — the flight still registered — the
189
189
  // flight's (`handleAsync` stamped it with the action that asked).
190
- const asking = () => question || (i.m !== null && i.m.De !== null ? i.m.Oe : 0);
190
+ const asking = () => question || (i.m !== null && i.m.Te !== null ? i.m._e : 0);
191
191
  const f = wrapDraft(e, () => c.run === u && !isDisposed(i), o, s.s,
192
192
  // A write after the run returned (a continuation, a callback) arms the
193
193
  // drain itself when no landing will.
194
194
  () => {
195
- if (!(i.G & STATUS_PENDING) && !i._e) schedule();
195
+ if (!(i.S & STATUS_PENDING) && !i.De) schedule();
196
196
  }, asking);
197
197
  // The creation run commits directly (a memo's first value is its
198
198
  // `_value`); every later run — a re-derive in a flush, an async landing
199
199
  // — stages and commits with the flush like a memo's recompute.
200
200
  const d = u === 1;
201
201
  const pass = () => storeSetter(f, o => {
202
- a = t(l ?? o);
202
+ l = t(a ?? o);
203
203
  const commit = t => {
204
204
  // Shadow run: commit a detached snapshot, never the shadow itself
205
205
  // (adoption takes the value by identity — handing it the live
206
206
  // shadow would fuse the draft to the observable store).
207
- if (l && (t === undefined || t === l)) t = cloneState(l, s.s);
207
+ if (a && (t === undefined || t === a)) t = cloneState(a, s.s);
208
208
  if (t !== o && t !== undefined) {
209
209
  const write = () => {
210
210
  const n = question;
@@ -219,19 +219,19 @@ function forEachFamilyNode(e, t) {
219
219
  }
220
220
  // A landing (not the sync pass's own commit): the readers held
221
221
  // pending on the derive settle.
222
- if (!d || !(i.G & STATUS_UNINITIALIZED)) settleFamily(c);
222
+ if (!d || !(i.S & STATUS_UNINITIALIZED)) settleFamily(c);
223
223
  };
224
- const u = handleAsync(i, a, commit, (e, t) => {
224
+ const u = handleAsync(i, l, commit, (e, t) => {
225
225
  // The flight rejected: the leaves' readers learn it from here —
226
226
  // they do not subscribe to the derive. Pending again (a NotReady
227
227
  // rejection): the wake, as for the pass. Errored: every live
228
228
  // reader re-derives and meets the error at its pull (memo parity,
229
229
  // #2897) — and the flush that runs them advances the clock, so a
230
230
  // later tracked re-read may retry (core `read`).
231
- if (d && i.G & STATUS_UNINITIALIZED) return;
231
+ if (d && i.S & STATUS_UNINITIALIZED) return;
232
232
  if (t) wakeFamily(c, e); else errorFamily(c);
233
233
  });
234
- if (!i._e) commit(u);
234
+ if (!i.De) commit(u);
235
235
  }, false);
236
236
  try {
237
237
  d ? runDirect(pass) : pass();
@@ -239,49 +239,55 @@ function forEachFamilyNode(e, t) {
239
239
  // A flight went up (NotReady out of the pass — the derive's own, with
240
240
  // the derive as its source): the leaves' readers learn it from here —
241
241
  // they do not subscribe to the derive.
242
- if (e instanceof NotReadyError && !d) wakeFamily(c, e);
242
+ // A synchronous error the same way (#3956: a rerun that finds the
243
+ // entry failed throws): every live reader re-derives and meets it.
244
+ if (!d) e instanceof NotReadyError ? wakeFamily(c, e) : errorFamily(c);
243
245
  throw e;
244
246
  }
245
247
  // A pass that returned with a flight up (an iterator's sync first yield):
246
248
  // the wake, as for the throw. Not a sync pass that superseded one — the
247
249
  // status it reads is the dead flight's, cleared when this pass settles
248
250
  // (#3181: a reader the settle walk had just released, re-parked for good).
249
- if (i.G & STATUS_PENDING && i.m.De !== null && !i._e && !d) wakeFamily(c, i.m?.v);
251
+ if (i.S & STATUS_PENDING && i.m.Te !== null && !i.De && !d) wakeFamily(c, i.m?.F);
250
252
  return i;
251
253
  }
252
254
 
253
255
  function createProjectionInternal(e, t, r) {
254
- const n = {
256
+ const n = r?.key === undefined ? "id" : r.key;
257
+ const o = {
255
258
  map: new WeakMap,
256
259
  node: null,
257
260
  live: new Set,
258
- shallow: !!r?.shallow
261
+ shallow: !!r?.shallow,
262
+ // The row key, for a child paired after the adoption (store.ts
263
+ // `adoptChild`, #3712) as the adoption pairs them.
264
+ key: typeof n === "function" ? n : n === null ? null : e => isWrappable(e) ? e[n] : undefined
259
265
  };
260
- const o = wrap(t, null, null, n);
261
- if (n.shallow) {
262
- o[$TARGET].s = true;
266
+ const i = wrap(t, null, null, o);
267
+ if (o.shallow) {
268
+ i[$TARGET].s = true;
263
269
  markRawIngest(t);
264
270
  }
265
- let i;
266
- if (r?.seedLoadingValue) i = {
271
+ let s;
272
+ if (r?.seedLoadingValue) s = {
267
273
  loadingValue: undefined
268
274
  };
269
275
  if (r?.name) {
270
- i = {
271
- ...i,
276
+ s = {
277
+ ...s,
272
278
  name: r.name
273
279
  };
274
- nameStore(o, r.name);
280
+ nameStore(i, r.name);
275
281
  }
276
- const s = computed(() => {
277
- if (!n.node) n.node = getOwner();
278
- runProjectionComputed(o, e, r?.key === undefined ? "id" : r.key);
279
- }, i);
280
- s.u &= ~CONFIG_AUTO_DISPOSE;
281
- n.node = s;
282
+ const c = computed(() => {
283
+ if (!o.node) o.node = getOwner();
284
+ runProjectionComputed(i, e, n);
285
+ }, s);
286
+ c.i &= ~CONFIG_AUTO_DISPOSE;
287
+ o.node = c;
282
288
  return {
283
- store: o,
284
- node: s
289
+ store: i,
290
+ node: c
285
291
  };
286
292
  }
287
293
 
@@ -2,7 +2,9 @@ import { isEqual } from "../core/core.js";
2
2
 
3
3
  import { isOwned, $OWNER, storeLookup, lookupTarget } from "./target.js";
4
4
 
5
- import { userWriting, optHooks, unwrapValue, adoptPB, sameKey, materializePB, notifyFold, targetsEqual, bumpDeep, notifyKeyValue, notifyKeyDiff, notifyFoldTail, hasAccessorFlag } from "./store.js";
5
+ import { userWriting, unwrapValue, adoptPB, sameKey, materializePB, notifyFold, sameRow, targetsEqual, bumpDeep, notifyKeyValue, notifyKeyDiff, notifyFoldTail, hasAccessorFlag } from "./store.js";
6
+
7
+ import { optHooks } from "./hooks.js";
6
8
 
7
9
  import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "./types.js";
8
10
 
@@ -73,33 +75,33 @@ import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "
73
75
  // — key matching from the arrangement the guesses made (R28), so a row
74
76
  // the guess added keeps its proxy when the server returns it.
75
77
  const i = l?.opt === true ? optHooks.view(e, f) : f;
76
- const u = Array.isArray(n);
77
- const s = e.s === true;
78
+ const s = Array.isArray(n);
79
+ const u = e.s === true;
78
80
  const r = f;
79
81
  adoptPB(e, n, false);
80
- if (s) markRawIngest(n);
81
- if (Array.isArray(i) !== u) {
82
+ if (u) markRawIngest(n);
83
+ if (Array.isArray(i) !== s) {
82
84
  notifyFold(e, r, n);
83
85
  return;
84
86
  }
85
- if (u) {
87
+ if (s) {
86
88
  const f = i;
87
- const u = n;
89
+ const s = n;
88
90
  const a = e.n;
89
91
  let c = 0;
90
- if (t && !s) {
92
+ if (t && !u) {
91
93
  const i = f.length;
92
- const s = u.length;
94
+ const u = s.length;
93
95
  let d = false;
94
96
  let p = 0;
95
97
  // Aligned prefix: same row (by reference or key) at the same index.
96
- for (const y = Math.min(i, s); p < y; p++) {
97
- const i = u[p];
98
- const s = f[p];
99
- if (s !== i && !(s !== null && typeof s === "object" && i !== null && typeof i === "object" && sameKey(t(s), t(i)))) break;
98
+ for (const y = Math.min(i, u); p < y; p++) {
99
+ const i = s[p];
100
+ const u = f[p];
101
+ if (u !== i && !sameRow(u, i, t)) break;
100
102
  // misaligned: fall to the keyed remainder below
101
- if ((s !== i || i !== null && typeof i === "object" && isOwned(i)) && i !== null && typeof i === "object") descend(unwrapValue(s), i, t, l, o);
102
- if (e.dk !== null && !d && !(i !== null && typeof i === "object" ? targetsEqual(s, i) : isEqual(s, i))) {
103
+ if ((u !== i || i !== null && typeof i === "object" && isOwned(i)) && i !== null && typeof i === "object") descend(unwrapValue(u), i, t, l, o);
104
+ if (e.dk !== null && !d && !(i !== null && typeof i === "object" ? targetsEqual(u, i) : isEqual(u, i))) {
103
105
  bumpDeep(e);
104
106
  d = true;
105
107
  }
@@ -111,12 +113,12 @@ import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "
111
113
  }
112
114
  }
113
115
  }
114
- if (e.dk !== null && !d && p < u.length) bumpDeep(e);
116
+ if (e.dk !== null && !d && p < s.length) bumpDeep(e);
115
117
  const y = p;
116
118
  // misalignment point (== nlen on aligned ticks)
117
119
  let w = null;
118
- for (;p < u.length; p++) {
119
- const e = u[p];
120
+ for (;p < s.length; p++) {
121
+ const e = s[p];
120
122
  if (e !== null && typeof e === "object") {
121
123
  const n = t(e);
122
124
  let i;
@@ -156,12 +158,12 @@ import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "
156
158
  }
157
159
  }
158
160
  } else {
159
- const i = Math.min(f.length, u.length);
160
- const d = u.length;
161
+ const i = Math.min(f.length, s.length);
162
+ const d = s.length;
161
163
  let p = false;
162
164
  for (let y = 0; y < d; y++) {
163
- const d = u[y];
164
- if (!s && y < i && d !== null && typeof d === "object") descend(unwrapValue(f[y]), d, t, l, o);
165
+ const d = s[y];
166
+ if (!u && y < i && d !== null && typeof d === "object") descend(unwrapValue(f[y]), d, t, l, o);
165
167
  if (e.dk !== null && !p && !(d !== null && typeof d === "object" ? targetsEqual(f[y], d) : isEqual(f[y], d))) {
166
168
  bumpDeep(e);
167
169
  p = true;
@@ -179,7 +181,7 @@ import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "
179
181
  if (a !== null && c < e.nc) {
180
182
  for (const e of Reflect.ownKeys(a)) {
181
183
  const t = typeof e === "string" ? +e : NaN;
182
- if (!(t >= 0 && t < u.length)) notifyKeyDiff(a[e], e, r, n, false);
184
+ if (!(t >= 0 && t < s.length)) notifyKeyDiff(a[e], e, r, n, false);
183
185
  }
184
186
  }
185
187
  notifyFoldTail(e, r, n);
@@ -189,15 +191,15 @@ import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "
189
191
  let c = 0;
190
192
  let d = false;
191
193
  for (const f in n) {
192
- const u = n[f];
194
+ const s = n[f];
193
195
  const p = r[f];
194
- const y = u !== null && typeof u === "object";
195
- if (p === u && (!y || !isOwned(u)) && (a === null || a[f] === undefined || !hasAccessorFlag(a[f]))) {
196
+ const y = s !== null && typeof s === "object";
197
+ if (p === s && (!y || !isOwned(s)) && (a === null || a[f] === undefined || !hasAccessorFlag(a[f]))) {
196
198
  if (a !== null && a[f] !== undefined) c++;
197
199
  continue;
198
200
  }
199
- if (y && !s) descend(unwrapValue(i[f]), u, t, l, o);
200
- if (e.dk !== null && !d && !(y ? targetsEqual(p, u) : isEqual(p, u))) {
201
+ if (y && !u) descend(unwrapValue(i[f]), s, t, l, o);
202
+ if (e.dk !== null && !d && !(y ? targetsEqual(p, s) : isEqual(p, s))) {
201
203
  bumpDeep(e);
202
204
  d = true;
203
205
  }
@@ -205,7 +207,7 @@ import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "
205
207
  const e = a[f];
206
208
  if (e !== undefined) {
207
209
  c++;
208
- notifyKeyValue(e, f, p, u, r, n);
210
+ notifyKeyValue(e, f, p, s, r, n);
209
211
  }
210
212
  }
211
213
  }
@@ -214,7 +216,7 @@ import { $TARGET, markRawIngest, isWrappable, rawValuesUsed, isRawValue } from "
214
216
  const f = p[e];
215
217
  if (f === $OWNER) continue;
216
218
  const i = n[f];
217
- if (!s && i !== null && typeof i === "object") descend(unwrapValue(r[f]), i, t, l, o);
219
+ if (!u && i !== null && typeof i === "object") descend(unwrapValue(r[f]), i, t, l, o);
218
220
  if (a !== null) {
219
221
  const e = a[f];
220
222
  if (e !== undefined) {