@solidjs/signals 0.3.1 → 0.4.0
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/dev.js +624 -503
- package/dist/node.cjs +775 -647
- package/dist/prod.js +762 -640
- package/dist/types/{core/boundaries.d.ts → boundaries.d.ts} +7 -3
- package/dist/types/core/core.d.ts +4 -5
- package/dist/types/core/effect.d.ts +4 -3
- package/dist/types/core/error.d.ts +0 -7
- package/dist/types/core/index.d.ts +4 -6
- package/dist/types/core/scheduler.d.ts +8 -8
- package/dist/types/index.d.ts +3 -2
- package/dist/types/signals.d.ts +43 -3
- package/dist/types/store/index.d.ts +2 -2
- package/dist/types/store/projection.d.ts +1 -2
- package/dist/types/store/reconcile.d.ts +1 -1
- package/dist/types/store/store.d.ts +14 -16
- package/dist/types/store/utils.d.ts +7 -0
- package/package.json +1 -1
- package/dist/types/core/utils.d.ts +0 -4
package/dist/prod.js
CHANGED
|
@@ -13,12 +13,6 @@ var ContextNotFoundError = class extends Error {
|
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
var EffectError = class extends Error {
|
|
17
|
-
constructor(effect, cause) {
|
|
18
|
-
super("");
|
|
19
|
-
this.cause = cause;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
16
|
|
|
23
17
|
// src/core/constants.ts
|
|
24
18
|
var STATE_CLEAN = 0;
|
|
@@ -43,121 +37,74 @@ function schedule() {
|
|
|
43
37
|
if (scheduled)
|
|
44
38
|
return;
|
|
45
39
|
scheduled = true;
|
|
46
|
-
if (!globalQueue.
|
|
47
|
-
queueMicrotask(
|
|
40
|
+
if (!globalQueue.J)
|
|
41
|
+
queueMicrotask(flush);
|
|
48
42
|
}
|
|
43
|
+
var pureQueue = [];
|
|
49
44
|
var Queue = class {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
o = null;
|
|
46
|
+
J = false;
|
|
47
|
+
K = [[], []];
|
|
48
|
+
E = [];
|
|
54
49
|
created = clock;
|
|
55
|
-
enqueue(type,
|
|
56
|
-
|
|
50
|
+
enqueue(type, fn) {
|
|
51
|
+
pureQueue.push(fn);
|
|
57
52
|
if (type)
|
|
58
|
-
this.
|
|
53
|
+
this.K[type - 1].push(fn);
|
|
59
54
|
schedule();
|
|
60
55
|
}
|
|
61
56
|
run(type) {
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
57
|
+
if (type === EFFECT_PURE) {
|
|
58
|
+
pureQueue.length && runQueue(pureQueue, type);
|
|
59
|
+
pureQueue = [];
|
|
60
|
+
return;
|
|
61
|
+
} else if (this.K[type - 1].length) {
|
|
62
|
+
const effects = this.K[type - 1];
|
|
63
|
+
this.K[type - 1] = [];
|
|
64
|
+
runQueue(effects, type);
|
|
71
65
|
}
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
rerun = this.F[i].run(type) || rerun;
|
|
66
|
+
for (let i = 0; i < this.E.length; i++) {
|
|
67
|
+
this.E[i].run(type);
|
|
75
68
|
}
|
|
76
|
-
if (type === EFFECT_PURE)
|
|
77
|
-
return rerun || !!this.s[type].length;
|
|
78
69
|
}
|
|
79
70
|
flush() {
|
|
80
|
-
if (this.
|
|
71
|
+
if (this.J)
|
|
81
72
|
return;
|
|
82
|
-
this.
|
|
73
|
+
this.J = true;
|
|
83
74
|
try {
|
|
84
|
-
|
|
85
|
-
}
|
|
75
|
+
this.run(EFFECT_PURE);
|
|
86
76
|
incrementClock();
|
|
87
77
|
scheduled = false;
|
|
88
78
|
this.run(EFFECT_RENDER);
|
|
89
79
|
this.run(EFFECT_USER);
|
|
90
80
|
} finally {
|
|
91
|
-
this.
|
|
81
|
+
this.J = false;
|
|
92
82
|
}
|
|
93
83
|
}
|
|
94
84
|
addChild(child) {
|
|
95
|
-
this.
|
|
96
|
-
child.
|
|
85
|
+
this.E.push(child);
|
|
86
|
+
child.o = this;
|
|
97
87
|
}
|
|
98
88
|
removeChild(child) {
|
|
99
|
-
const index = this.
|
|
89
|
+
const index = this.E.indexOf(child);
|
|
100
90
|
if (index >= 0)
|
|
101
|
-
this.
|
|
91
|
+
this.E.splice(index, 1);
|
|
102
92
|
}
|
|
103
93
|
notify(...args) {
|
|
104
|
-
if (this.
|
|
105
|
-
return this.
|
|
94
|
+
if (this.o)
|
|
95
|
+
return this.o.notify(...args);
|
|
106
96
|
return false;
|
|
107
97
|
}
|
|
108
98
|
};
|
|
109
99
|
var globalQueue = new Queue();
|
|
110
|
-
function
|
|
100
|
+
function flush() {
|
|
111
101
|
while (scheduled) {
|
|
112
102
|
globalQueue.flush();
|
|
113
103
|
}
|
|
114
104
|
}
|
|
115
|
-
function
|
|
116
|
-
const ancestors = [];
|
|
117
|
-
for (let current = node; current !== null; current = current.n) {
|
|
118
|
-
if (current.a !== STATE_CLEAN) {
|
|
119
|
-
ancestors.push(current);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
123
|
-
if (ancestors[i].a !== STATE_DISPOSED)
|
|
124
|
-
ancestors[i].x();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function runPureQueue(queue) {
|
|
128
|
-
for (let i = 0; i < queue.length; i++) {
|
|
129
|
-
if (queue[i].a !== STATE_CLEAN)
|
|
130
|
-
runTop(queue[i]);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function runEffectQueue(queue) {
|
|
105
|
+
function runQueue(queue, type) {
|
|
134
106
|
for (let i = 0; i < queue.length; i++)
|
|
135
|
-
queue[i]
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// src/core/utils.ts
|
|
139
|
-
function isUndefined(value) {
|
|
140
|
-
return typeof value === "undefined";
|
|
141
|
-
}
|
|
142
|
-
function tryCatch(fn) {
|
|
143
|
-
try {
|
|
144
|
-
const v = fn();
|
|
145
|
-
if (v instanceof Promise) {
|
|
146
|
-
return v.then(
|
|
147
|
-
(v2) => [void 0, v2],
|
|
148
|
-
(e) => {
|
|
149
|
-
if (e instanceof NotReadyError)
|
|
150
|
-
throw e;
|
|
151
|
-
return [e];
|
|
152
|
-
}
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
return [void 0, v];
|
|
156
|
-
} catch (e) {
|
|
157
|
-
if (e instanceof NotReadyError)
|
|
158
|
-
throw e;
|
|
159
|
-
return [e];
|
|
160
|
-
}
|
|
107
|
+
queue[i](type);
|
|
161
108
|
}
|
|
162
109
|
|
|
163
110
|
// src/core/owner.ts
|
|
@@ -171,40 +118,36 @@ function setOwner(owner) {
|
|
|
171
118
|
currentOwner = owner;
|
|
172
119
|
return out;
|
|
173
120
|
}
|
|
174
|
-
function formatId(prefix, id) {
|
|
175
|
-
const num = id.toString(36), len = num.length - 1;
|
|
176
|
-
return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
|
|
177
|
-
}
|
|
178
121
|
var Owner = class {
|
|
179
122
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
180
123
|
// However, the children are actually added in reverse creation order
|
|
181
124
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
182
|
-
|
|
125
|
+
o = null;
|
|
183
126
|
m = null;
|
|
184
127
|
t = null;
|
|
185
128
|
a = STATE_CLEAN;
|
|
186
129
|
l = null;
|
|
187
|
-
|
|
130
|
+
p = defaultContext;
|
|
188
131
|
h = globalQueue;
|
|
189
132
|
W = 0;
|
|
190
133
|
id = null;
|
|
191
134
|
constructor(id = null, skipAppend = false) {
|
|
192
135
|
this.id = id;
|
|
193
136
|
if (currentOwner) {
|
|
194
|
-
if (!id && currentOwner.id)
|
|
195
|
-
this.id = currentOwner.getNextChildId();
|
|
196
137
|
!skipAppend && currentOwner.append(this);
|
|
197
138
|
}
|
|
198
139
|
}
|
|
199
140
|
append(child) {
|
|
200
|
-
child.
|
|
141
|
+
child.o = this;
|
|
201
142
|
child.t = this;
|
|
202
143
|
if (this.m)
|
|
203
144
|
this.m.t = child;
|
|
204
145
|
child.m = this.m;
|
|
205
146
|
this.m = child;
|
|
206
|
-
if (child.
|
|
207
|
-
child.
|
|
147
|
+
if (this.id != null && child.id == null)
|
|
148
|
+
child.id = this.getNextChildId();
|
|
149
|
+
if (child.p !== this.p) {
|
|
150
|
+
child.p = { ...this.p, ...child.p };
|
|
208
151
|
}
|
|
209
152
|
if (this.h)
|
|
210
153
|
child.h = this.h;
|
|
@@ -212,8 +155,8 @@ var Owner = class {
|
|
|
212
155
|
dispose(self = true) {
|
|
213
156
|
if (this.a === STATE_DISPOSED)
|
|
214
157
|
return;
|
|
215
|
-
let head = self ? this.t || this.
|
|
216
|
-
while (current && current.
|
|
158
|
+
let head = self ? this.t || this.o : this, current = this.m, next = null;
|
|
159
|
+
while (current && current.o === this) {
|
|
217
160
|
current.dispose(true);
|
|
218
161
|
current.y();
|
|
219
162
|
next = current.m;
|
|
@@ -231,9 +174,9 @@ var Owner = class {
|
|
|
231
174
|
y() {
|
|
232
175
|
if (this.t)
|
|
233
176
|
this.t.m = null;
|
|
234
|
-
this.
|
|
177
|
+
this.o = null;
|
|
235
178
|
this.t = null;
|
|
236
|
-
this.
|
|
179
|
+
this.p = defaultContext;
|
|
237
180
|
this.a = STATE_DISPOSED;
|
|
238
181
|
this.emptyDisposal();
|
|
239
182
|
}
|
|
@@ -251,7 +194,7 @@ var Owner = class {
|
|
|
251
194
|
this.l = null;
|
|
252
195
|
}
|
|
253
196
|
getNextChildId() {
|
|
254
|
-
if (this.id)
|
|
197
|
+
if (this.id != null)
|
|
255
198
|
return formatId(this.id, this.W++);
|
|
256
199
|
throw new Error("Cannot get child id from owner without an id");
|
|
257
200
|
}
|
|
@@ -263,7 +206,7 @@ function getContext(context, owner = currentOwner) {
|
|
|
263
206
|
if (!owner) {
|
|
264
207
|
throw new NoOwnerError();
|
|
265
208
|
}
|
|
266
|
-
const value = hasContext(context, owner) ? owner.
|
|
209
|
+
const value = hasContext(context, owner) ? owner.p[context.id] : context.defaultValue;
|
|
267
210
|
if (isUndefined(value)) {
|
|
268
211
|
throw new ContextNotFoundError();
|
|
269
212
|
}
|
|
@@ -273,13 +216,13 @@ function setContext(context, value, owner = currentOwner) {
|
|
|
273
216
|
if (!owner) {
|
|
274
217
|
throw new NoOwnerError();
|
|
275
218
|
}
|
|
276
|
-
owner.
|
|
277
|
-
...owner.
|
|
219
|
+
owner.p = {
|
|
220
|
+
...owner.p,
|
|
278
221
|
[context.id]: isUndefined(value) ? context.defaultValue : value
|
|
279
222
|
};
|
|
280
223
|
}
|
|
281
224
|
function hasContext(context, owner = currentOwner) {
|
|
282
|
-
return !isUndefined(owner?.
|
|
225
|
+
return !isUndefined(owner?.p[context.id]);
|
|
283
226
|
}
|
|
284
227
|
function onCleanup(fn) {
|
|
285
228
|
if (!currentOwner)
|
|
@@ -294,6 +237,13 @@ function onCleanup(fn) {
|
|
|
294
237
|
}
|
|
295
238
|
return fn;
|
|
296
239
|
}
|
|
240
|
+
function formatId(prefix, id) {
|
|
241
|
+
const num = id.toString(36), len = num.length - 1;
|
|
242
|
+
return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
|
|
243
|
+
}
|
|
244
|
+
function isUndefined(value) {
|
|
245
|
+
return typeof value === "undefined";
|
|
246
|
+
}
|
|
297
247
|
|
|
298
248
|
// src/core/flags.ts
|
|
299
249
|
var ERROR_OFFSET = 0;
|
|
@@ -310,6 +260,7 @@ var currentMask = DEFAULT_FLAGS;
|
|
|
310
260
|
var newSources = null;
|
|
311
261
|
var newSourcesIndex = 0;
|
|
312
262
|
var newFlags = 0;
|
|
263
|
+
var unobserved = [];
|
|
313
264
|
var notStale = false;
|
|
314
265
|
var updateCheck = null;
|
|
315
266
|
var staleCheck = null;
|
|
@@ -319,30 +270,33 @@ function getObserver() {
|
|
|
319
270
|
var UNCHANGED = Symbol(0);
|
|
320
271
|
var Computation = class extends Owner {
|
|
321
272
|
c = null;
|
|
322
|
-
|
|
273
|
+
d = null;
|
|
323
274
|
g;
|
|
324
|
-
|
|
275
|
+
F;
|
|
325
276
|
z;
|
|
326
277
|
// Used in __DEV__ mode, hopefully removed in production
|
|
327
|
-
|
|
278
|
+
ca;
|
|
328
279
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
329
280
|
// which could enable more efficient DIRTY notification
|
|
330
|
-
|
|
281
|
+
R = isEqual;
|
|
331
282
|
X;
|
|
283
|
+
_ = false;
|
|
332
284
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
333
285
|
f = 0;
|
|
334
286
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
335
|
-
|
|
287
|
+
S = DEFAULT_FLAGS;
|
|
336
288
|
A = -1;
|
|
337
|
-
|
|
289
|
+
w = false;
|
|
338
290
|
constructor(initialValue, compute2, options) {
|
|
339
|
-
super(
|
|
291
|
+
super(options?.id, compute2 === null);
|
|
340
292
|
this.z = compute2;
|
|
341
293
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
342
294
|
this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
343
295
|
this.g = initialValue;
|
|
344
296
|
if (options?.equals !== void 0)
|
|
345
|
-
this.
|
|
297
|
+
this.R = options.equals;
|
|
298
|
+
if (options?.pureWrite)
|
|
299
|
+
this._ = true;
|
|
346
300
|
if (options?.unobserved)
|
|
347
301
|
this.X = options?.unobserved;
|
|
348
302
|
}
|
|
@@ -356,7 +310,7 @@ var Computation = class extends Owner {
|
|
|
356
310
|
track(this);
|
|
357
311
|
newFlags |= this.f & ~currentMask;
|
|
358
312
|
if (this.f & ERROR_BIT) {
|
|
359
|
-
throw this.
|
|
313
|
+
throw this.F;
|
|
360
314
|
} else {
|
|
361
315
|
return this.g;
|
|
362
316
|
}
|
|
@@ -393,20 +347,21 @@ var Computation = class extends Owner {
|
|
|
393
347
|
/** Update the computation with a new value. */
|
|
394
348
|
write(value, flags = 0, raw = false) {
|
|
395
349
|
const newValue = !raw && typeof value === "function" ? value(this.g) : value;
|
|
396
|
-
const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || this.
|
|
350
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
|
|
351
|
+
this.R === false || !this.R(this.g, newValue));
|
|
397
352
|
if (valueChanged) {
|
|
398
353
|
this.g = newValue;
|
|
399
|
-
this.
|
|
354
|
+
this.F = void 0;
|
|
400
355
|
}
|
|
401
356
|
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
402
357
|
this.f = flags;
|
|
403
358
|
this.A = getClock() + 1;
|
|
404
|
-
if (this.
|
|
405
|
-
for (let i = 0; i < this.
|
|
359
|
+
if (this.d) {
|
|
360
|
+
for (let i = 0; i < this.d.length; i++) {
|
|
406
361
|
if (valueChanged) {
|
|
407
|
-
this.
|
|
362
|
+
this.d[i].r(STATE_DIRTY);
|
|
408
363
|
} else if (changedFlagsMask) {
|
|
409
|
-
this.
|
|
364
|
+
this.d[i].Z(changedFlagsMask, changedFlags);
|
|
410
365
|
}
|
|
411
366
|
}
|
|
412
367
|
}
|
|
@@ -416,13 +371,13 @@ var Computation = class extends Owner {
|
|
|
416
371
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
417
372
|
*/
|
|
418
373
|
r(state, skipQueue) {
|
|
419
|
-
if (this.a >= state && !this.
|
|
374
|
+
if (this.a >= state && !this.w)
|
|
420
375
|
return;
|
|
421
|
-
this.
|
|
376
|
+
this.w = !!skipQueue;
|
|
422
377
|
this.a = state;
|
|
423
|
-
if (this.
|
|
424
|
-
for (let i = 0; i < this.
|
|
425
|
-
this.
|
|
378
|
+
if (this.d) {
|
|
379
|
+
for (let i = 0; i < this.d.length; i++) {
|
|
380
|
+
this.d[i].r(STATE_CHECK, skipQueue);
|
|
426
381
|
}
|
|
427
382
|
}
|
|
428
383
|
}
|
|
@@ -435,7 +390,7 @@ var Computation = class extends Owner {
|
|
|
435
390
|
Z(mask, newFlags2) {
|
|
436
391
|
if (this.a >= STATE_DIRTY)
|
|
437
392
|
return;
|
|
438
|
-
if (mask & this.
|
|
393
|
+
if (mask & this.S) {
|
|
439
394
|
this.r(STATE_DIRTY);
|
|
440
395
|
return;
|
|
441
396
|
}
|
|
@@ -447,15 +402,15 @@ var Computation = class extends Owner {
|
|
|
447
402
|
this.r(STATE_CHECK);
|
|
448
403
|
} else {
|
|
449
404
|
this.f ^= deltaFlags;
|
|
450
|
-
if (this.
|
|
451
|
-
for (let i = 0; i < this.
|
|
452
|
-
this.
|
|
405
|
+
if (this.d) {
|
|
406
|
+
for (let i = 0; i < this.d.length; i++) {
|
|
407
|
+
this.d[i].Z(mask, newFlags2);
|
|
453
408
|
}
|
|
454
409
|
}
|
|
455
410
|
}
|
|
456
411
|
}
|
|
457
412
|
L(error) {
|
|
458
|
-
this.
|
|
413
|
+
this.F = error;
|
|
459
414
|
this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
460
415
|
}
|
|
461
416
|
/**
|
|
@@ -548,15 +503,16 @@ function update(node) {
|
|
|
548
503
|
let source;
|
|
549
504
|
for (let i = newSourcesIndex; i < node.c.length; i++) {
|
|
550
505
|
source = node.c[i];
|
|
551
|
-
if (!source.
|
|
552
|
-
source.
|
|
506
|
+
if (!source.d)
|
|
507
|
+
source.d = [node];
|
|
553
508
|
else
|
|
554
|
-
source.
|
|
509
|
+
source.d.push(node);
|
|
555
510
|
}
|
|
556
511
|
} else if (node.c && newSourcesIndex < node.c.length) {
|
|
557
512
|
removeSourceObservers(node, newSourcesIndex);
|
|
558
513
|
node.c.length = newSourcesIndex;
|
|
559
514
|
}
|
|
515
|
+
unobserved.length && notifyUnobserved();
|
|
560
516
|
newSources = prevSources;
|
|
561
517
|
newSourcesIndex = prevSourcesIndex;
|
|
562
518
|
newFlags = prevFlags;
|
|
@@ -569,15 +525,23 @@ function removeSourceObservers(node, index) {
|
|
|
569
525
|
let swap;
|
|
570
526
|
for (let i = index; i < node.c.length; i++) {
|
|
571
527
|
source = node.c[i];
|
|
572
|
-
if (source.
|
|
573
|
-
swap = source.
|
|
574
|
-
source.
|
|
575
|
-
source.
|
|
576
|
-
if (!source.
|
|
577
|
-
|
|
528
|
+
if (source.d) {
|
|
529
|
+
swap = source.d.indexOf(node);
|
|
530
|
+
source.d[swap] = source.d[source.d.length - 1];
|
|
531
|
+
source.d.pop();
|
|
532
|
+
if (!source.d.length)
|
|
533
|
+
unobserved.push(source);
|
|
578
534
|
}
|
|
579
535
|
}
|
|
580
536
|
}
|
|
537
|
+
function notifyUnobserved() {
|
|
538
|
+
for (let i = 0; i < unobserved.length; i++) {
|
|
539
|
+
const source = unobserved[i];
|
|
540
|
+
if (!source.d || !source.d.length)
|
|
541
|
+
unobserved[i].X?.();
|
|
542
|
+
}
|
|
543
|
+
unobserved = [];
|
|
544
|
+
}
|
|
581
545
|
function isEqual(a, b) {
|
|
582
546
|
return a === b;
|
|
583
547
|
}
|
|
@@ -616,7 +580,7 @@ function isPending(fn, loadingValue) {
|
|
|
616
580
|
if (!currentObserver)
|
|
617
581
|
return pendingCheck(fn, loadingValue);
|
|
618
582
|
const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
|
|
619
|
-
c.
|
|
583
|
+
c.S |= LOADING_BIT;
|
|
620
584
|
return c.read();
|
|
621
585
|
}
|
|
622
586
|
function latest(fn, fallback) {
|
|
@@ -664,10 +628,10 @@ function runWithObserver(observer, run) {
|
|
|
664
628
|
let source;
|
|
665
629
|
for (let i = newSourcesIndex; i < observer.c.length; i++) {
|
|
666
630
|
source = observer.c[i];
|
|
667
|
-
if (!source.
|
|
668
|
-
source.
|
|
631
|
+
if (!source.d)
|
|
632
|
+
source.d = [observer];
|
|
669
633
|
else
|
|
670
|
-
source.
|
|
634
|
+
source.d.push(observer);
|
|
671
635
|
}
|
|
672
636
|
}
|
|
673
637
|
newSources = prevSources;
|
|
@@ -678,7 +642,7 @@ function runWithObserver(observer, run) {
|
|
|
678
642
|
function compute(owner, fn, observer) {
|
|
679
643
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
680
644
|
currentObserver = observer;
|
|
681
|
-
currentMask = observer?.
|
|
645
|
+
currentMask = observer?.S ?? DEFAULT_FLAGS;
|
|
682
646
|
notStale = true;
|
|
683
647
|
try {
|
|
684
648
|
return fn(observer ? observer.g : void 0);
|
|
@@ -689,94 +653,32 @@ function compute(owner, fn, observer) {
|
|
|
689
653
|
notStale = prevNotStale;
|
|
690
654
|
}
|
|
691
655
|
}
|
|
692
|
-
function flatten(children, options) {
|
|
693
|
-
try {
|
|
694
|
-
if (typeof children === "function" && !children.length) {
|
|
695
|
-
if (options?.doNotUnwrap)
|
|
696
|
-
return children;
|
|
697
|
-
do {
|
|
698
|
-
children = children();
|
|
699
|
-
} while (typeof children === "function" && !children.length);
|
|
700
|
-
}
|
|
701
|
-
if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
|
|
702
|
-
return;
|
|
703
|
-
if (Array.isArray(children)) {
|
|
704
|
-
let results = [];
|
|
705
|
-
if (flattenArray(children, results, options)) {
|
|
706
|
-
return () => {
|
|
707
|
-
let nested = [];
|
|
708
|
-
flattenArray(results, nested, { ...options, doNotUnwrap: false });
|
|
709
|
-
return nested;
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
return results;
|
|
713
|
-
}
|
|
714
|
-
return children;
|
|
715
|
-
} catch (e) {
|
|
716
|
-
if (options?.skipNonRendered && e instanceof NotReadyError) {
|
|
717
|
-
newFlags |= LOADING_BIT;
|
|
718
|
-
return void 0;
|
|
719
|
-
}
|
|
720
|
-
throw e;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
function flattenArray(children, results = [], options) {
|
|
724
|
-
let notReady = null;
|
|
725
|
-
let needsUnwrap = false;
|
|
726
|
-
for (let i = 0; i < children.length; i++) {
|
|
727
|
-
try {
|
|
728
|
-
let child = children[i];
|
|
729
|
-
if (typeof child === "function" && !child.length) {
|
|
730
|
-
if (options?.doNotUnwrap) {
|
|
731
|
-
results.push(child);
|
|
732
|
-
needsUnwrap = true;
|
|
733
|
-
continue;
|
|
734
|
-
}
|
|
735
|
-
do {
|
|
736
|
-
child = child();
|
|
737
|
-
} while (typeof child === "function" && !child.length);
|
|
738
|
-
}
|
|
739
|
-
if (Array.isArray(child)) {
|
|
740
|
-
needsUnwrap = flattenArray(child, results, options);
|
|
741
|
-
} else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
|
|
742
|
-
} else
|
|
743
|
-
results.push(child);
|
|
744
|
-
} catch (e) {
|
|
745
|
-
if (!(e instanceof NotReadyError))
|
|
746
|
-
throw e;
|
|
747
|
-
notReady = e;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
if (notReady)
|
|
751
|
-
throw notReady;
|
|
752
|
-
return needsUnwrap;
|
|
753
|
-
}
|
|
754
656
|
|
|
755
657
|
// src/core/effect.ts
|
|
756
658
|
var Effect = class extends Computation {
|
|
659
|
+
T;
|
|
757
660
|
M;
|
|
758
|
-
|
|
759
|
-
C;
|
|
661
|
+
B;
|
|
760
662
|
U = false;
|
|
761
|
-
|
|
762
|
-
|
|
663
|
+
N;
|
|
664
|
+
s;
|
|
763
665
|
constructor(initialValue, compute2, effect, error, options) {
|
|
764
666
|
super(initialValue, compute2, options);
|
|
765
|
-
this.
|
|
766
|
-
this.
|
|
767
|
-
this.
|
|
768
|
-
this.
|
|
769
|
-
if (this.
|
|
667
|
+
this.T = effect;
|
|
668
|
+
this.M = error;
|
|
669
|
+
this.N = initialValue;
|
|
670
|
+
this.s = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
671
|
+
if (this.s === EFFECT_RENDER) {
|
|
770
672
|
this.z = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
771
673
|
}
|
|
772
674
|
this.x();
|
|
773
|
-
!options?.defer && (this.
|
|
675
|
+
!options?.defer && (this.s === EFFECT_USER ? this.h.enqueue(this.s, this.V.bind(this)) : this.V(this.s));
|
|
774
676
|
}
|
|
775
677
|
write(value, flags = 0) {
|
|
776
678
|
if (this.a == STATE_DIRTY) {
|
|
777
679
|
this.f;
|
|
778
680
|
this.f = flags;
|
|
779
|
-
if (this.
|
|
681
|
+
if (this.s === EFFECT_RENDER) {
|
|
780
682
|
this.h.notify(this, LOADING_BIT | ERROR_BIT, flags);
|
|
781
683
|
}
|
|
782
684
|
}
|
|
@@ -790,17 +692,19 @@ var Effect = class extends Computation {
|
|
|
790
692
|
if (this.a >= state || skipQueue)
|
|
791
693
|
return;
|
|
792
694
|
if (this.a === STATE_CLEAN)
|
|
793
|
-
this.h.enqueue(this.
|
|
695
|
+
this.h.enqueue(this.s, this.V.bind(this));
|
|
794
696
|
this.a = state;
|
|
795
697
|
}
|
|
796
698
|
L(error) {
|
|
797
|
-
this.
|
|
798
|
-
this.C?.();
|
|
699
|
+
this.F = error;
|
|
799
700
|
this.h.notify(this, LOADING_BIT, 0);
|
|
800
701
|
this.f = ERROR_BIT;
|
|
801
|
-
if (this.
|
|
702
|
+
if (this.s === EFFECT_USER) {
|
|
802
703
|
try {
|
|
803
|
-
return this.
|
|
704
|
+
return this.M ? this.M(error, () => {
|
|
705
|
+
this.B?.();
|
|
706
|
+
this.B = void 0;
|
|
707
|
+
}) : console.error(error);
|
|
804
708
|
} catch (e) {
|
|
805
709
|
error = e;
|
|
806
710
|
}
|
|
@@ -811,179 +715,72 @@ var Effect = class extends Computation {
|
|
|
811
715
|
y() {
|
|
812
716
|
if (this.a === STATE_DISPOSED)
|
|
813
717
|
return;
|
|
814
|
-
this.
|
|
815
|
-
this.O = void 0;
|
|
718
|
+
this.T = void 0;
|
|
816
719
|
this.N = void 0;
|
|
817
|
-
this.
|
|
818
|
-
this.
|
|
720
|
+
this.M = void 0;
|
|
721
|
+
this.B?.();
|
|
722
|
+
this.B = void 0;
|
|
819
723
|
super.y();
|
|
820
724
|
}
|
|
821
|
-
V() {
|
|
822
|
-
if (
|
|
823
|
-
this.
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
725
|
+
V(type) {
|
|
726
|
+
if (type) {
|
|
727
|
+
if (this.U && this.a !== STATE_DISPOSED) {
|
|
728
|
+
this.B?.();
|
|
729
|
+
try {
|
|
730
|
+
this.B = this.T(this.g, this.N);
|
|
731
|
+
} catch (e) {
|
|
732
|
+
if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
|
|
733
|
+
throw e;
|
|
734
|
+
} finally {
|
|
735
|
+
this.N = this.g;
|
|
736
|
+
this.U = false;
|
|
737
|
+
}
|
|
832
738
|
}
|
|
833
|
-
}
|
|
739
|
+
} else
|
|
740
|
+
this.a !== STATE_CLEAN && runTop(this);
|
|
834
741
|
}
|
|
835
742
|
};
|
|
743
|
+
function runComputation() {
|
|
744
|
+
this.a !== STATE_CLEAN && runTop(this);
|
|
745
|
+
}
|
|
836
746
|
var EagerComputation = class extends Computation {
|
|
837
747
|
constructor(initialValue, compute2, options) {
|
|
838
748
|
super(initialValue, compute2, options);
|
|
839
749
|
!options?.defer && this.x();
|
|
840
750
|
}
|
|
841
751
|
r(state, skipQueue) {
|
|
842
|
-
if (this.a >= state && !this.
|
|
752
|
+
if (this.a >= state && !this.w)
|
|
843
753
|
return;
|
|
844
|
-
if (this.a === STATE_CLEAN &&
|
|
845
|
-
this.h.enqueue(EFFECT_PURE, this);
|
|
754
|
+
if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.w))
|
|
755
|
+
this.h.enqueue(EFFECT_PURE, runComputation.bind(this));
|
|
846
756
|
super.r(state, skipQueue);
|
|
847
757
|
}
|
|
848
758
|
};
|
|
849
|
-
var
|
|
759
|
+
var FirewallComputation = class extends Computation {
|
|
760
|
+
firewall = true;
|
|
850
761
|
constructor(compute2) {
|
|
851
762
|
super(void 0, compute2);
|
|
852
763
|
}
|
|
853
764
|
r(state, skipQueue) {
|
|
854
|
-
if (this.a >= state && !this.
|
|
765
|
+
if (this.a >= state && !this.w)
|
|
855
766
|
return;
|
|
856
|
-
if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.
|
|
857
|
-
this.h.enqueue(EFFECT_PURE, this);
|
|
767
|
+
if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.w))
|
|
768
|
+
this.h.enqueue(EFFECT_PURE, runComputation.bind(this));
|
|
858
769
|
super.r(state, true);
|
|
859
|
-
this.
|
|
770
|
+
this.w = !!skipQueue;
|
|
860
771
|
}
|
|
861
772
|
};
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
super(void 0, compute2, { defer: true });
|
|
868
|
-
this.H = propagationMask;
|
|
869
|
-
}
|
|
870
|
-
write(value, flags) {
|
|
871
|
-
super.write(value, flags & ~this.H);
|
|
872
|
-
if (this.H & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
|
|
873
|
-
flags &= ~LOADING_BIT;
|
|
874
|
-
}
|
|
875
|
-
this.h.notify(this, this.H, flags);
|
|
876
|
-
return this.g;
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
function createBoundChildren(owner, fn, queue, mask) {
|
|
880
|
-
const parentQueue = owner.h;
|
|
881
|
-
parentQueue.addChild(owner.h = queue);
|
|
882
|
-
onCleanup(() => parentQueue.removeChild(owner.h));
|
|
883
|
-
return compute(
|
|
884
|
-
owner,
|
|
885
|
-
() => {
|
|
886
|
-
const c = new Computation(void 0, fn);
|
|
887
|
-
return new BoundaryComputation(() => flatten(c.wait()), mask);
|
|
888
|
-
},
|
|
889
|
-
null
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
var ConditionalQueue = class extends Queue {
|
|
893
|
-
p;
|
|
894
|
-
P = /* @__PURE__ */ new Set();
|
|
895
|
-
Q = /* @__PURE__ */ new Set();
|
|
896
|
-
constructor(disabled) {
|
|
897
|
-
super();
|
|
898
|
-
this.p = disabled;
|
|
899
|
-
}
|
|
900
|
-
run(type) {
|
|
901
|
-
if (type && this.p.read())
|
|
902
|
-
return;
|
|
903
|
-
return super.run(type);
|
|
904
|
-
}
|
|
905
|
-
notify(node, type, flags) {
|
|
906
|
-
if (this.p.read()) {
|
|
907
|
-
if (type === LOADING_BIT) {
|
|
908
|
-
flags & LOADING_BIT ? this.Q.add(node) : this.Q.delete(node);
|
|
909
|
-
}
|
|
910
|
-
if (type === ERROR_BIT) {
|
|
911
|
-
flags & ERROR_BIT ? this.P.add(node) : this.P.delete(node);
|
|
912
|
-
}
|
|
913
|
-
return true;
|
|
773
|
+
function runTop(node) {
|
|
774
|
+
const ancestors = [];
|
|
775
|
+
for (let current = node; current !== null; current = current.o) {
|
|
776
|
+
if (current.a !== STATE_CLEAN) {
|
|
777
|
+
ancestors.push(current);
|
|
914
778
|
}
|
|
915
|
-
return super.notify(node, type, flags);
|
|
916
779
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
b = /* @__PURE__ */ new Set();
|
|
921
|
-
p = new Computation(false, null);
|
|
922
|
-
constructor(type) {
|
|
923
|
-
super();
|
|
924
|
-
this.R = type;
|
|
925
|
-
}
|
|
926
|
-
notify(node, type, flags) {
|
|
927
|
-
if (!(type & this.R))
|
|
928
|
-
return super.notify(node, type, flags);
|
|
929
|
-
if (flags & this.R) {
|
|
930
|
-
this.b.add(node);
|
|
931
|
-
if (this.b.size === 1)
|
|
932
|
-
this.p.write(true);
|
|
933
|
-
} else {
|
|
934
|
-
this.b.delete(node);
|
|
935
|
-
if (this.b.size === 0)
|
|
936
|
-
this.p.write(false);
|
|
937
|
-
}
|
|
938
|
-
type &= ~this.R;
|
|
939
|
-
return type ? super.notify(node, type, flags) : true;
|
|
780
|
+
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
781
|
+
if (ancestors[i].a !== STATE_DISPOSED)
|
|
782
|
+
ancestors[i].x();
|
|
940
783
|
}
|
|
941
|
-
};
|
|
942
|
-
function createBoundary(fn, condition) {
|
|
943
|
-
const owner = new Owner();
|
|
944
|
-
const queue = new ConditionalQueue(new Computation(void 0, () => condition() === "hidden" /* HIDDEN */));
|
|
945
|
-
const tree = createBoundChildren(owner, fn, queue, 0);
|
|
946
|
-
new EagerComputation(void 0, () => {
|
|
947
|
-
const disabled = queue.p.read();
|
|
948
|
-
tree.H = disabled ? ERROR_BIT | LOADING_BIT : 0;
|
|
949
|
-
if (!disabled) {
|
|
950
|
-
queue.Q.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
|
|
951
|
-
queue.P.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
|
|
952
|
-
queue.Q.clear();
|
|
953
|
-
queue.P.clear();
|
|
954
|
-
}
|
|
955
|
-
});
|
|
956
|
-
return () => queue.p.read() ? void 0 : tree.read();
|
|
957
|
-
}
|
|
958
|
-
function createCollectionBoundary(type, fn, fallback) {
|
|
959
|
-
const owner = new Owner();
|
|
960
|
-
const queue = new CollectionQueue(type);
|
|
961
|
-
const tree = createBoundChildren(owner, fn, queue, type);
|
|
962
|
-
const decision = new Computation(void 0, () => {
|
|
963
|
-
if (!queue.p.read()) {
|
|
964
|
-
const resolved = tree.read();
|
|
965
|
-
if (!queue.p.read())
|
|
966
|
-
return resolved;
|
|
967
|
-
}
|
|
968
|
-
return fallback(queue);
|
|
969
|
-
});
|
|
970
|
-
return decision.read.bind(decision);
|
|
971
|
-
}
|
|
972
|
-
function createSuspense(fn, fallback) {
|
|
973
|
-
return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
|
|
974
|
-
}
|
|
975
|
-
function createErrorBoundary(fn, fallback) {
|
|
976
|
-
return createCollectionBoundary(
|
|
977
|
-
ERROR_BIT,
|
|
978
|
-
fn,
|
|
979
|
-
(queue) => fallback(queue.b.values().next().value.G, () => {
|
|
980
|
-
incrementClock();
|
|
981
|
-
for (let node of queue.b) {
|
|
982
|
-
node.a = STATE_DIRTY;
|
|
983
|
-
node.h?.enqueue(node.u, node);
|
|
984
|
-
}
|
|
985
|
-
})
|
|
986
|
-
);
|
|
987
784
|
}
|
|
988
785
|
|
|
989
786
|
// src/signals.ts
|
|
@@ -999,7 +796,13 @@ function createSignal(first, second, third) {
|
|
|
999
796
|
});
|
|
1000
797
|
return [() => memo()[0](), (value) => memo()[1](value)];
|
|
1001
798
|
}
|
|
1002
|
-
const
|
|
799
|
+
const o = getOwner();
|
|
800
|
+
const needsId = o?.id != null;
|
|
801
|
+
const node = new Computation(
|
|
802
|
+
first,
|
|
803
|
+
null,
|
|
804
|
+
needsId ? { id: o.getNextChildId(), ...second } : second
|
|
805
|
+
);
|
|
1003
806
|
return [node.read.bind(node), node.write.bind(node)];
|
|
1004
807
|
}
|
|
1005
808
|
function createMemo(compute2, value, options) {
|
|
@@ -1016,7 +819,7 @@ function createMemo(compute2, value, options) {
|
|
|
1016
819
|
return resolvedValue;
|
|
1017
820
|
}
|
|
1018
821
|
resolvedValue = node.wait();
|
|
1019
|
-
if (!node.c?.length && node.m?.
|
|
822
|
+
if (!node.c?.length && node.m?.o !== node) {
|
|
1020
823
|
node.dispose();
|
|
1021
824
|
node = void 0;
|
|
1022
825
|
}
|
|
@@ -1025,10 +828,12 @@ function createMemo(compute2, value, options) {
|
|
|
1025
828
|
};
|
|
1026
829
|
}
|
|
1027
830
|
function createAsync(compute2, value, options) {
|
|
831
|
+
let refreshing = false;
|
|
1028
832
|
const node = new EagerComputation(
|
|
1029
833
|
value,
|
|
1030
834
|
(p) => {
|
|
1031
|
-
const source = compute2(p);
|
|
835
|
+
const source = compute2(p, refreshing);
|
|
836
|
+
refreshing = false;
|
|
1032
837
|
const isPromise = source instanceof Promise;
|
|
1033
838
|
const iterator = source[Symbol.asyncIterator];
|
|
1034
839
|
if (!isPromise && !iterator) {
|
|
@@ -1068,14 +873,20 @@ function createAsync(compute2, value, options) {
|
|
|
1068
873
|
},
|
|
1069
874
|
options
|
|
1070
875
|
);
|
|
1071
|
-
|
|
876
|
+
const read = node.wait.bind(node);
|
|
877
|
+
read.refresh = () => {
|
|
878
|
+
node.a = STATE_DIRTY;
|
|
879
|
+
refreshing = true;
|
|
880
|
+
node.x();
|
|
881
|
+
};
|
|
882
|
+
return read;
|
|
1072
883
|
}
|
|
1073
|
-
function createEffect(compute2, effect,
|
|
884
|
+
function createEffect(compute2, effect, value, options) {
|
|
1074
885
|
void new Effect(
|
|
1075
886
|
value,
|
|
1076
887
|
compute2,
|
|
1077
|
-
effect,
|
|
1078
|
-
error,
|
|
888
|
+
effect.effect ? effect.effect : effect,
|
|
889
|
+
effect.error,
|
|
1079
890
|
options
|
|
1080
891
|
);
|
|
1081
892
|
}
|
|
@@ -1108,101 +919,97 @@ function resolve(fn) {
|
|
|
1108
919
|
});
|
|
1109
920
|
});
|
|
1110
921
|
}
|
|
922
|
+
function tryCatch(fn) {
|
|
923
|
+
try {
|
|
924
|
+
const v = fn();
|
|
925
|
+
if (v instanceof Promise) {
|
|
926
|
+
return v.then(
|
|
927
|
+
(v2) => [void 0, v2],
|
|
928
|
+
(e) => {
|
|
929
|
+
if (e instanceof NotReadyError)
|
|
930
|
+
throw e;
|
|
931
|
+
return [e];
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
return [void 0, v];
|
|
936
|
+
} catch (e) {
|
|
937
|
+
if (e instanceof NotReadyError)
|
|
938
|
+
throw e;
|
|
939
|
+
return [e];
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
function transition(fn) {
|
|
943
|
+
}
|
|
944
|
+
function createOptimistic(initial, compute2, options) {
|
|
945
|
+
return [];
|
|
946
|
+
}
|
|
1111
947
|
|
|
1112
948
|
// src/store/projection.ts
|
|
1113
949
|
function createProjection(fn, initialValue = {}) {
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
function wrapProjection(fn, store, setStore) {
|
|
1118
|
-
const node = new ProjectionComputation(() => {
|
|
1119
|
-
setStore(fn);
|
|
950
|
+
let wrappedStore;
|
|
951
|
+
const node = new FirewallComputation(() => {
|
|
952
|
+
storeSetter(wrappedStore, fn);
|
|
1120
953
|
});
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
get(target, property) {
|
|
1129
|
-
node.read();
|
|
1130
|
-
const v = target[property];
|
|
1131
|
-
return isWrappable(v) ? wrap3(v, node, wrapped) : v;
|
|
1132
|
-
},
|
|
1133
|
-
set() {
|
|
1134
|
-
throw new Error("Projections are readonly");
|
|
1135
|
-
},
|
|
1136
|
-
deleteProperty() {
|
|
1137
|
-
throw new Error("Projections are readonly");
|
|
954
|
+
const wrappedMap = /* @__PURE__ */ new WeakMap();
|
|
955
|
+
const traps = {
|
|
956
|
+
...storeTraps,
|
|
957
|
+
get(target, property, receiver) {
|
|
958
|
+
const o = getOwner();
|
|
959
|
+
(!o || o !== node) && node.wait();
|
|
960
|
+
return storeTraps.get(target, property, receiver);
|
|
1138
961
|
}
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
|
|
962
|
+
};
|
|
963
|
+
function wrapProjection(source) {
|
|
964
|
+
if (wrappedMap.has(source))
|
|
965
|
+
return wrappedMap.get(source);
|
|
966
|
+
if (source[$TARGET]?.[STORE_WRAP] === wrapProjection)
|
|
967
|
+
return source;
|
|
968
|
+
const wrapped = createStoreProxy(source, traps, {
|
|
969
|
+
[STORE_WRAP]: wrapProjection,
|
|
970
|
+
[STORE_LOOKUP]: wrappedMap
|
|
971
|
+
});
|
|
972
|
+
wrappedMap.set(source, wrapped);
|
|
973
|
+
return wrapped;
|
|
974
|
+
}
|
|
975
|
+
return wrappedStore = wrapProjection(initialValue);
|
|
1142
976
|
}
|
|
1143
977
|
|
|
1144
978
|
// src/store/store.ts
|
|
1145
|
-
var $RAW = Symbol(0);
|
|
1146
979
|
var $TRACK = Symbol(0);
|
|
1147
980
|
var $DEEP = Symbol(0);
|
|
1148
981
|
var $TARGET = Symbol(0);
|
|
1149
982
|
var $PROXY = Symbol(0);
|
|
983
|
+
var $DELETED = Symbol(0);
|
|
1150
984
|
var PARENTS = /* @__PURE__ */ new WeakMap();
|
|
1151
985
|
var STORE_VALUE = "v";
|
|
986
|
+
var STORE_OVERRIDE = "o";
|
|
1152
987
|
var STORE_NODE = "n";
|
|
1153
988
|
var STORE_HAS = "h";
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
989
|
+
var STORE_WRAP = "w";
|
|
990
|
+
var STORE_LOOKUP = "l";
|
|
991
|
+
function createStoreProxy(value, traps = storeTraps, extend) {
|
|
992
|
+
let newTarget;
|
|
993
|
+
if (Array.isArray(value)) {
|
|
994
|
+
newTarget = [];
|
|
995
|
+
newTarget.v = value;
|
|
996
|
+
} else
|
|
997
|
+
newTarget = { v: value };
|
|
998
|
+
extend && Object.assign(newTarget, extend);
|
|
999
|
+
return newTarget[$PROXY] = new Proxy(newTarget, traps);
|
|
1000
|
+
}
|
|
1001
|
+
var storeLookup = /* @__PURE__ */ new WeakMap();
|
|
1002
|
+
function wrap(value, target) {
|
|
1003
|
+
if (target?.[STORE_WRAP])
|
|
1004
|
+
return target[STORE_WRAP](value, target);
|
|
1005
|
+
let p = value[$PROXY] || storeLookup.get(value);
|
|
1006
|
+
if (!p)
|
|
1007
|
+
storeLookup.set(value, p = createStoreProxy(value));
|
|
1168
1008
|
return p;
|
|
1169
1009
|
}
|
|
1170
1010
|
function isWrappable(obj) {
|
|
1171
1011
|
return obj != null && typeof obj === "object" && !Object.isFrozen(obj);
|
|
1172
1012
|
}
|
|
1173
|
-
function unwrap(item, deep2 = true, set) {
|
|
1174
|
-
let result, unwrapped, v, prop;
|
|
1175
|
-
if (result = item != null && item[$RAW])
|
|
1176
|
-
return result;
|
|
1177
|
-
if (!deep2)
|
|
1178
|
-
return item;
|
|
1179
|
-
if (!isWrappable(item) || set?.has(item))
|
|
1180
|
-
return item;
|
|
1181
|
-
if (!set)
|
|
1182
|
-
set = /* @__PURE__ */ new Set();
|
|
1183
|
-
set.add(item);
|
|
1184
|
-
if (Array.isArray(item)) {
|
|
1185
|
-
for (let i = 0, l = item.length; i < l; i++) {
|
|
1186
|
-
v = item[i];
|
|
1187
|
-
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1188
|
-
item[i] = unwrapped;
|
|
1189
|
-
}
|
|
1190
|
-
} else {
|
|
1191
|
-
if (!deep2)
|
|
1192
|
-
return item;
|
|
1193
|
-
const keys = Object.keys(item);
|
|
1194
|
-
for (let i = 0, l = keys.length; i < l; i++) {
|
|
1195
|
-
prop = keys[i];
|
|
1196
|
-
const desc = Object.getOwnPropertyDescriptor(item, prop);
|
|
1197
|
-
if (desc.get)
|
|
1198
|
-
continue;
|
|
1199
|
-
v = item[prop];
|
|
1200
|
-
if ((unwrapped = unwrap(v, deep2, set)) !== v)
|
|
1201
|
-
item[prop] = unwrapped;
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
return item;
|
|
1205
|
-
}
|
|
1206
1013
|
function getNodes(target, type) {
|
|
1207
1014
|
let nodes = target[type];
|
|
1208
1015
|
if (!nodes)
|
|
@@ -1219,31 +1026,38 @@ function getNode(nodes, property, value, equals = isEqual) {
|
|
|
1219
1026
|
}
|
|
1220
1027
|
});
|
|
1221
1028
|
}
|
|
1222
|
-
function proxyDescriptor(target, property) {
|
|
1223
|
-
if (property === $PROXY)
|
|
1224
|
-
return { value: target[$PROXY], writable: true, configurable: true };
|
|
1225
|
-
const desc = Reflect.getOwnPropertyDescriptor(target[STORE_VALUE], property);
|
|
1226
|
-
if (!desc || desc.get || !desc.configurable)
|
|
1227
|
-
return desc;
|
|
1228
|
-
delete desc.value;
|
|
1229
|
-
delete desc.writable;
|
|
1230
|
-
desc.get = () => target[STORE_VALUE][$PROXY][property];
|
|
1231
|
-
return desc;
|
|
1232
|
-
}
|
|
1233
1029
|
function trackSelf(target, symbol = $TRACK) {
|
|
1234
1030
|
getObserver() && getNode(getNodes(target, STORE_NODE), symbol, void 0, false).read();
|
|
1235
1031
|
}
|
|
1236
|
-
function
|
|
1237
|
-
|
|
1238
|
-
|
|
1032
|
+
function getKeys(source, override, enumerable = true) {
|
|
1033
|
+
const baseKeys = untrack(() => enumerable ? Object.keys(source) : Reflect.ownKeys(source));
|
|
1034
|
+
if (!override)
|
|
1035
|
+
return baseKeys;
|
|
1036
|
+
const keys = new Set(baseKeys);
|
|
1037
|
+
const overrides = Reflect.ownKeys(override);
|
|
1038
|
+
for (const key of overrides) {
|
|
1039
|
+
if (override[key] !== $DELETED)
|
|
1040
|
+
keys.add(key);
|
|
1041
|
+
else
|
|
1042
|
+
keys.delete(key);
|
|
1043
|
+
}
|
|
1044
|
+
return Array.from(keys);
|
|
1045
|
+
}
|
|
1046
|
+
function getPropertyDescriptor(source, override, property) {
|
|
1047
|
+
let value = source;
|
|
1048
|
+
if (override && property in override) {
|
|
1049
|
+
if (value[property] === $DELETED)
|
|
1050
|
+
return void 0;
|
|
1051
|
+
if (!(property in value))
|
|
1052
|
+
value = override;
|
|
1053
|
+
}
|
|
1054
|
+
return Reflect.getOwnPropertyDescriptor(value, property);
|
|
1239
1055
|
}
|
|
1240
1056
|
var Writing = null;
|
|
1241
|
-
var
|
|
1057
|
+
var storeTraps = {
|
|
1242
1058
|
get(target, property, receiver) {
|
|
1243
1059
|
if (property === $TARGET)
|
|
1244
1060
|
return target;
|
|
1245
|
-
if (property === $RAW)
|
|
1246
|
-
return target[STORE_VALUE];
|
|
1247
1061
|
if (property === $PROXY)
|
|
1248
1062
|
return receiver;
|
|
1249
1063
|
if (property === $TRACK || property === $DEEP) {
|
|
@@ -1251,92 +1065,156 @@ var proxyTraps = {
|
|
|
1251
1065
|
return receiver;
|
|
1252
1066
|
}
|
|
1253
1067
|
const nodes = getNodes(target, STORE_NODE);
|
|
1254
|
-
const storeValue = target[STORE_VALUE];
|
|
1255
1068
|
const tracked = nodes[property];
|
|
1069
|
+
const overridden = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE];
|
|
1070
|
+
const proxySource = !!target[STORE_VALUE][$TARGET];
|
|
1071
|
+
const storeValue = overridden ? target[STORE_OVERRIDE] : target[STORE_VALUE];
|
|
1256
1072
|
if (!tracked) {
|
|
1257
1073
|
const desc = Object.getOwnPropertyDescriptor(storeValue, property);
|
|
1258
1074
|
if (desc && desc.get)
|
|
1259
1075
|
return desc.get.call(receiver);
|
|
1260
1076
|
}
|
|
1261
|
-
if (Writing?.has(
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1077
|
+
if (Writing?.has(receiver)) {
|
|
1078
|
+
let value2 = tracked && (overridden || !proxySource) ? tracked.g : storeValue[property];
|
|
1079
|
+
value2 === $DELETED && (value2 = void 0);
|
|
1080
|
+
if (!isWrappable(value2))
|
|
1081
|
+
return value2;
|
|
1082
|
+
const wrapped = wrap(value2, target);
|
|
1083
|
+
Writing.add(wrapped);
|
|
1084
|
+
return wrapped;
|
|
1085
|
+
}
|
|
1086
|
+
let value = tracked ? overridden || !proxySource ? nodes[property].read() : (nodes[property].read(), storeValue[property]) : storeValue[property];
|
|
1087
|
+
value === $DELETED && (value = void 0);
|
|
1266
1088
|
if (!tracked) {
|
|
1267
|
-
if (typeof value === "function" && !storeValue.hasOwnProperty(property)) {
|
|
1089
|
+
if (!overridden && typeof value === "function" && !storeValue.hasOwnProperty(property)) {
|
|
1268
1090
|
let proto;
|
|
1269
|
-
return !Array.isArray(
|
|
1091
|
+
return !Array.isArray(target[STORE_VALUE]) && (proto = Object.getPrototypeOf(target[STORE_VALUE])) && proto !== Object.prototype ? value.bind(storeValue) : value;
|
|
1270
1092
|
} else if (getObserver()) {
|
|
1271
|
-
return getNode(nodes, property, isWrappable(value) ?
|
|
1093
|
+
return getNode(nodes, property, isWrappable(value) ? wrap(value, target) : value).read();
|
|
1272
1094
|
}
|
|
1273
1095
|
}
|
|
1274
|
-
return isWrappable(value) ?
|
|
1096
|
+
return isWrappable(value) ? wrap(value, target) : value;
|
|
1275
1097
|
},
|
|
1276
1098
|
has(target, property) {
|
|
1277
|
-
if (property === $
|
|
1099
|
+
if (property === $PROXY || property === $TRACK || property === "__proto__")
|
|
1278
1100
|
return true;
|
|
1279
|
-
const has = property in target[STORE_VALUE];
|
|
1101
|
+
const has = target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE] ? target[STORE_OVERRIDE][property] !== $DELETED : property in target[STORE_VALUE];
|
|
1280
1102
|
getObserver() && getNode(getNodes(target, STORE_HAS), property, has).read();
|
|
1281
1103
|
return has;
|
|
1282
1104
|
},
|
|
1283
|
-
set(target, property,
|
|
1284
|
-
|
|
1105
|
+
set(target, property, rawValue) {
|
|
1106
|
+
const store = target[$PROXY];
|
|
1107
|
+
if (Writing?.has(target[$PROXY])) {
|
|
1108
|
+
untrack(() => {
|
|
1109
|
+
const state = target[STORE_VALUE];
|
|
1110
|
+
const base = state[property];
|
|
1111
|
+
const prev = target[STORE_OVERRIDE]?.[property] || base;
|
|
1112
|
+
const value = rawValue?.[$TARGET]?.[STORE_VALUE] ?? rawValue;
|
|
1113
|
+
if (prev === value)
|
|
1114
|
+
return true;
|
|
1115
|
+
const len = target[STORE_OVERRIDE]?.length || state.length;
|
|
1116
|
+
if (value !== void 0 && value === base)
|
|
1117
|
+
delete target[STORE_OVERRIDE][property];
|
|
1118
|
+
else
|
|
1119
|
+
(target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = value;
|
|
1120
|
+
const wrappable = isWrappable(value);
|
|
1121
|
+
if (isWrappable(prev)) {
|
|
1122
|
+
const parents = PARENTS.get(prev);
|
|
1123
|
+
parents && (parents instanceof Set ? parents.delete(store) : PARENTS.delete(prev));
|
|
1124
|
+
}
|
|
1125
|
+
if (recursivelyNotify(store, storeLookup) && wrappable)
|
|
1126
|
+
recursivelyAddParent(value, store);
|
|
1127
|
+
target[STORE_HAS]?.[property]?.write(true);
|
|
1128
|
+
const nodes = getNodes(target, STORE_NODE);
|
|
1129
|
+
nodes[property]?.write(wrappable ? wrap(value, target) : value);
|
|
1130
|
+
if (Array.isArray(state)) {
|
|
1131
|
+
const index = parseInt(property) + 1;
|
|
1132
|
+
if (index > len)
|
|
1133
|
+
nodes.length?.write(index);
|
|
1134
|
+
}
|
|
1135
|
+
nodes[$TRACK]?.write(void 0);
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1285
1138
|
return true;
|
|
1286
1139
|
},
|
|
1287
1140
|
deleteProperty(target, property) {
|
|
1288
|
-
Writing?.has(target[
|
|
1141
|
+
if (Writing?.has(target[$PROXY]) && target[STORE_OVERRIDE]?.[property] !== $DELETED) {
|
|
1142
|
+
untrack(() => {
|
|
1143
|
+
const prev = target[STORE_OVERRIDE]?.[property] || target[STORE_VALUE][property];
|
|
1144
|
+
if (property in target[STORE_VALUE]) {
|
|
1145
|
+
(target[STORE_OVERRIDE] || (target[STORE_OVERRIDE] = /* @__PURE__ */ Object.create(null)))[property] = $DELETED;
|
|
1146
|
+
} else if (target[STORE_OVERRIDE] && property in target[STORE_OVERRIDE]) {
|
|
1147
|
+
delete target[STORE_OVERRIDE][property];
|
|
1148
|
+
} else
|
|
1149
|
+
return true;
|
|
1150
|
+
if (isWrappable(prev)) {
|
|
1151
|
+
const parents = PARENTS.get(prev);
|
|
1152
|
+
parents && (parents instanceof Set ? parents.delete(target) : PARENTS.delete(prev));
|
|
1153
|
+
}
|
|
1154
|
+
target[STORE_HAS]?.[property]?.write(false);
|
|
1155
|
+
const nodes = getNodes(target, STORE_NODE);
|
|
1156
|
+
nodes[property]?.write(void 0);
|
|
1157
|
+
nodes[$TRACK]?.write(void 0);
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1289
1160
|
return true;
|
|
1290
1161
|
},
|
|
1291
|
-
ownKeys
|
|
1292
|
-
|
|
1162
|
+
ownKeys(target) {
|
|
1163
|
+
trackSelf(target);
|
|
1164
|
+
return getKeys(target[STORE_VALUE], target[STORE_OVERRIDE], false);
|
|
1165
|
+
},
|
|
1166
|
+
getOwnPropertyDescriptor(target, property) {
|
|
1167
|
+
if (property === $PROXY)
|
|
1168
|
+
return { value: target[$PROXY], writable: true, configurable: true };
|
|
1169
|
+
return getPropertyDescriptor(target[STORE_VALUE], target[STORE_OVERRIDE], property);
|
|
1170
|
+
},
|
|
1293
1171
|
getPrototypeOf(target) {
|
|
1294
1172
|
return Object.getPrototypeOf(target[STORE_VALUE]);
|
|
1295
1173
|
}
|
|
1296
1174
|
};
|
|
1297
|
-
function
|
|
1298
|
-
const
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
if (!target)
|
|
1315
|
-
return;
|
|
1316
|
-
if (deleting)
|
|
1317
|
-
target[STORE_HAS]?.[property]?.write(false);
|
|
1318
|
-
else
|
|
1319
|
-
target[STORE_HAS]?.[property]?.write(true);
|
|
1320
|
-
const nodes = getNodes(target, STORE_NODE);
|
|
1321
|
-
nodes[property]?.write(wrappable ? wrap2(value) : value);
|
|
1322
|
-
Array.isArray(state) && state.length !== len && nodes.length?.write(state.length);
|
|
1323
|
-
nodes[$TRACK]?.write(void 0);
|
|
1324
|
-
}
|
|
1325
|
-
function recursivelyNotify(state) {
|
|
1326
|
-
let target = state[$PROXY]?.[$TARGET];
|
|
1175
|
+
function storeSetter(store, fn) {
|
|
1176
|
+
const prevWriting = Writing;
|
|
1177
|
+
Writing = /* @__PURE__ */ new Set();
|
|
1178
|
+
Writing.add(store);
|
|
1179
|
+
try {
|
|
1180
|
+
fn(store);
|
|
1181
|
+
} finally {
|
|
1182
|
+
Writing.clear();
|
|
1183
|
+
Writing = prevWriting;
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
function createStore(first, second) {
|
|
1187
|
+
const derived = typeof first === "function", wrappedStore = derived ? createProjection(first, second) : wrap(first);
|
|
1188
|
+
return [wrappedStore, (fn) => storeSetter(wrappedStore, fn)];
|
|
1189
|
+
}
|
|
1190
|
+
function recursivelyNotify(state, lookup) {
|
|
1191
|
+
let target = state[$TARGET] || lookup?.get(state)?.[$TARGET];
|
|
1327
1192
|
let notified = false;
|
|
1328
|
-
|
|
1329
|
-
|
|
1193
|
+
if (target) {
|
|
1194
|
+
const deep2 = getNodes(target, STORE_NODE)[$DEEP];
|
|
1195
|
+
if (deep2) {
|
|
1196
|
+
deep2.write(void 0);
|
|
1197
|
+
notified = true;
|
|
1198
|
+
}
|
|
1199
|
+
lookup = target[STORE_LOOKUP] || lookup;
|
|
1200
|
+
}
|
|
1201
|
+
const parents = PARENTS.get(target?.[STORE_VALUE] || state);
|
|
1330
1202
|
if (!parents)
|
|
1331
1203
|
return notified;
|
|
1332
1204
|
if (parents instanceof Set) {
|
|
1333
1205
|
for (let parent of parents)
|
|
1334
|
-
notified = recursivelyNotify(parent) || notified;
|
|
1206
|
+
notified = recursivelyNotify(parent, lookup) || notified;
|
|
1335
1207
|
} else
|
|
1336
|
-
notified = recursivelyNotify(parents) || notified;
|
|
1208
|
+
notified = recursivelyNotify(parents, lookup) || notified;
|
|
1337
1209
|
return notified;
|
|
1338
1210
|
}
|
|
1339
1211
|
function recursivelyAddParent(state, parent) {
|
|
1212
|
+
let override;
|
|
1213
|
+
const target = state[$TARGET];
|
|
1214
|
+
if (target) {
|
|
1215
|
+
override = target[STORE_OVERRIDE];
|
|
1216
|
+
state = target[STORE_VALUE];
|
|
1217
|
+
}
|
|
1340
1218
|
if (parent) {
|
|
1341
1219
|
let parents = PARENTS.get(state);
|
|
1342
1220
|
if (!parents)
|
|
@@ -1351,80 +1229,73 @@ function recursivelyAddParent(state, parent) {
|
|
|
1351
1229
|
return;
|
|
1352
1230
|
}
|
|
1353
1231
|
if (Array.isArray(state)) {
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1232
|
+
const len = override?.length || state.length;
|
|
1233
|
+
for (let i = 0; i < len; i++) {
|
|
1234
|
+
const item = override && i in override ? override[i] : state[i];
|
|
1235
|
+
isWrappable(item) && recursivelyAddParent(item, state);
|
|
1357
1236
|
}
|
|
1358
1237
|
} else {
|
|
1359
|
-
const keys =
|
|
1238
|
+
const keys = getKeys(state, override);
|
|
1360
1239
|
for (let i = 0; i < keys.length; i++) {
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1240
|
+
const key = keys[i];
|
|
1241
|
+
const item = override && key in override ? override[key] : state[key];
|
|
1242
|
+
isWrappable(item) && recursivelyAddParent(item, state);
|
|
1363
1243
|
}
|
|
1364
1244
|
}
|
|
1365
1245
|
}
|
|
1366
|
-
function createStore(first, second) {
|
|
1367
|
-
const derived = typeof first === "function", store = derived ? second : first;
|
|
1368
|
-
const unwrappedStore = unwrap(store);
|
|
1369
|
-
let wrappedStore = wrap2(unwrappedStore);
|
|
1370
|
-
const setStore = (fn) => {
|
|
1371
|
-
const prevWriting = Writing;
|
|
1372
|
-
Writing = /* @__PURE__ */ new Set();
|
|
1373
|
-
Writing.add(unwrappedStore);
|
|
1374
|
-
try {
|
|
1375
|
-
fn(wrappedStore);
|
|
1376
|
-
} finally {
|
|
1377
|
-
Writing.clear();
|
|
1378
|
-
Writing = prevWriting;
|
|
1379
|
-
}
|
|
1380
|
-
};
|
|
1381
|
-
if (derived)
|
|
1382
|
-
return wrapProjection(first, wrappedStore, setStore);
|
|
1383
|
-
return [wrappedStore, setStore];
|
|
1384
|
-
}
|
|
1385
1246
|
function deep(store) {
|
|
1386
|
-
recursivelyAddParent(store
|
|
1247
|
+
recursivelyAddParent(store);
|
|
1387
1248
|
return store[$DEEP];
|
|
1388
1249
|
}
|
|
1389
1250
|
|
|
1390
1251
|
// src/store/reconcile.ts
|
|
1391
|
-
function
|
|
1252
|
+
function unwrap(value) {
|
|
1253
|
+
return value?.[$TARGET]?.[STORE_NODE] ?? value;
|
|
1254
|
+
}
|
|
1255
|
+
function getOverrideValue(value, override, key) {
|
|
1256
|
+
return override && key in override ? override[key] : value[key];
|
|
1257
|
+
}
|
|
1258
|
+
function getAllKeys(value, override, next) {
|
|
1259
|
+
const keys = getKeys(value, override);
|
|
1260
|
+
const nextKeys = Object.keys(next);
|
|
1261
|
+
return Array.from(/* @__PURE__ */ new Set([...keys, ...nextKeys]));
|
|
1262
|
+
}
|
|
1263
|
+
function applyState(next, state, keyFn, all) {
|
|
1392
1264
|
const target = state?.[$TARGET];
|
|
1393
1265
|
if (!target)
|
|
1394
1266
|
return;
|
|
1395
1267
|
const previous = target[STORE_VALUE];
|
|
1396
|
-
|
|
1268
|
+
const override = target[STORE_OVERRIDE];
|
|
1269
|
+
if (next === previous && !override)
|
|
1397
1270
|
return;
|
|
1398
|
-
|
|
1399
|
-
value: previous[$PROXY],
|
|
1400
|
-
writable: true
|
|
1401
|
-
});
|
|
1402
|
-
previous[$PROXY] = null;
|
|
1271
|
+
(target[STORE_LOOKUP] || storeLookup).set(next, target[$PROXY]);
|
|
1403
1272
|
target[STORE_VALUE] = next;
|
|
1273
|
+
target[STORE_OVERRIDE] = void 0;
|
|
1404
1274
|
if (Array.isArray(previous)) {
|
|
1405
1275
|
let changed = false;
|
|
1406
|
-
|
|
1276
|
+
const prevLength = getOverrideValue(previous, override, "length");
|
|
1277
|
+
if (next.length && prevLength && next[0] && keyFn(next[0]) != null) {
|
|
1407
1278
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
1408
|
-
for (start = 0, end = Math.min(
|
|
1409
|
-
applyState(next[start],
|
|
1279
|
+
for (start = 0, end = Math.min(prevLength, next.length); start < end && ((item = getOverrideValue(previous, override, start)) === next[start] || item && next[start] && keyFn(item) === keyFn(next[start])); start++) {
|
|
1280
|
+
applyState(next[start], wrap(item, target), keyFn, all);
|
|
1410
1281
|
}
|
|
1411
1282
|
const temp = new Array(next.length), newIndices = /* @__PURE__ */ new Map();
|
|
1412
|
-
for (end =
|
|
1413
|
-
temp[newEnd] =
|
|
1283
|
+
for (end = prevLength - 1, newEnd = next.length - 1; end >= start && newEnd >= start && ((item = getOverrideValue(previous, override, end)) === next[newEnd] || item && next[newEnd] && keyFn(item) === keyFn(next[newEnd])); end--, newEnd--) {
|
|
1284
|
+
temp[newEnd] = item;
|
|
1414
1285
|
}
|
|
1415
1286
|
if (start > newEnd || start > end) {
|
|
1416
1287
|
for (j = start; j <= newEnd; j++) {
|
|
1417
1288
|
changed = true;
|
|
1418
|
-
target[STORE_NODE][j]?.write(
|
|
1289
|
+
target[STORE_NODE][j]?.write(wrap(next[j], target));
|
|
1419
1290
|
}
|
|
1420
1291
|
for (; j < next.length; j++) {
|
|
1421
1292
|
changed = true;
|
|
1422
|
-
const wrapped =
|
|
1293
|
+
const wrapped = wrap(temp[j], target);
|
|
1423
1294
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1424
|
-
applyState(next[j], wrapped, keyFn);
|
|
1295
|
+
applyState(next[j], wrapped, keyFn, all);
|
|
1425
1296
|
}
|
|
1426
1297
|
changed && target[STORE_NODE][$TRACK]?.write(void 0);
|
|
1427
|
-
|
|
1298
|
+
prevLength !== next.length && target[STORE_NODE].length?.write(next.length);
|
|
1428
1299
|
return;
|
|
1429
1300
|
}
|
|
1430
1301
|
newIndicesNext = new Array(newEnd + 1);
|
|
@@ -1436,31 +1307,32 @@ function applyState(next, state, keyFn) {
|
|
|
1436
1307
|
newIndices.set(keyVal, j);
|
|
1437
1308
|
}
|
|
1438
1309
|
for (i = start; i <= end; i++) {
|
|
1439
|
-
item = previous
|
|
1310
|
+
item = getOverrideValue(previous, override, i);
|
|
1440
1311
|
keyVal = item ? keyFn(item) : item;
|
|
1441
1312
|
j = newIndices.get(keyVal);
|
|
1442
1313
|
if (j !== void 0 && j !== -1) {
|
|
1443
|
-
temp[j] =
|
|
1314
|
+
temp[j] = item;
|
|
1444
1315
|
j = newIndicesNext[j];
|
|
1445
1316
|
newIndices.set(keyVal, j);
|
|
1446
1317
|
}
|
|
1447
1318
|
}
|
|
1448
1319
|
for (j = start; j < next.length; j++) {
|
|
1449
1320
|
if (j in temp) {
|
|
1450
|
-
const wrapped =
|
|
1321
|
+
const wrapped = wrap(temp[j], target);
|
|
1451
1322
|
target[STORE_NODE][j]?.write(wrapped);
|
|
1452
|
-
applyState(next[j], wrapped, keyFn);
|
|
1323
|
+
applyState(next[j], wrapped, keyFn, all);
|
|
1453
1324
|
} else
|
|
1454
|
-
target[STORE_NODE][j]?.write(
|
|
1325
|
+
target[STORE_NODE][j]?.write(wrap(next[j], target));
|
|
1455
1326
|
}
|
|
1456
1327
|
if (start < next.length)
|
|
1457
1328
|
changed = true;
|
|
1458
|
-
} else if (
|
|
1329
|
+
} else if (prevLength && next.length) {
|
|
1459
1330
|
for (let i = 0, len = next.length; i < len; i++) {
|
|
1460
|
-
|
|
1331
|
+
const item = getOverrideValue(previous, override, i);
|
|
1332
|
+
isWrappable(item) && applyState(next[i], wrap(item, target), keyFn, all);
|
|
1461
1333
|
}
|
|
1462
1334
|
}
|
|
1463
|
-
if (
|
|
1335
|
+
if (prevLength !== next.length) {
|
|
1464
1336
|
changed = true;
|
|
1465
1337
|
target[STORE_NODE].length?.write(next.length);
|
|
1466
1338
|
}
|
|
@@ -1469,17 +1341,20 @@ function applyState(next, state, keyFn) {
|
|
|
1469
1341
|
}
|
|
1470
1342
|
let nodes = target[STORE_NODE];
|
|
1471
1343
|
if (nodes) {
|
|
1472
|
-
const
|
|
1344
|
+
const tracked = nodes[$TRACK];
|
|
1345
|
+
const keys = tracked || all ? getAllKeys(previous, override, next) : Object.keys(nodes);
|
|
1473
1346
|
for (let i = 0, len = keys.length; i < len; i++) {
|
|
1474
|
-
const
|
|
1475
|
-
const
|
|
1476
|
-
|
|
1347
|
+
const key = keys[i];
|
|
1348
|
+
const node = nodes[key];
|
|
1349
|
+
const previousValue = unwrap(getOverrideValue(previous, override, key));
|
|
1350
|
+
let nextValue = unwrap(next[key]);
|
|
1477
1351
|
if (previousValue === nextValue)
|
|
1478
1352
|
continue;
|
|
1479
|
-
if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue))
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1353
|
+
if (!previousValue || !isWrappable(previousValue) || keyFn(previousValue) != null && keyFn(previousValue) !== keyFn(nextValue)) {
|
|
1354
|
+
tracked?.write(void 0);
|
|
1355
|
+
node?.write(isWrappable(nextValue) ? wrap(nextValue, target) : nextValue);
|
|
1356
|
+
} else
|
|
1357
|
+
applyState(nextValue, wrap(previousValue, target), keyFn, all);
|
|
1483
1358
|
}
|
|
1484
1359
|
}
|
|
1485
1360
|
if (nodes = target[STORE_HAS]) {
|
|
@@ -1489,17 +1364,69 @@ function applyState(next, state, keyFn) {
|
|
|
1489
1364
|
}
|
|
1490
1365
|
}
|
|
1491
1366
|
}
|
|
1492
|
-
function reconcile(value, key) {
|
|
1367
|
+
function reconcile(value, key, all = false) {
|
|
1493
1368
|
return (state) => {
|
|
1494
1369
|
const keyFn = typeof key === "string" ? (item) => item[key] : key;
|
|
1495
|
-
|
|
1370
|
+
const eq = keyFn(state);
|
|
1371
|
+
if (eq !== void 0 && keyFn(value) !== keyFn(state))
|
|
1496
1372
|
throw new Error("Cannot reconcile states with different identity");
|
|
1497
|
-
applyState(value, state, keyFn);
|
|
1498
|
-
return state;
|
|
1373
|
+
applyState(value, state, keyFn, all);
|
|
1499
1374
|
};
|
|
1500
1375
|
}
|
|
1501
1376
|
|
|
1502
1377
|
// src/store/utils.ts
|
|
1378
|
+
function snapshot(item, map, lookup) {
|
|
1379
|
+
let target, isArray, override, result, unwrapped, v;
|
|
1380
|
+
if (!isWrappable(item))
|
|
1381
|
+
return item;
|
|
1382
|
+
if (map && map.has(item))
|
|
1383
|
+
return map.get(item);
|
|
1384
|
+
if (!map)
|
|
1385
|
+
map = /* @__PURE__ */ new Map();
|
|
1386
|
+
if (target = item[$TARGET] || lookup?.get(item)?.[$TARGET]) {
|
|
1387
|
+
override = target[STORE_OVERRIDE];
|
|
1388
|
+
isArray = Array.isArray(target[STORE_VALUE]);
|
|
1389
|
+
map.set(
|
|
1390
|
+
item,
|
|
1391
|
+
override ? result = isArray ? [] : Object.create(Object.getPrototypeOf(target[STORE_VALUE])) : target[STORE_VALUE]
|
|
1392
|
+
);
|
|
1393
|
+
item = target[STORE_VALUE];
|
|
1394
|
+
lookup = storeLookup;
|
|
1395
|
+
} else {
|
|
1396
|
+
isArray = Array.isArray(item);
|
|
1397
|
+
map.set(item, item);
|
|
1398
|
+
}
|
|
1399
|
+
if (isArray) {
|
|
1400
|
+
const len = override?.length || item.length;
|
|
1401
|
+
for (let i = 0; i < len; i++) {
|
|
1402
|
+
v = override && i in override ? override[i] : item[i];
|
|
1403
|
+
if (v === $DELETED)
|
|
1404
|
+
continue;
|
|
1405
|
+
if ((unwrapped = snapshot(v, map, lookup)) !== v || result) {
|
|
1406
|
+
if (!result)
|
|
1407
|
+
map.set(item, result = [...item]);
|
|
1408
|
+
result[i] = unwrapped;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
} else {
|
|
1412
|
+
const keys = getKeys(item, override);
|
|
1413
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
1414
|
+
let prop = keys[i];
|
|
1415
|
+
const desc = getPropertyDescriptor(item, override, prop);
|
|
1416
|
+
if (desc.get)
|
|
1417
|
+
continue;
|
|
1418
|
+
v = override && prop in override ? override[prop] : item[prop];
|
|
1419
|
+
if ((unwrapped = snapshot(v, map, lookup)) !== item[prop] || result) {
|
|
1420
|
+
if (!result) {
|
|
1421
|
+
result = Object.create(Object.getPrototypeOf(item));
|
|
1422
|
+
Object.assign(result, item);
|
|
1423
|
+
}
|
|
1424
|
+
result[prop] = unwrapped;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
return result || item;
|
|
1429
|
+
}
|
|
1503
1430
|
function trueFn() {
|
|
1504
1431
|
return true;
|
|
1505
1432
|
}
|
|
@@ -1651,72 +1578,73 @@ function omit(props, ...keys) {
|
|
|
1651
1578
|
function mapArray(list, map, options) {
|
|
1652
1579
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1653
1580
|
return updateKeyedMap.bind({
|
|
1654
|
-
|
|
1581
|
+
G: new Owner(),
|
|
1655
1582
|
i: 0,
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1583
|
+
$: list,
|
|
1584
|
+
u: [],
|
|
1585
|
+
C: map,
|
|
1586
|
+
e: [],
|
|
1660
1587
|
b: [],
|
|
1661
|
-
|
|
1588
|
+
D: keyFn,
|
|
1662
1589
|
j: keyFn || options?.keyed === false ? [] : void 0,
|
|
1663
1590
|
k: map.length > 1 ? [] : void 0,
|
|
1664
|
-
|
|
1591
|
+
H: options?.fallback
|
|
1665
1592
|
});
|
|
1666
1593
|
}
|
|
1594
|
+
var pureOptions = { pureWrite: true };
|
|
1667
1595
|
function updateKeyedMap() {
|
|
1668
|
-
const newItems = this
|
|
1596
|
+
const newItems = this.$() || [], newLen = newItems.length;
|
|
1669
1597
|
newItems[$TRACK];
|
|
1670
|
-
runWithOwner(this.
|
|
1598
|
+
runWithOwner(this.G, () => {
|
|
1671
1599
|
let i, j, mapper = this.j ? () => {
|
|
1672
|
-
this.j[j] = new Computation(newItems[j], null);
|
|
1673
|
-
this.k && (this.k[j] = new Computation(j, null));
|
|
1674
|
-
return this.
|
|
1600
|
+
this.j[j] = new Computation(newItems[j], null, pureOptions);
|
|
1601
|
+
this.k && (this.k[j] = new Computation(j, null, pureOptions));
|
|
1602
|
+
return this.C(
|
|
1675
1603
|
Computation.prototype.read.bind(this.j[j]),
|
|
1676
1604
|
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1677
1605
|
);
|
|
1678
1606
|
} : this.k ? () => {
|
|
1679
1607
|
const item = newItems[j];
|
|
1680
|
-
this.k[j] = new Computation(j, null);
|
|
1681
|
-
return this.
|
|
1608
|
+
this.k[j] = new Computation(j, null, pureOptions);
|
|
1609
|
+
return this.C(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1682
1610
|
} : () => {
|
|
1683
1611
|
const item = newItems[j];
|
|
1684
|
-
return this.
|
|
1612
|
+
return this.C(() => item);
|
|
1685
1613
|
};
|
|
1686
1614
|
if (newLen === 0) {
|
|
1687
1615
|
if (this.i !== 0) {
|
|
1688
|
-
this.
|
|
1616
|
+
this.G.dispose(false);
|
|
1689
1617
|
this.b = [];
|
|
1690
|
-
this.
|
|
1691
|
-
this.
|
|
1618
|
+
this.u = [];
|
|
1619
|
+
this.e = [];
|
|
1692
1620
|
this.i = 0;
|
|
1693
1621
|
this.j && (this.j = []);
|
|
1694
1622
|
this.k && (this.k = []);
|
|
1695
1623
|
}
|
|
1696
|
-
if (this.
|
|
1697
|
-
this.
|
|
1624
|
+
if (this.H && !this.e[0]) {
|
|
1625
|
+
this.e[0] = compute(
|
|
1698
1626
|
this.b[0] = new Owner(),
|
|
1699
|
-
this.
|
|
1627
|
+
this.H,
|
|
1700
1628
|
null
|
|
1701
1629
|
);
|
|
1702
1630
|
}
|
|
1703
1631
|
} else if (this.i === 0) {
|
|
1704
1632
|
if (this.b[0])
|
|
1705
1633
|
this.b[0].dispose();
|
|
1706
|
-
this.
|
|
1634
|
+
this.e = new Array(newLen);
|
|
1707
1635
|
for (j = 0; j < newLen; j++) {
|
|
1708
|
-
this.
|
|
1709
|
-
this.
|
|
1636
|
+
this.u[j] = newItems[j];
|
|
1637
|
+
this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
|
|
1710
1638
|
}
|
|
1711
1639
|
this.i = newLen;
|
|
1712
1640
|
} else {
|
|
1713
1641
|
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.j ? new Array(newLen) : void 0, tempIndexes = this.k ? new Array(newLen) : void 0;
|
|
1714
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1642
|
+
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.u[start] === newItems[start] || this.j && compare(this.D, this.u[start], newItems[start])); start++) {
|
|
1715
1643
|
if (this.j)
|
|
1716
1644
|
this.j[start].write(newItems[start]);
|
|
1717
1645
|
}
|
|
1718
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1719
|
-
temp[newEnd] = this.
|
|
1646
|
+
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.u[end] === newItems[newEnd] || this.j && compare(this.D, this.u[end], newItems[newEnd])); end--, newEnd--) {
|
|
1647
|
+
temp[newEnd] = this.e[end];
|
|
1720
1648
|
tempNodes[newEnd] = this.b[end];
|
|
1721
1649
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1722
1650
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
@@ -1725,17 +1653,17 @@ function updateKeyedMap() {
|
|
|
1725
1653
|
newIndicesNext = new Array(newEnd + 1);
|
|
1726
1654
|
for (j = newEnd; j >= start; j--) {
|
|
1727
1655
|
item = newItems[j];
|
|
1728
|
-
key = this.
|
|
1656
|
+
key = this.D ? this.D(item) : item;
|
|
1729
1657
|
i = newIndices.get(key);
|
|
1730
1658
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1731
1659
|
newIndices.set(key, j);
|
|
1732
1660
|
}
|
|
1733
1661
|
for (i = start; i <= end; i++) {
|
|
1734
|
-
item = this.
|
|
1735
|
-
key = this.
|
|
1662
|
+
item = this.u[i];
|
|
1663
|
+
key = this.D ? this.D(item) : item;
|
|
1736
1664
|
j = newIndices.get(key);
|
|
1737
1665
|
if (j !== void 0 && j !== -1) {
|
|
1738
|
-
temp[j] = this.
|
|
1666
|
+
temp[j] = this.e[i];
|
|
1739
1667
|
tempNodes[j] = this.b[i];
|
|
1740
1668
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1741
1669
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
@@ -1746,7 +1674,7 @@ function updateKeyedMap() {
|
|
|
1746
1674
|
}
|
|
1747
1675
|
for (j = start; j < newLen; j++) {
|
|
1748
1676
|
if (j in temp) {
|
|
1749
|
-
this.
|
|
1677
|
+
this.e[j] = temp[j];
|
|
1750
1678
|
this.b[j] = tempNodes[j];
|
|
1751
1679
|
if (tempRows) {
|
|
1752
1680
|
this.j[j] = tempRows[j];
|
|
@@ -1757,43 +1685,43 @@ function updateKeyedMap() {
|
|
|
1757
1685
|
this.k[j].write(j);
|
|
1758
1686
|
}
|
|
1759
1687
|
} else {
|
|
1760
|
-
this.
|
|
1688
|
+
this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
|
|
1761
1689
|
}
|
|
1762
1690
|
}
|
|
1763
|
-
this.
|
|
1764
|
-
this.
|
|
1691
|
+
this.e = this.e.slice(0, this.i = newLen);
|
|
1692
|
+
this.u = newItems.slice(0);
|
|
1765
1693
|
}
|
|
1766
1694
|
});
|
|
1767
|
-
return this.
|
|
1695
|
+
return this.e;
|
|
1768
1696
|
}
|
|
1769
1697
|
function repeat(count, map, options) {
|
|
1770
1698
|
return updateRepeat.bind({
|
|
1771
|
-
|
|
1699
|
+
G: new Owner(),
|
|
1772
1700
|
i: 0,
|
|
1773
1701
|
q: 0,
|
|
1774
|
-
|
|
1775
|
-
|
|
1702
|
+
aa: count,
|
|
1703
|
+
C: map,
|
|
1776
1704
|
b: [],
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1705
|
+
e: [],
|
|
1706
|
+
ba: options?.from,
|
|
1707
|
+
H: options?.fallback
|
|
1780
1708
|
});
|
|
1781
1709
|
}
|
|
1782
1710
|
function updateRepeat() {
|
|
1783
|
-
const newLen = this
|
|
1784
|
-
const from = this.
|
|
1785
|
-
runWithOwner(this.
|
|
1711
|
+
const newLen = this.aa();
|
|
1712
|
+
const from = this.ba?.() || 0;
|
|
1713
|
+
runWithOwner(this.G, () => {
|
|
1786
1714
|
if (newLen === 0) {
|
|
1787
1715
|
if (this.i !== 0) {
|
|
1788
|
-
this.
|
|
1716
|
+
this.G.dispose(false);
|
|
1789
1717
|
this.b = [];
|
|
1790
|
-
this.
|
|
1718
|
+
this.e = [];
|
|
1791
1719
|
this.i = 0;
|
|
1792
1720
|
}
|
|
1793
|
-
if (this.
|
|
1794
|
-
this.
|
|
1721
|
+
if (this.H && !this.e[0]) {
|
|
1722
|
+
this.e[0] = compute(
|
|
1795
1723
|
this.b[0] = new Owner(),
|
|
1796
|
-
this.
|
|
1724
|
+
this.H,
|
|
1797
1725
|
null
|
|
1798
1726
|
);
|
|
1799
1727
|
}
|
|
@@ -1810,39 +1738,233 @@ function updateRepeat() {
|
|
|
1810
1738
|
while (i < from && i < this.i)
|
|
1811
1739
|
this.b[i++].dispose();
|
|
1812
1740
|
this.b.splice(0, from - this.q);
|
|
1813
|
-
this.
|
|
1741
|
+
this.e.splice(0, from - this.q);
|
|
1814
1742
|
} else if (this.q > from) {
|
|
1815
1743
|
let i = prevTo - this.q - 1;
|
|
1816
1744
|
let difference = this.q - from;
|
|
1817
|
-
this.b.length = this.
|
|
1745
|
+
this.b.length = this.e.length = newLen;
|
|
1818
1746
|
while (i >= difference) {
|
|
1819
1747
|
this.b[i] = this.b[i - difference];
|
|
1820
|
-
this.
|
|
1748
|
+
this.e[i] = this.e[i - difference];
|
|
1821
1749
|
i--;
|
|
1822
1750
|
}
|
|
1823
1751
|
for (let i2 = 0; i2 < difference; i2++) {
|
|
1824
|
-
this.
|
|
1752
|
+
this.e[i2] = compute(
|
|
1825
1753
|
this.b[i2] = new Owner(),
|
|
1826
|
-
() => this.
|
|
1754
|
+
() => this.C(i2 + from),
|
|
1827
1755
|
null
|
|
1828
1756
|
);
|
|
1829
1757
|
}
|
|
1830
1758
|
}
|
|
1831
1759
|
for (let i = prevTo; i < to; i++) {
|
|
1832
|
-
this.
|
|
1760
|
+
this.e[i - from] = compute(
|
|
1833
1761
|
this.b[i - from] = new Owner(),
|
|
1834
|
-
() => this.
|
|
1762
|
+
() => this.C(i),
|
|
1835
1763
|
null
|
|
1836
1764
|
);
|
|
1837
1765
|
}
|
|
1838
|
-
this.
|
|
1766
|
+
this.e = this.e.slice(0, newLen);
|
|
1839
1767
|
this.q = from;
|
|
1840
1768
|
this.i = newLen;
|
|
1841
1769
|
});
|
|
1842
|
-
return this.
|
|
1770
|
+
return this.e;
|
|
1843
1771
|
}
|
|
1844
1772
|
function compare(key, a, b) {
|
|
1845
1773
|
return key ? key(a) === key(b) : true;
|
|
1846
1774
|
}
|
|
1847
1775
|
|
|
1848
|
-
|
|
1776
|
+
// src/boundaries.ts
|
|
1777
|
+
var BoundaryComputation = class extends EagerComputation {
|
|
1778
|
+
I;
|
|
1779
|
+
constructor(compute2, propagationMask) {
|
|
1780
|
+
super(void 0, compute2, { defer: true });
|
|
1781
|
+
this.I = propagationMask;
|
|
1782
|
+
}
|
|
1783
|
+
write(value, flags) {
|
|
1784
|
+
super.write(value, flags & ~this.I);
|
|
1785
|
+
if (this.I & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
|
|
1786
|
+
flags &= ~LOADING_BIT;
|
|
1787
|
+
}
|
|
1788
|
+
this.h.notify(this, this.I, flags);
|
|
1789
|
+
return this.g;
|
|
1790
|
+
}
|
|
1791
|
+
};
|
|
1792
|
+
function createBoundChildren(owner, fn, queue, mask) {
|
|
1793
|
+
const parentQueue = owner.h;
|
|
1794
|
+
parentQueue.addChild(owner.h = queue);
|
|
1795
|
+
onCleanup(() => parentQueue.removeChild(owner.h));
|
|
1796
|
+
return compute(
|
|
1797
|
+
owner,
|
|
1798
|
+
() => {
|
|
1799
|
+
const c = new Computation(void 0, fn);
|
|
1800
|
+
return new BoundaryComputation(() => flatten(c.wait()), mask);
|
|
1801
|
+
},
|
|
1802
|
+
null
|
|
1803
|
+
);
|
|
1804
|
+
}
|
|
1805
|
+
var ConditionalQueue = class extends Queue {
|
|
1806
|
+
n;
|
|
1807
|
+
O = /* @__PURE__ */ new Set();
|
|
1808
|
+
P = /* @__PURE__ */ new Set();
|
|
1809
|
+
constructor(disabled) {
|
|
1810
|
+
super();
|
|
1811
|
+
this.n = disabled;
|
|
1812
|
+
}
|
|
1813
|
+
run(type) {
|
|
1814
|
+
if (!type || this.n.read())
|
|
1815
|
+
return;
|
|
1816
|
+
return super.run(type);
|
|
1817
|
+
}
|
|
1818
|
+
notify(node, type, flags) {
|
|
1819
|
+
if (this.n.read()) {
|
|
1820
|
+
if (type & LOADING_BIT) {
|
|
1821
|
+
if (flags & LOADING_BIT) {
|
|
1822
|
+
this.P.add(node);
|
|
1823
|
+
type &= ~LOADING_BIT;
|
|
1824
|
+
} else if (this.P.delete(node))
|
|
1825
|
+
type &= ~LOADING_BIT;
|
|
1826
|
+
}
|
|
1827
|
+
if (type & ERROR_BIT) {
|
|
1828
|
+
if (flags & ERROR_BIT) {
|
|
1829
|
+
this.O.add(node);
|
|
1830
|
+
type &= ~ERROR_BIT;
|
|
1831
|
+
} else if (this.O.delete(node))
|
|
1832
|
+
type &= ~ERROR_BIT;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
return type ? super.notify(node, type, flags) : true;
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
var CollectionQueue = class extends Queue {
|
|
1839
|
+
Q;
|
|
1840
|
+
b = /* @__PURE__ */ new Set();
|
|
1841
|
+
n = new Computation(false, null, { pureWrite: true });
|
|
1842
|
+
constructor(type) {
|
|
1843
|
+
super();
|
|
1844
|
+
this.Q = type;
|
|
1845
|
+
}
|
|
1846
|
+
run(type) {
|
|
1847
|
+
if (!type || this.n.read())
|
|
1848
|
+
return;
|
|
1849
|
+
return super.run(type);
|
|
1850
|
+
}
|
|
1851
|
+
notify(node, type, flags) {
|
|
1852
|
+
if (!(type & this.Q))
|
|
1853
|
+
return super.notify(node, type, flags);
|
|
1854
|
+
if (flags & this.Q) {
|
|
1855
|
+
this.b.add(node);
|
|
1856
|
+
if (this.b.size === 1)
|
|
1857
|
+
this.n.write(true);
|
|
1858
|
+
} else {
|
|
1859
|
+
this.b.delete(node);
|
|
1860
|
+
if (this.b.size === 0)
|
|
1861
|
+
this.n.write(false);
|
|
1862
|
+
}
|
|
1863
|
+
type &= ~this.Q;
|
|
1864
|
+
return type ? super.notify(node, type, flags) : true;
|
|
1865
|
+
}
|
|
1866
|
+
};
|
|
1867
|
+
function createBoundary(fn, condition) {
|
|
1868
|
+
const owner = new Owner();
|
|
1869
|
+
const queue = new ConditionalQueue(
|
|
1870
|
+
new Computation(void 0, () => condition() === "hidden" /* HIDDEN */)
|
|
1871
|
+
);
|
|
1872
|
+
const tree = createBoundChildren(owner, fn, queue, 0);
|
|
1873
|
+
new EagerComputation(void 0, () => {
|
|
1874
|
+
const disabled = queue.n.read();
|
|
1875
|
+
tree.I = disabled ? ERROR_BIT | LOADING_BIT : 0;
|
|
1876
|
+
if (!disabled) {
|
|
1877
|
+
queue.P.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
|
|
1878
|
+
queue.O.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
|
|
1879
|
+
queue.P.clear();
|
|
1880
|
+
queue.O.clear();
|
|
1881
|
+
}
|
|
1882
|
+
});
|
|
1883
|
+
return () => queue.n.read() ? void 0 : tree.read();
|
|
1884
|
+
}
|
|
1885
|
+
function createCollectionBoundary(type, fn, fallback) {
|
|
1886
|
+
const owner = new Owner();
|
|
1887
|
+
const queue = new CollectionQueue(type);
|
|
1888
|
+
const tree = createBoundChildren(owner, fn, queue, type);
|
|
1889
|
+
const decision = new Computation(void 0, () => {
|
|
1890
|
+
if (!queue.n.read()) {
|
|
1891
|
+
const resolved = tree.read();
|
|
1892
|
+
if (!queue.n.read())
|
|
1893
|
+
return resolved;
|
|
1894
|
+
}
|
|
1895
|
+
return fallback(queue);
|
|
1896
|
+
});
|
|
1897
|
+
return decision.read.bind(decision);
|
|
1898
|
+
}
|
|
1899
|
+
function createSuspense(fn, fallback) {
|
|
1900
|
+
return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
|
|
1901
|
+
}
|
|
1902
|
+
function createErrorBoundary(fn, fallback) {
|
|
1903
|
+
return createCollectionBoundary(
|
|
1904
|
+
ERROR_BIT,
|
|
1905
|
+
fn,
|
|
1906
|
+
(queue) => fallback(queue.b.values().next().value.F, () => {
|
|
1907
|
+
incrementClock();
|
|
1908
|
+
for (let node of queue.b) {
|
|
1909
|
+
node.a = STATE_DIRTY;
|
|
1910
|
+
node.h?.enqueue(node.s, node);
|
|
1911
|
+
}
|
|
1912
|
+
})
|
|
1913
|
+
);
|
|
1914
|
+
}
|
|
1915
|
+
function flatten(children, options) {
|
|
1916
|
+
if (typeof children === "function" && !children.length) {
|
|
1917
|
+
if (options?.doNotUnwrap)
|
|
1918
|
+
return children;
|
|
1919
|
+
do {
|
|
1920
|
+
children = children();
|
|
1921
|
+
} while (typeof children === "function" && !children.length);
|
|
1922
|
+
}
|
|
1923
|
+
if (options?.skipNonRendered && (children == null || children === true || children === false || children === ""))
|
|
1924
|
+
return;
|
|
1925
|
+
if (Array.isArray(children)) {
|
|
1926
|
+
let results = [];
|
|
1927
|
+
if (flattenArray(children, results, options)) {
|
|
1928
|
+
return () => {
|
|
1929
|
+
let nested = [];
|
|
1930
|
+
flattenArray(results, nested, { ...options, doNotUnwrap: false });
|
|
1931
|
+
return nested;
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
return results;
|
|
1935
|
+
}
|
|
1936
|
+
return children;
|
|
1937
|
+
}
|
|
1938
|
+
function flattenArray(children, results = [], options) {
|
|
1939
|
+
let notReady = null;
|
|
1940
|
+
let needsUnwrap = false;
|
|
1941
|
+
for (let i = 0; i < children.length; i++) {
|
|
1942
|
+
try {
|
|
1943
|
+
let child = children[i];
|
|
1944
|
+
if (typeof child === "function" && !child.length) {
|
|
1945
|
+
if (options?.doNotUnwrap) {
|
|
1946
|
+
results.push(child);
|
|
1947
|
+
needsUnwrap = true;
|
|
1948
|
+
continue;
|
|
1949
|
+
}
|
|
1950
|
+
do {
|
|
1951
|
+
child = child();
|
|
1952
|
+
} while (typeof child === "function" && !child.length);
|
|
1953
|
+
}
|
|
1954
|
+
if (Array.isArray(child)) {
|
|
1955
|
+
needsUnwrap = flattenArray(child, results, options);
|
|
1956
|
+
} else if (options?.skipNonRendered && (child == null || child === true || child === false || child === "")) {
|
|
1957
|
+
} else
|
|
1958
|
+
results.push(child);
|
|
1959
|
+
} catch (e) {
|
|
1960
|
+
if (!(e instanceof NotReadyError))
|
|
1961
|
+
throw e;
|
|
1962
|
+
notReady = e;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
if (notReady)
|
|
1966
|
+
throw notReady;
|
|
1967
|
+
return needsUnwrap;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
export { $PROXY, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createOptimistic, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, deep, flatten, flush, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, snapshot, transition, tryCatch, untrack };
|