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

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 (57) hide show
  1. package/dist/dev.js +1618 -232
  2. package/dist/node.cjs +2262 -1199
  3. package/dist/prod/boundaries.js +4 -1
  4. package/dist/prod/core/async.js +152 -101
  5. package/dist/prod/core/constants.js +55 -1
  6. package/dist/prod/core/core.js +305 -234
  7. package/dist/prod/core/effect.js +28 -28
  8. package/dist/prod/core/error.js +13 -1
  9. package/dist/prod/core/external.js +2 -2
  10. package/dist/prod/core/graph.js +27 -27
  11. package/dist/prod/core/heap.js +30 -30
  12. package/dist/prod/core/lanes.js +32 -32
  13. package/dist/prod/core/optimistic.js +57 -57
  14. package/dist/prod/core/owner.js +34 -34
  15. package/dist/prod/core/scheduler.js +346 -152
  16. package/dist/prod/core/verdict.js +122 -65
  17. package/dist/prod/index.js +3 -3
  18. package/dist/prod/map.js +106 -106
  19. package/dist/prod/signals.js +321 -26
  20. package/dist/prod/store/next/optimistic.js +363 -151
  21. package/dist/prod/store/next/patch.js +6 -6
  22. package/dist/prod/store/next/projection.js +25 -21
  23. package/dist/prod/store/next/store.js +223 -113
  24. package/dist/prod/store/store.js +2 -2
  25. package/dist/types/core/async.d.ts +2 -0
  26. package/dist/types/core/attribution-hooks.d.ts +11 -0
  27. package/dist/types/core/attribution.d.ts +57 -4
  28. package/dist/types/core/constants.d.ts +54 -0
  29. package/dist/types/core/core.d.ts +19 -20
  30. package/dist/types/core/dev.d.ts +8 -2
  31. package/dist/types/core/error.d.ts +9 -0
  32. package/dist/types/core/index.d.ts +2 -2
  33. package/dist/types/core/scheduler.d.ts +39 -0
  34. package/dist/types/core/types.d.ts +12 -0
  35. package/dist/types/index.d.ts +3 -3
  36. package/dist/types/signals.d.ts +108 -11
  37. package/dist/types/store/next/optimistic.d.ts +13 -10
  38. package/dist/types/store/next/projection.d.ts +1 -1
  39. package/dist/types/store/next/store.d.ts +22 -0
  40. package/dist/types/store/next/target.d.ts +25 -0
  41. package/dist/types-cjs/core/async.d.cts +2 -0
  42. package/dist/types-cjs/core/attribution-hooks.d.cts +11 -0
  43. package/dist/types-cjs/core/attribution.d.cts +57 -4
  44. package/dist/types-cjs/core/constants.d.cts +54 -0
  45. package/dist/types-cjs/core/core.d.cts +19 -20
  46. package/dist/types-cjs/core/dev.d.cts +8 -2
  47. package/dist/types-cjs/core/error.d.cts +9 -0
  48. package/dist/types-cjs/core/index.d.cts +2 -2
  49. package/dist/types-cjs/core/scheduler.d.cts +39 -0
  50. package/dist/types-cjs/core/types.d.cts +12 -0
  51. package/dist/types-cjs/index.d.cts +3 -3
  52. package/dist/types-cjs/signals.d.cts +108 -11
  53. package/dist/types-cjs/store/next/optimistic.d.cts +13 -10
  54. package/dist/types-cjs/store/next/projection.d.cts +1 -1
  55. package/dist/types-cjs/store/next/store.d.cts +22 -0
  56. package/dist/types-cjs/store/next/target.d.cts +25 -0
  57. package/package.json +1 -1
package/dist/prod/map.js CHANGED
@@ -23,23 +23,23 @@ function mapArray(t, s, i) {
23
23
  const r = s.length > 1;
24
24
  const n = s;
25
25
  const h = {
26
- Wt: createOwner(),
27
- xt: 0,
28
- Kt: t,
29
- $t: [],
30
- qt: n,
31
- zt: [],
32
- Jt: [],
33
- Xt: e,
34
- Yt: e || i?.keyed === false ? [] : undefined,
35
- Zt: r && i?.keyed !== false ? [] : undefined,
36
- ts: i?.keyed === false,
37
- ss: i?.fallback
26
+ Kt: createOwner(),
27
+ $t: 0,
28
+ Jt: t,
29
+ Xt: [],
30
+ Yt: n,
31
+ Zt: [],
32
+ ts: [],
33
+ ss: e,
34
+ es: e || i?.keyed === false ? [] : undefined,
35
+ rs: r && i?.keyed !== false ? [] : undefined,
36
+ ns: i?.keyed === false,
37
+ hs: i?.fallback
38
38
  };
39
39
  const o = computed(updateKeyedMap.bind(h));
40
40
  // Untracked reads inside the internal owner resolve via _parentComputed; routing
41
41
  // them through node lets store-proxy lookups see pending writes (not stale _value).
42
- h.Wt.Ot = o;
42
+ h.Kt.Dt = o;
43
43
  o.T &= ~CONFIG_AUTO_DISPOSE;
44
44
  return accessor(o);
45
45
  }
@@ -58,52 +58,52 @@ const pureOptions = {
58
58
  // strong-abort ordering: removed rows now dispose AFTER the pass's new rows
59
59
  // are created (you cannot destroy state before knowing the pass will land).
60
60
  function updateKeyedMap() {
61
- const t = this.Kt() || [], s = t.length;
61
+ const t = this.Jt() || [], s = t.length;
62
62
  t[$TRACK];
63
63
  // top level tracking
64
- runWithOwner(this.Wt, () => {
64
+ runWithOwner(this.Kt, () => {
65
65
  let i, e, r, n,
66
66
  // Mappers write freshly-created row/index signals into the STAGE
67
67
  // arrays (`rows`/`indexes`), never into `this._rows`/`this._indexes`.
68
- h = this.Yt ? this.ts ? () => {
68
+ h = this.es ? this.ns ? () => {
69
69
  r[e] = signal(t[e], pureOptions);
70
- return this.qt(accessor(r[e]), e);
70
+ return this.Yt(accessor(r[e]), e);
71
71
  } : () => {
72
72
  r[e] = signal(t[e], pureOptions);
73
73
  n && (n[e] = signal(e, pureOptions));
74
- return this.qt(accessor(r[e]), n ? accessor(n[e]) : undefined);
75
- } : this.Zt ? () => {
74
+ return this.Yt(accessor(r[e]), n ? accessor(n[e]) : undefined);
75
+ } : this.rs ? () => {
76
76
  const s = t[e];
77
77
  n[e] = signal(e, pureOptions);
78
- return this.qt(s, accessor(n[e]));
78
+ return this.Yt(s, accessor(n[e]));
79
79
  } : () => {
80
80
  const s = t[e];
81
- return this.qt(s);
81
+ return this.Yt(s);
82
82
  };
83
83
  // fast path for empty arrays
84
84
  if (s === 0) {
85
- if (this.xt !== 0) {
86
- this.Wt.dispose(false);
87
- this.Jt = [];
88
- this.$t = [];
89
- this.zt = [];
90
- this.xt = 0;
91
- this.Yt && (this.Yt = []);
92
- this.Zt && (this.Zt = []);
85
+ if (this.$t !== 0) {
86
+ this.Kt.dispose(false);
87
+ this.ts = [];
88
+ this.Xt = [];
89
+ this.Zt = [];
90
+ this.$t = 0;
91
+ this.es && (this.es = []);
92
+ this.rs && (this.rs = []);
93
93
  }
94
- if (this.ss && !this.zt[0]) {
94
+ if (this.hs && !this.Zt[0]) {
95
95
  // an aborted fallback attempt leaves an owner without a mapping;
96
96
  // dispose it before re-creating
97
- this.Jt[0]?.dispose();
98
- this.zt[0] = runWithOwner(this.Jt[0] = createOwner(), this.ss);
97
+ this.ts[0]?.dispose();
98
+ this.Zt[0] = runWithOwner(this.ts[0] = createOwner(), this.hs);
99
99
  }
100
100
  }
101
101
  // fast path for new create
102
- else if (this.xt === 0) {
102
+ else if (this.$t === 0) {
103
103
  const o = new Array(s);
104
104
  const c = new Array(s);
105
- r = this.Yt && new Array(s);
106
- n = this.Zt && new Array(s);
105
+ r = this.es && new Array(s);
106
+ n = this.rs && new Array(s);
107
107
  try {
108
108
  for (e = 0; e < s; e++) o[e] = runWithOwner(c[e] = createOwner(), h);
109
109
  } catch (t) {
@@ -111,43 +111,43 @@ function updateKeyedMap() {
111
111
  throw t;
112
112
  }
113
113
  // commit
114
- if (this.Jt[0]) this.Jt[0].dispose();
114
+ if (this.ts[0]) this.ts[0].dispose();
115
115
  // previous fallback
116
- this.zt = o;
117
- this.Jt = c;
118
- r && (this.Yt = r);
119
- n && (this.Zt = n);
120
- this.$t = t.slice(0);
121
- this.xt = s;
116
+ this.Zt = o;
117
+ this.ts = c;
118
+ r && (this.es = r);
119
+ n && (this.rs = n);
120
+ this.Xt = t.slice(0);
121
+ this.$t = s;
122
122
  } else {
123
123
  let o, c, a, f, u, p, w, l, d;
124
124
  // skip common prefix
125
- for (o = 0, c = Math.min(this.xt, s); o < c && (this.$t[o] === t[o] || this.Yt && compare(this.Xt, this.$t[o], t[o])); o++) {
126
- if (this.Yt) setSignal(this.Yt[o], t[o]);
125
+ for (o = 0, c = Math.min(this.$t, s); o < c && (this.Xt[o] === t[o] || this.es && compare(this.ss, this.Xt[o], t[o])); o++) {
126
+ if (this.es) setSignal(this.es[o], t[o]);
127
127
  }
128
128
  // skip common suffix — counted only; retained entries land in one pass
129
129
  // at commit instead of being staged and copied twice
130
- for (c = this.xt - 1, a = s - 1; c >= o && a >= o && (this.$t[c] === t[a] || this.Yt && compare(this.Xt, this.$t[c], t[a])); c--,
130
+ for (c = this.$t - 1, a = s - 1; c >= o && a >= o && (this.Xt[c] === t[a] || this.es && compare(this.ss, this.Xt[c], t[a])); c--,
131
131
  a--) ;
132
132
  // no structural change (every position matched in place at equal
133
133
  // length — the common post-reconcile shape): keep the same mapped
134
134
  // array identity so downstream consumers don't re-run at all
135
- if (o === s && this.xt === s) {
136
- this.$t = t.slice(0);
135
+ if (o === s && this.$t === s) {
136
+ this.Xt = t.slice(0);
137
137
  return;
138
138
  }
139
- const O = s - this.xt;
139
+ const O = s - this.$t;
140
140
  const m = new Array(s);
141
141
  const _ = new Array(s);
142
- r = this.Yt ? new Array(s) : undefined;
143
- n = this.Zt ? new Array(s) : undefined;
142
+ r = this.es ? new Array(s) : undefined;
143
+ n = this.rs ? new Array(s) : undefined;
144
144
  // 0) prepare a map of all indices in the changed window of newItems,
145
145
  // scanning backwards so we encounter them in natural order
146
146
  p = new Map;
147
147
  w = new Array(a + 1);
148
148
  for (e = a; e >= o; e--) {
149
149
  f = t[e];
150
- u = this.Xt ? this.Xt(f) : f;
150
+ u = this.ss ? this.ss(f) : f;
151
151
  i = p.get(u);
152
152
  w[e] = i === undefined ? -1 : i;
153
153
  p.set(u, e);
@@ -156,17 +156,17 @@ function updateKeyedMap() {
156
156
  // in the new set; if so, stage them at their new positions; if not,
157
157
  // queue them for disposal at commit
158
158
  for (i = o; i <= c; i++) {
159
- f = this.$t[i];
160
- u = this.Xt ? this.Xt(f) : f;
159
+ f = this.Xt[i];
160
+ u = this.ss ? this.ss(f) : f;
161
161
  e = p.get(u);
162
162
  if (e !== undefined && e !== -1) {
163
- m[e] = this.zt[i];
164
- _[e] = this.Jt[i];
165
- r && (r[e] = this.Yt[i]);
166
- n && (n[e] = this.Zt[i]);
163
+ m[e] = this.Zt[i];
164
+ _[e] = this.ts[i];
165
+ r && (r[e] = this.es[i]);
166
+ n && (n[e] = this.rs[i]);
167
167
  e = w[e];
168
168
  p.set(u, e);
169
- } else (l ??= []).push(this.Jt[i]);
169
+ } else (l ??= []).push(this.ts[i]);
170
170
  }
171
171
  // 2) create new rows into the temp arrays; an abort disposes only these
172
172
  try {
@@ -183,38 +183,38 @@ function updateKeyedMap() {
183
183
  // into the fresh arrays, swap them in (new identity for downstream
184
184
  // change propagation), then dispose exited rows
185
185
  for (i = 0; i < o; i++) {
186
- m[i] = this.zt[i];
187
- _[i] = this.Jt[i];
188
- r && (r[i] = this.Yt[i]);
189
- n && (n[i] = this.Zt[i]);
186
+ m[i] = this.Zt[i];
187
+ _[i] = this.ts[i];
188
+ r && (r[i] = this.es[i]);
189
+ n && (n[i] = this.rs[i]);
190
190
  }
191
191
  for (e = o; e <= a; e++) {
192
192
  if (r) setSignal(r[e], t[e]);
193
193
  if (n) setSignal(n[e], e);
194
194
  }
195
195
  for (e = a + 1; e < s; e++) {
196
- m[e] = this.zt[e - O];
197
- _[e] = this.Jt[e - O];
196
+ m[e] = this.Zt[e - O];
197
+ _[e] = this.ts[e - O];
198
198
  if (r) {
199
- r[e] = this.Yt[e - O];
199
+ r[e] = this.es[e - O];
200
200
  setSignal(r[e], t[e]);
201
201
  }
202
202
  if (n) {
203
- n[e] = this.Zt[e - O];
203
+ n[e] = this.rs[e - O];
204
204
  if (O !== 0) setSignal(n[e], e);
205
205
  }
206
206
  }
207
- this.zt = m;
208
- this.Jt = _;
209
- r && (this.Yt = r);
210
- n && (this.Zt = n);
211
- this.xt = s;
207
+ this.Zt = m;
208
+ this.ts = _;
209
+ r && (this.es = r);
210
+ n && (this.rs = n);
211
+ this.$t = s;
212
212
  // save a copy of the mapped items for the next update
213
- this.$t = t.slice(0);
213
+ this.Xt = t.slice(0);
214
214
  if (l) for (i = 0; i < l.length; i++) l[i].dispose();
215
215
  }
216
216
  });
217
- return this.zt;
217
+ return this.Zt;
218
218
  }
219
219
 
220
220
  /**
@@ -234,21 +234,21 @@ function updateKeyedMap() {
234
234
  */ function repeat(t, s, i) {
235
235
  const e = s;
236
236
  const r = {
237
- Wt: createOwner(),
238
- xt: 0,
239
- es: 0,
240
- rs: t,
241
- qt: e,
242
- Jt: [],
243
- zt: [],
244
- ns: i?.from,
245
- ss: i?.fallback
237
+ Kt: createOwner(),
238
+ $t: 0,
239
+ cs: 0,
240
+ fs: t,
241
+ Yt: e,
242
+ ts: [],
243
+ Zt: [],
244
+ us: i?.from,
245
+ hs: i?.fallback
246
246
  };
247
247
  const n = computed(updateRepeat.bind(r));
248
248
  // Same as mapArray: untracked reads inside the internal owner resolve via
249
249
  // _parentComputed, so async reads in row callbacks register with the node
250
250
  // (pending tracking + post-settle retry) instead of vanishing.
251
- r.Wt.Ot = n;
251
+ r.Kt.Dt = n;
252
252
  n.T &= ~CONFIG_AUTO_DISPOSE;
253
253
  return accessor(n);
254
254
  }
@@ -261,55 +261,55 @@ function updateKeyedMap() {
261
261
  // for the post-settle retry. The overlap math also subsumes the previous
262
262
  // disjoint-window/front-clear/end-clear/shift special cases.
263
263
  function updateRepeat() {
264
- const t = this.rs();
265
- const s = this.ns?.() || 0;
266
- runWithOwner(this.Wt, () => {
264
+ const t = this.fs();
265
+ const s = this.us?.() || 0;
266
+ runWithOwner(this.Kt, () => {
267
267
  if (t === 0) {
268
- if (this.xt !== 0) {
269
- this.Wt.dispose(false);
270
- this.Jt = [];
271
- this.zt = [];
272
- this.xt = 0;
268
+ if (this.$t !== 0) {
269
+ this.Kt.dispose(false);
270
+ this.ts = [];
271
+ this.Zt = [];
272
+ this.$t = 0;
273
273
  // Reset offset to match the cleared data (#2767, repro 2).
274
- this.es = 0;
274
+ this.cs = 0;
275
275
  }
276
- if (this.ss && !this.zt[0]) {
276
+ if (this.hs && !this.Zt[0]) {
277
277
  // an aborted fallback attempt leaves an owner without a mapping;
278
278
  // dispose it before re-creating
279
- this.Jt[0]?.dispose();
280
- this.zt[0] = runWithOwner(this.Jt[0] = createOwner(), this.ss);
279
+ this.ts[0]?.dispose();
280
+ this.Zt[0] = runWithOwner(this.ts[0] = createOwner(), this.hs);
281
281
  }
282
282
  return;
283
283
  }
284
284
  const i = s + t;
285
- const e = this.es + this.xt;
285
+ const e = this.cs + this.$t;
286
286
  // Retained overlap [keepStart, keepEnd) in global indexes; empty when the
287
287
  // windows are disjoint or when coming from empty/fallback.
288
- const r = Math.max(s, this.es);
288
+ const r = Math.max(s, this.cs);
289
289
  const n = Math.min(i, e);
290
290
  const h = new Array(t);
291
291
  const o = new Array(t);
292
292
  for (let t = r; t < n; t++) {
293
- o[t - s] = this.Jt[t - this.es];
294
- h[t - s] = this.zt[t - this.es];
293
+ o[t - s] = this.ts[t - this.cs];
294
+ h[t - s] = this.Zt[t - this.cs];
295
295
  }
296
296
  try {
297
297
  for (let t = s; t < i; t++) {
298
298
  if (t >= r && t < n) continue;
299
- h[t - s] = runWithOwner(o[t - s] = createOwner(), () => this.qt(t));
299
+ h[t - s] = runWithOwner(o[t - s] = createOwner(), () => this.Yt(t));
300
300
  }
301
301
  } catch (t) {
302
302
  for (let t = s; t < i; t++) if ((t < r || t >= n) && o[t - s]) o[t - s].dispose();
303
303
  throw t;
304
304
  }
305
305
  // commit: dispose the previous fallback or the rows leaving the window
306
- if (this.xt === 0) this.Jt[0]?.dispose(); else for (let t = this.es; t < e; t++) if (t < s || t >= i) this.Jt[t - this.es].dispose();
307
- this.zt = h;
308
- this.Jt = o;
309
- this.es = s;
310
- this.xt = t;
306
+ if (this.$t === 0) this.ts[0]?.dispose(); else for (let t = this.cs; t < e; t++) if (t < s || t >= i) this.ts[t - this.cs].dispose();
307
+ this.Zt = h;
308
+ this.ts = o;
309
+ this.cs = s;
310
+ this.$t = t;
311
311
  });
312
- return this.zt;
312
+ return this.Zt;
313
313
  }
314
314
 
315
315
  function compare(t, s, i) {