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