@solidjs/signals 0.4.3 → 0.4.5
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 +194 -84
- package/dist/node.cjs +655 -545
- package/dist/prod.js +655 -545
- package/dist/types/boundaries.d.ts +2 -1
- package/dist/types/core/core.d.ts +3 -2
- package/dist/types/core/scheduler.d.ts +9 -3
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -39,36 +39,36 @@ function incrementClock() {
|
|
|
39
39
|
clock++;
|
|
40
40
|
}
|
|
41
41
|
var ActiveTransition = null;
|
|
42
|
-
var
|
|
42
|
+
var Unobserved = [];
|
|
43
43
|
var scheduled = false;
|
|
44
44
|
function schedule() {
|
|
45
45
|
if (scheduled)
|
|
46
46
|
return;
|
|
47
47
|
scheduled = true;
|
|
48
|
-
if (!globalQueue.
|
|
48
|
+
if (!globalQueue.z)
|
|
49
49
|
queueMicrotask(flush);
|
|
50
50
|
}
|
|
51
51
|
function notifyUnobserved() {
|
|
52
|
-
for (let i = 0; i <
|
|
53
|
-
const source =
|
|
54
|
-
if (!source.
|
|
55
|
-
|
|
52
|
+
for (let i = 0; i < Unobserved.length; i++) {
|
|
53
|
+
const source = Unobserved[i];
|
|
54
|
+
if (!source.b || !source.b.length)
|
|
55
|
+
Unobserved[i].da?.();
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
Unobserved = [];
|
|
58
58
|
}
|
|
59
59
|
var pureQueue = [];
|
|
60
60
|
var Queue = class {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
m = null;
|
|
62
|
+
z = false;
|
|
63
|
+
f = [[], []];
|
|
64
|
+
e = [];
|
|
65
65
|
created = clock;
|
|
66
66
|
enqueue(type, fn) {
|
|
67
|
-
if (ActiveTransition)
|
|
68
|
-
return ActiveTransition.enqueue(type, fn);
|
|
67
|
+
if (ActiveTransition && ActiveTransition.u.has(this))
|
|
68
|
+
return ActiveTransition.u.get(this).enqueue(type, fn);
|
|
69
69
|
pureQueue.push(fn);
|
|
70
70
|
if (type)
|
|
71
|
-
this.
|
|
71
|
+
this.f[type - 1].push(fn);
|
|
72
72
|
schedule();
|
|
73
73
|
}
|
|
74
74
|
run(type) {
|
|
@@ -76,19 +76,19 @@ var Queue = class {
|
|
|
76
76
|
pureQueue.length && runQueue(pureQueue, type);
|
|
77
77
|
pureQueue = [];
|
|
78
78
|
return;
|
|
79
|
-
} else if (this.
|
|
80
|
-
const effects = this.
|
|
81
|
-
this.
|
|
79
|
+
} else if (this.f[type - 1].length) {
|
|
80
|
+
const effects = this.f[type - 1];
|
|
81
|
+
this.f[type - 1] = [];
|
|
82
82
|
runQueue(effects, type);
|
|
83
83
|
}
|
|
84
|
-
for (let i = 0; i < this.
|
|
85
|
-
this.
|
|
84
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
85
|
+
this.e[i].run(type);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
flush() {
|
|
89
|
-
if (this.
|
|
89
|
+
if (this.z)
|
|
90
90
|
return;
|
|
91
|
-
this.
|
|
91
|
+
this.z = true;
|
|
92
92
|
try {
|
|
93
93
|
this.run(EFFECT_PURE);
|
|
94
94
|
incrementClock();
|
|
@@ -96,24 +96,37 @@ var Queue = class {
|
|
|
96
96
|
this.run(EFFECT_RENDER);
|
|
97
97
|
this.run(EFFECT_USER);
|
|
98
98
|
} finally {
|
|
99
|
-
this.
|
|
100
|
-
|
|
99
|
+
this.z = false;
|
|
100
|
+
Unobserved.length && notifyUnobserved();
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
addChild(child) {
|
|
104
|
-
this.
|
|
105
|
-
child.
|
|
104
|
+
this.e.push(child);
|
|
105
|
+
child.m = this;
|
|
106
106
|
}
|
|
107
107
|
removeChild(child) {
|
|
108
|
-
const index = this.
|
|
108
|
+
const index = this.e.indexOf(child);
|
|
109
109
|
if (index >= 0)
|
|
110
|
-
this.
|
|
110
|
+
this.e.splice(index, 1);
|
|
111
111
|
}
|
|
112
112
|
notify(...args) {
|
|
113
|
-
if (this
|
|
114
|
-
return this.
|
|
113
|
+
if (ActiveTransition && ActiveTransition.u.has(this))
|
|
114
|
+
return ActiveTransition.u.get(this).notify(...args);
|
|
115
|
+
if (this.m)
|
|
116
|
+
return this.m.notify(...args);
|
|
115
117
|
return false;
|
|
116
118
|
}
|
|
119
|
+
merge(queue) {
|
|
120
|
+
this.f[0].push.apply(this.f[0], queue.f[0]);
|
|
121
|
+
this.f[1].push.apply(this.f[1], queue.f[1]);
|
|
122
|
+
for (let i = 0; i < queue.e.length; i++) {
|
|
123
|
+
const og = this.e.find((c) => c.g === queue.e[i].g);
|
|
124
|
+
if (og)
|
|
125
|
+
og.merge(queue.e[i]);
|
|
126
|
+
else
|
|
127
|
+
this.addChild(queue.e[i]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
117
130
|
};
|
|
118
131
|
var globalQueue = new Queue();
|
|
119
132
|
function flush() {
|
|
@@ -127,84 +140,103 @@ function runQueue(queue, type) {
|
|
|
127
140
|
}
|
|
128
141
|
var Transition = class _Transition {
|
|
129
142
|
a = /* @__PURE__ */ new Map();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
143
|
+
s = /* @__PURE__ */ new Set();
|
|
144
|
+
R = /* @__PURE__ */ new Set();
|
|
145
|
+
W = /* @__PURE__ */ new Set();
|
|
146
|
+
I = false;
|
|
147
|
+
f = [[], []];
|
|
148
|
+
u = /* @__PURE__ */ new Map();
|
|
149
|
+
E = [];
|
|
150
|
+
e = [];
|
|
151
|
+
m = null;
|
|
152
|
+
z = false;
|
|
153
|
+
X = false;
|
|
140
154
|
created = clock;
|
|
155
|
+
constructor() {
|
|
156
|
+
this.u.set(globalQueue, this);
|
|
157
|
+
for (const child of globalQueue.e) {
|
|
158
|
+
cloneQueue(child, this, this.u);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
141
161
|
enqueue(type, fn) {
|
|
142
|
-
this.
|
|
162
|
+
this.E.push(fn);
|
|
143
163
|
if (type)
|
|
144
|
-
this.
|
|
164
|
+
this.f[type - 1].push(fn);
|
|
145
165
|
this.schedule();
|
|
146
166
|
}
|
|
147
167
|
run(type) {
|
|
148
168
|
if (type === EFFECT_PURE) {
|
|
149
|
-
this.
|
|
150
|
-
this.
|
|
169
|
+
this.E.length && runQueue(this.E, type);
|
|
170
|
+
this.E = [];
|
|
151
171
|
return;
|
|
152
|
-
} else if (this.
|
|
153
|
-
const effects = this.
|
|
154
|
-
this.
|
|
172
|
+
} else if (this.f[type - 1].length) {
|
|
173
|
+
const effects = this.f[type - 1];
|
|
174
|
+
this.f[type - 1] = [];
|
|
155
175
|
runQueue(effects, type);
|
|
156
176
|
}
|
|
157
|
-
for (let i = 0; i < this.
|
|
158
|
-
this.
|
|
177
|
+
for (let i = 0; i < this.e.length; i++) {
|
|
178
|
+
this.e[i].run(type);
|
|
159
179
|
}
|
|
160
180
|
}
|
|
161
181
|
flush() {
|
|
162
|
-
if (this.
|
|
182
|
+
if (this.z)
|
|
163
183
|
return;
|
|
164
|
-
this.
|
|
184
|
+
this.z = true;
|
|
165
185
|
let currentTransition = ActiveTransition;
|
|
166
186
|
ActiveTransition = this;
|
|
167
187
|
try {
|
|
168
188
|
this.run(EFFECT_PURE);
|
|
169
189
|
incrementClock();
|
|
170
|
-
this.
|
|
190
|
+
this.X = false;
|
|
171
191
|
ActiveTransition = currentTransition;
|
|
172
192
|
finishTransition(this);
|
|
173
193
|
} finally {
|
|
174
|
-
this.
|
|
194
|
+
this.z = false;
|
|
175
195
|
ActiveTransition = currentTransition;
|
|
176
196
|
}
|
|
177
197
|
}
|
|
178
198
|
addChild(child) {
|
|
179
|
-
this.
|
|
180
|
-
child.
|
|
199
|
+
this.e.push(child);
|
|
200
|
+
child.m = this;
|
|
181
201
|
}
|
|
182
202
|
removeChild(child) {
|
|
183
|
-
const index = this.
|
|
203
|
+
const index = this.e.indexOf(child);
|
|
184
204
|
if (index >= 0)
|
|
185
|
-
this.
|
|
205
|
+
this.e.splice(index, 1);
|
|
186
206
|
}
|
|
187
207
|
notify(node, type, flags) {
|
|
188
208
|
if (!(type & LOADING_BIT))
|
|
189
209
|
return false;
|
|
190
210
|
if (flags & LOADING_BIT) {
|
|
191
|
-
this.
|
|
211
|
+
this.s.add(node);
|
|
192
212
|
} else {
|
|
193
|
-
this.
|
|
213
|
+
this.s.delete(node);
|
|
194
214
|
}
|
|
195
215
|
return true;
|
|
196
216
|
}
|
|
217
|
+
merge(queue) {
|
|
218
|
+
this.f[0].push.apply(this.f[0], queue.f[0]);
|
|
219
|
+
this.f[1].push.apply(this.f[1], queue.f[1]);
|
|
220
|
+
this.E.push.apply(this.E, queue.E);
|
|
221
|
+
for (let i = 0; i < queue.e.length; i++) {
|
|
222
|
+
const og = this.e.find((c) => c.g === queue.e[i].g);
|
|
223
|
+
if (og)
|
|
224
|
+
og.merge(queue.e[i]);
|
|
225
|
+
else
|
|
226
|
+
this.addChild(queue.e[i]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
197
229
|
schedule() {
|
|
198
|
-
if (this.
|
|
230
|
+
if (this.X)
|
|
199
231
|
return;
|
|
200
|
-
this.
|
|
201
|
-
if (!this.
|
|
232
|
+
this.X = true;
|
|
233
|
+
if (!this.z)
|
|
202
234
|
queueMicrotask(() => this.flush());
|
|
203
235
|
}
|
|
204
236
|
runTransition(fn, force = false) {
|
|
205
|
-
if (this.
|
|
206
|
-
if (this.
|
|
207
|
-
return this.
|
|
237
|
+
if (this.I) {
|
|
238
|
+
if (this.I instanceof _Transition)
|
|
239
|
+
return this.I.runTransition(fn, force);
|
|
208
240
|
if (!force)
|
|
209
241
|
throw new Error("Transition already completed");
|
|
210
242
|
fn();
|
|
@@ -215,9 +247,9 @@ var Transition = class _Transition {
|
|
|
215
247
|
const result = fn();
|
|
216
248
|
const transition2 = ActiveTransition;
|
|
217
249
|
if (result instanceof Promise) {
|
|
218
|
-
transition2.
|
|
250
|
+
transition2.R.add(result);
|
|
219
251
|
result.finally(() => {
|
|
220
|
-
transition2.
|
|
252
|
+
transition2.R.delete(result);
|
|
221
253
|
finishTransition(transition2);
|
|
222
254
|
});
|
|
223
255
|
}
|
|
@@ -228,96 +260,142 @@ var Transition = class _Transition {
|
|
|
228
260
|
}
|
|
229
261
|
}
|
|
230
262
|
addOptimistic(fn) {
|
|
231
|
-
if (fn.
|
|
232
|
-
mergeTransitions(fn.
|
|
233
|
-
ActiveTransition = fn.
|
|
263
|
+
if (fn.k && fn.k !== this) {
|
|
264
|
+
mergeTransitions(fn.k, this);
|
|
265
|
+
ActiveTransition = fn.k;
|
|
234
266
|
return;
|
|
235
267
|
}
|
|
236
|
-
fn.
|
|
237
|
-
this.
|
|
268
|
+
fn.k = this;
|
|
269
|
+
this.W.add(fn);
|
|
238
270
|
}
|
|
239
271
|
};
|
|
240
|
-
var Transitions = /* @__PURE__ */ new Set();
|
|
241
272
|
function transition(fn) {
|
|
242
273
|
let t = new Transition();
|
|
243
|
-
Transitions.add(t);
|
|
244
274
|
queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
|
|
245
275
|
}
|
|
246
276
|
function cloneGraph(node) {
|
|
247
|
-
if (node.
|
|
248
|
-
if (node.
|
|
249
|
-
mergeTransitions(node.
|
|
250
|
-
ActiveTransition = node.
|
|
277
|
+
if (node.k) {
|
|
278
|
+
if (node.k !== ActiveTransition) {
|
|
279
|
+
mergeTransitions(node.k, ActiveTransition);
|
|
280
|
+
ActiveTransition = node.k;
|
|
251
281
|
}
|
|
252
|
-
return node.
|
|
282
|
+
return node.k.a.get(node);
|
|
253
283
|
}
|
|
254
284
|
const clone = Object.create(Object.getPrototypeOf(node));
|
|
255
|
-
Object.assign(clone, node, {
|
|
285
|
+
Object.assign(clone, node, {
|
|
286
|
+
n: null,
|
|
287
|
+
r: null,
|
|
288
|
+
b: null,
|
|
289
|
+
a: node.a ? [...node.a] : null,
|
|
290
|
+
g: node
|
|
291
|
+
});
|
|
256
292
|
ActiveTransition.a.set(node, clone);
|
|
257
|
-
node.
|
|
258
|
-
if (node.
|
|
259
|
-
for (let i = 0
|
|
260
|
-
|
|
261
|
-
|
|
293
|
+
node.k = ActiveTransition;
|
|
294
|
+
if (node.a) {
|
|
295
|
+
for (let i = 0; i < node.a.length; i++)
|
|
296
|
+
node.a[i].b.push(clone);
|
|
297
|
+
}
|
|
298
|
+
if (node.b) {
|
|
299
|
+
clone.b = [];
|
|
300
|
+
for (let i = 0, length = node.b.length; i < length; i++) {
|
|
301
|
+
!node.b[i].g && clone.b.push(cloneGraph(node.b[i]));
|
|
262
302
|
}
|
|
263
303
|
}
|
|
264
304
|
return clone;
|
|
265
305
|
}
|
|
266
|
-
function
|
|
306
|
+
function replaceSourceObservers(node, transition2) {
|
|
267
307
|
let source;
|
|
308
|
+
let transitionSource;
|
|
268
309
|
let swap;
|
|
269
|
-
for (let i =
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
310
|
+
for (let i = 0; i < node.a.length; i++) {
|
|
311
|
+
transitionSource = transition2.a.get(node.a[i]);
|
|
312
|
+
source = transitionSource || node.a[i];
|
|
313
|
+
if (source.b && (swap = source.b.indexOf(node)) !== -1) {
|
|
314
|
+
source.b[swap] = transitionSource ? node.g : source.b[source.b.length - 1];
|
|
315
|
+
!transitionSource && source.b.pop();
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function cloneQueue(queue, parent, clonedQueues) {
|
|
320
|
+
const clone = Object.create(Object.getPrototypeOf(queue));
|
|
321
|
+
Object.assign(clone, queue, {
|
|
322
|
+
g: queue,
|
|
323
|
+
m: parent,
|
|
324
|
+
e: [],
|
|
325
|
+
enqueue(type, fn) {
|
|
326
|
+
ActiveTransition?.enqueue(type, fn);
|
|
327
|
+
},
|
|
328
|
+
notify(node, type, flags) {
|
|
329
|
+
node = node.g || node;
|
|
330
|
+
if (!clone.F || type & LOADING_BIT) {
|
|
331
|
+
type &= ~LOADING_BIT;
|
|
332
|
+
ActiveTransition?.notify(node, LOADING_BIT, flags);
|
|
333
|
+
if (!type)
|
|
334
|
+
return true;
|
|
275
335
|
}
|
|
276
|
-
|
|
277
|
-
|
|
336
|
+
return queue.notify.call(this, node, type, flags);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
parent.e.push(clone);
|
|
340
|
+
clonedQueues.set(queue, clone);
|
|
341
|
+
for (const child of queue.e) {
|
|
342
|
+
cloneQueue(child, clone, clonedQueues);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function resolveQueues(children) {
|
|
346
|
+
for (const child of children) {
|
|
347
|
+
const og = child.g;
|
|
348
|
+
if (og) {
|
|
349
|
+
const clonedChildren = child.e;
|
|
350
|
+
delete child.enqueue;
|
|
351
|
+
delete child.notify;
|
|
352
|
+
delete child.m;
|
|
353
|
+
delete child.e;
|
|
354
|
+
Object.assign(og, child);
|
|
355
|
+
delete og.g;
|
|
356
|
+
resolveQueues(clonedChildren);
|
|
357
|
+
} else if (child.m.g) {
|
|
358
|
+
child.m.g.addChild(child);
|
|
278
359
|
}
|
|
279
360
|
}
|
|
280
361
|
}
|
|
281
362
|
function mergeTransitions(t1, t2) {
|
|
282
363
|
t2.a.forEach((value, key) => {
|
|
283
|
-
key.
|
|
364
|
+
key.k = t1;
|
|
284
365
|
t1.a.set(key, value);
|
|
285
366
|
});
|
|
286
|
-
t2.
|
|
287
|
-
c.
|
|
288
|
-
t1.
|
|
367
|
+
t2.W.forEach((c) => {
|
|
368
|
+
c.k = t1;
|
|
369
|
+
t1.W.add(c);
|
|
289
370
|
});
|
|
290
|
-
t2.
|
|
291
|
-
t2.
|
|
292
|
-
|
|
293
|
-
t2.
|
|
294
|
-
t2.F.forEach((f) => t1.F.push(f));
|
|
295
|
-
t2.q.forEach((c) => t1.addChild(c));
|
|
296
|
-
t2.E = t1;
|
|
297
|
-
Transitions.delete(t2);
|
|
371
|
+
t2.R.forEach((p) => t1.R.add(p));
|
|
372
|
+
t2.s.forEach((n) => t1.s.add(n));
|
|
373
|
+
t1.merge(t2);
|
|
374
|
+
t2.I = t1;
|
|
298
375
|
}
|
|
299
376
|
function finishTransition(transition2) {
|
|
300
|
-
if (transition2.
|
|
377
|
+
if (transition2.I || transition2.X || transition2.R.size || transition2.s.size)
|
|
301
378
|
return;
|
|
302
379
|
for (const [source, clone] of transition2.a) {
|
|
303
|
-
if (source === clone || source.
|
|
380
|
+
if (source === clone || source.k !== transition2)
|
|
304
381
|
continue;
|
|
305
382
|
if (clone.a)
|
|
306
|
-
|
|
383
|
+
replaceSourceObservers(clone, transition2);
|
|
307
384
|
source.dispose(false);
|
|
308
385
|
source.emptyDisposal();
|
|
309
386
|
Object.assign(source, clone);
|
|
310
|
-
delete source.
|
|
311
|
-
delete source.
|
|
312
|
-
}
|
|
313
|
-
transition2.
|
|
314
|
-
|
|
315
|
-
transition2.
|
|
316
|
-
transition2.
|
|
317
|
-
for (const reset of transition2.
|
|
318
|
-
delete reset.
|
|
387
|
+
delete source.g;
|
|
388
|
+
delete source.k;
|
|
389
|
+
}
|
|
390
|
+
globalQueue.f[0].push.apply(globalQueue.f[0], transition2.f[0]);
|
|
391
|
+
globalQueue.f[1].push.apply(globalQueue.f[1], transition2.f[1]);
|
|
392
|
+
resolveQueues(transition2.e);
|
|
393
|
+
transition2.I = true;
|
|
394
|
+
for (const reset of transition2.W) {
|
|
395
|
+
delete reset.k;
|
|
319
396
|
reset();
|
|
320
397
|
}
|
|
398
|
+
globalQueue.flush();
|
|
321
399
|
}
|
|
322
400
|
|
|
323
401
|
// src/core/owner.ts
|
|
@@ -335,14 +413,14 @@ var Owner = class {
|
|
|
335
413
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
336
414
|
// However, the children are actually added in reverse creation order
|
|
337
415
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
338
|
-
|
|
416
|
+
m = null;
|
|
339
417
|
r = null;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
418
|
+
B = null;
|
|
419
|
+
c = STATE_CLEAN;
|
|
420
|
+
n = null;
|
|
421
|
+
w = defaultContext;
|
|
422
|
+
l = globalQueue;
|
|
423
|
+
ea = 0;
|
|
346
424
|
id = null;
|
|
347
425
|
constructor(id = null, skipAppend = false) {
|
|
348
426
|
this.id = id;
|
|
@@ -351,64 +429,64 @@ var Owner = class {
|
|
|
351
429
|
}
|
|
352
430
|
}
|
|
353
431
|
append(child) {
|
|
354
|
-
child.
|
|
355
|
-
child.
|
|
432
|
+
child.m = this;
|
|
433
|
+
child.B = this;
|
|
356
434
|
if (this.r)
|
|
357
|
-
this.r.
|
|
435
|
+
this.r.B = child;
|
|
358
436
|
child.r = this.r;
|
|
359
437
|
this.r = child;
|
|
360
438
|
if (this.id != null && child.id == null)
|
|
361
439
|
child.id = this.getNextChildId();
|
|
362
|
-
if (child.
|
|
363
|
-
child.
|
|
440
|
+
if (child.w !== this.w) {
|
|
441
|
+
child.w = { ...this.w, ...child.w };
|
|
364
442
|
}
|
|
365
|
-
if (this.
|
|
366
|
-
child.
|
|
443
|
+
if (this.l)
|
|
444
|
+
child.l = this.l;
|
|
367
445
|
}
|
|
368
446
|
dispose(self = true) {
|
|
369
|
-
if (this.
|
|
447
|
+
if (this.c === STATE_DISPOSED)
|
|
370
448
|
return;
|
|
371
|
-
let head = self ? this.
|
|
372
|
-
while (current && current.
|
|
449
|
+
let head = self ? this.B || this.m : this, current = this.r, next = null;
|
|
450
|
+
while (current && current.m === this) {
|
|
373
451
|
current.dispose(true);
|
|
374
|
-
current.
|
|
452
|
+
current.J();
|
|
375
453
|
next = current.r;
|
|
376
454
|
current.r = null;
|
|
377
455
|
current = next;
|
|
378
456
|
}
|
|
379
|
-
this.
|
|
457
|
+
this.ea = 0;
|
|
380
458
|
if (self)
|
|
381
|
-
this.
|
|
459
|
+
this.J();
|
|
382
460
|
if (current)
|
|
383
|
-
current.
|
|
461
|
+
current.B = !self ? this : this.B;
|
|
384
462
|
if (head)
|
|
385
463
|
head.r = current;
|
|
386
464
|
}
|
|
387
|
-
|
|
388
|
-
if (this.
|
|
389
|
-
this.
|
|
390
|
-
this.
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
465
|
+
J() {
|
|
466
|
+
if (this.B)
|
|
467
|
+
this.B.r = null;
|
|
468
|
+
this.m = null;
|
|
469
|
+
this.B = null;
|
|
470
|
+
this.w = defaultContext;
|
|
471
|
+
this.c = STATE_DISPOSED;
|
|
394
472
|
this.emptyDisposal();
|
|
395
473
|
}
|
|
396
474
|
emptyDisposal() {
|
|
397
|
-
if (!this.
|
|
475
|
+
if (!this.n)
|
|
398
476
|
return;
|
|
399
|
-
if (Array.isArray(this.
|
|
400
|
-
for (let i = 0; i < this.
|
|
401
|
-
const callable = this.
|
|
477
|
+
if (Array.isArray(this.n)) {
|
|
478
|
+
for (let i = 0; i < this.n.length; i++) {
|
|
479
|
+
const callable = this.n[i];
|
|
402
480
|
callable.call(callable);
|
|
403
481
|
}
|
|
404
482
|
} else {
|
|
405
|
-
this.
|
|
483
|
+
this.n.call(this.n);
|
|
406
484
|
}
|
|
407
|
-
this.
|
|
485
|
+
this.n = null;
|
|
408
486
|
}
|
|
409
487
|
getNextChildId() {
|
|
410
488
|
if (this.id != null)
|
|
411
|
-
return formatId(this.id, this.
|
|
489
|
+
return formatId(this.id, this.ea++);
|
|
412
490
|
throw new Error("Cannot get child id from owner without an id");
|
|
413
491
|
}
|
|
414
492
|
};
|
|
@@ -419,7 +497,7 @@ function getContext(context, owner = currentOwner) {
|
|
|
419
497
|
if (!owner) {
|
|
420
498
|
throw new NoOwnerError();
|
|
421
499
|
}
|
|
422
|
-
const value = hasContext(context, owner) ? owner.
|
|
500
|
+
const value = hasContext(context, owner) ? owner.w[context.id] : context.defaultValue;
|
|
423
501
|
if (isUndefined(value)) {
|
|
424
502
|
throw new ContextNotFoundError();
|
|
425
503
|
}
|
|
@@ -429,24 +507,24 @@ function setContext(context, value, owner = currentOwner) {
|
|
|
429
507
|
if (!owner) {
|
|
430
508
|
throw new NoOwnerError();
|
|
431
509
|
}
|
|
432
|
-
owner.
|
|
433
|
-
...owner.
|
|
510
|
+
owner.w = {
|
|
511
|
+
...owner.w,
|
|
434
512
|
[context.id]: isUndefined(value) ? context.defaultValue : value
|
|
435
513
|
};
|
|
436
514
|
}
|
|
437
515
|
function hasContext(context, owner = currentOwner) {
|
|
438
|
-
return !isUndefined(owner?.
|
|
516
|
+
return !isUndefined(owner?.w[context.id]);
|
|
439
517
|
}
|
|
440
518
|
function onCleanup(fn) {
|
|
441
519
|
if (!currentOwner)
|
|
442
520
|
return fn;
|
|
443
521
|
const node = currentOwner;
|
|
444
|
-
if (!node.
|
|
445
|
-
node.
|
|
446
|
-
} else if (Array.isArray(node.
|
|
447
|
-
node.
|
|
522
|
+
if (!node.n) {
|
|
523
|
+
node.n = fn;
|
|
524
|
+
} else if (Array.isArray(node.n)) {
|
|
525
|
+
node.n.push(fn);
|
|
448
526
|
} else {
|
|
449
|
-
node.
|
|
527
|
+
node.n = [node.n, fn];
|
|
450
528
|
}
|
|
451
529
|
return fn;
|
|
452
530
|
}
|
|
@@ -473,49 +551,49 @@ function getObserver() {
|
|
|
473
551
|
var UNCHANGED = Symbol(0);
|
|
474
552
|
var Computation = class extends Owner {
|
|
475
553
|
a = null;
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
554
|
+
b = null;
|
|
555
|
+
j;
|
|
556
|
+
K;
|
|
557
|
+
L;
|
|
480
558
|
// Used in __DEV__ mode, hopefully removed in production
|
|
481
|
-
|
|
559
|
+
ka;
|
|
482
560
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
483
561
|
// which could enable more efficient DIRTY notification
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
562
|
+
$ = isEqual;
|
|
563
|
+
da;
|
|
564
|
+
ga = false;
|
|
487
565
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
488
|
-
|
|
566
|
+
h = 0;
|
|
489
567
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
568
|
+
aa = DEFAULT_FLAGS;
|
|
569
|
+
M = -1;
|
|
570
|
+
G = false;
|
|
571
|
+
k;
|
|
572
|
+
g;
|
|
495
573
|
constructor(initialValue, compute2, options) {
|
|
496
574
|
super(options?.id, compute2 === null);
|
|
497
|
-
this.
|
|
498
|
-
this.
|
|
499
|
-
this.
|
|
500
|
-
this.
|
|
575
|
+
this.L = compute2;
|
|
576
|
+
this.c = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
577
|
+
this.h = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
578
|
+
this.j = initialValue;
|
|
501
579
|
if (options?.equals !== void 0)
|
|
502
|
-
this
|
|
580
|
+
this.$ = options.equals;
|
|
503
581
|
if (options?.pureWrite)
|
|
504
|
-
this.
|
|
582
|
+
this.ga = true;
|
|
505
583
|
if (options?.unobserved)
|
|
506
|
-
this.
|
|
584
|
+
this.da = options?.unobserved;
|
|
507
585
|
if (ActiveTransition) {
|
|
508
|
-
this.
|
|
586
|
+
this.k = ActiveTransition;
|
|
509
587
|
ActiveTransition.a.set(this, this);
|
|
510
588
|
}
|
|
511
589
|
}
|
|
512
|
-
|
|
590
|
+
fa() {
|
|
513
591
|
track(this);
|
|
514
|
-
newFlags |= this.
|
|
515
|
-
if (this.
|
|
516
|
-
throw this.
|
|
592
|
+
newFlags |= this.h & ~currentMask;
|
|
593
|
+
if (this.h & ERROR_BIT) {
|
|
594
|
+
throw this.K;
|
|
517
595
|
} else {
|
|
518
|
-
return this.
|
|
596
|
+
return this.j;
|
|
519
597
|
}
|
|
520
598
|
}
|
|
521
599
|
/**
|
|
@@ -523,18 +601,18 @@ var Computation = class extends Owner {
|
|
|
523
601
|
* Automatically re-executes the surrounding computation when the value changes
|
|
524
602
|
*/
|
|
525
603
|
read() {
|
|
526
|
-
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
527
|
-
const clone = ActiveTransition.a.get(this);
|
|
604
|
+
if (ActiveTransition && (ActiveTransition.a.has(this) || !this.g && this.h & UNINITIALIZED_BIT)) {
|
|
605
|
+
const clone = ActiveTransition.a.get(this) || cloneGraph(this);
|
|
528
606
|
if (clone !== this)
|
|
529
607
|
return clone.read();
|
|
530
608
|
}
|
|
531
|
-
if (this.
|
|
532
|
-
if (this.
|
|
609
|
+
if (this.L) {
|
|
610
|
+
if (this.h & ERROR_BIT && this.M <= clock)
|
|
533
611
|
update(this);
|
|
534
612
|
else
|
|
535
|
-
this.
|
|
613
|
+
this.H();
|
|
536
614
|
}
|
|
537
|
-
return this.
|
|
615
|
+
return this.fa();
|
|
538
616
|
}
|
|
539
617
|
/**
|
|
540
618
|
* Return the current value of this computation
|
|
@@ -544,69 +622,65 @@ var Computation = class extends Owner {
|
|
|
544
622
|
* before continuing
|
|
545
623
|
*/
|
|
546
624
|
wait() {
|
|
547
|
-
if (ActiveTransition && ActiveTransition.a.has(this)) {
|
|
548
|
-
const clone = ActiveTransition.a.get(this);
|
|
625
|
+
if (ActiveTransition && (ActiveTransition.a.has(this) || !this.g && this.h & UNINITIALIZED_BIT)) {
|
|
626
|
+
const clone = ActiveTransition.a.get(this) || cloneGraph(this);
|
|
549
627
|
if (clone !== this)
|
|
550
628
|
return clone.wait();
|
|
551
629
|
}
|
|
552
|
-
if (this.
|
|
553
|
-
if (this.
|
|
630
|
+
if (this.L) {
|
|
631
|
+
if (this.h & ERROR_BIT && this.M <= clock)
|
|
554
632
|
update(this);
|
|
555
633
|
else
|
|
556
|
-
this.
|
|
634
|
+
this.H();
|
|
557
635
|
}
|
|
558
|
-
if ((notStale || this.
|
|
636
|
+
if ((notStale || this.h & UNINITIALIZED_BIT) && this.h & LOADING_BIT) {
|
|
559
637
|
track(this);
|
|
560
638
|
throw new NotReadyError();
|
|
561
639
|
}
|
|
562
|
-
if (staleCheck && this.
|
|
563
|
-
staleCheck.
|
|
640
|
+
if (staleCheck && this.h & LOADING_BIT) {
|
|
641
|
+
staleCheck.j = true;
|
|
564
642
|
}
|
|
565
|
-
return this.
|
|
643
|
+
return this.fa();
|
|
566
644
|
}
|
|
567
645
|
/** Update the computation with a new value. */
|
|
568
646
|
write(value, flags = 0, raw = false) {
|
|
569
|
-
if (ActiveTransition && !this.
|
|
647
|
+
if (ActiveTransition && !this.g) {
|
|
570
648
|
const clone = cloneGraph(this);
|
|
571
|
-
|
|
649
|
+
if (clone !== this)
|
|
650
|
+
return clone.write(value, flags, raw);
|
|
572
651
|
}
|
|
573
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
574
|
-
const valueChanged = newValue !== UNCHANGED && (!!(this.
|
|
575
|
-
this
|
|
652
|
+
const newValue = !raw && typeof value === "function" ? value(this.j) : value;
|
|
653
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.h & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
|
|
654
|
+
this.$ === false || !this.$(this.j, newValue));
|
|
576
655
|
if (valueChanged) {
|
|
577
|
-
this.
|
|
578
|
-
this.
|
|
579
|
-
}
|
|
580
|
-
const changedFlagsMask = this.
|
|
581
|
-
this.
|
|
582
|
-
this.
|
|
583
|
-
if (this.
|
|
584
|
-
for (let i = 0; i < this.
|
|
656
|
+
this.j = newValue;
|
|
657
|
+
this.K = void 0;
|
|
658
|
+
}
|
|
659
|
+
const changedFlagsMask = this.h ^ flags, changedFlags = changedFlagsMask & flags;
|
|
660
|
+
this.h = flags;
|
|
661
|
+
this.M = clock + 1;
|
|
662
|
+
if (this.b) {
|
|
663
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
585
664
|
if (valueChanged) {
|
|
586
|
-
this.
|
|
665
|
+
this.b[i].x(STATE_DIRTY);
|
|
587
666
|
} else if (changedFlagsMask) {
|
|
588
|
-
this.
|
|
667
|
+
this.b[i].Y(changedFlagsMask, changedFlags);
|
|
589
668
|
}
|
|
590
669
|
}
|
|
591
670
|
}
|
|
592
|
-
return this.
|
|
671
|
+
return this.j;
|
|
593
672
|
}
|
|
594
673
|
/**
|
|
595
674
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
596
675
|
*/
|
|
597
|
-
|
|
598
|
-
if (
|
|
599
|
-
const clone = ActiveTransition.a.get(this);
|
|
600
|
-
if (clone !== this)
|
|
601
|
-
return clone.k(state, skipQueue);
|
|
602
|
-
}
|
|
603
|
-
if (this.b >= state && !this.C)
|
|
676
|
+
x(state, skipQueue) {
|
|
677
|
+
if (this.c >= state && !this.G)
|
|
604
678
|
return;
|
|
605
|
-
this.
|
|
606
|
-
this.
|
|
607
|
-
if (this.
|
|
608
|
-
for (let i = 0; i < this.
|
|
609
|
-
this.
|
|
679
|
+
this.G = !!skipQueue;
|
|
680
|
+
this.c = state;
|
|
681
|
+
if (this.b) {
|
|
682
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
683
|
+
this.b[i].x(STATE_CHECK, skipQueue);
|
|
610
684
|
}
|
|
611
685
|
}
|
|
612
686
|
}
|
|
@@ -616,31 +690,36 @@ var Computation = class extends Owner {
|
|
|
616
690
|
* @param mask A bitmask for which flag(s) were changed.
|
|
617
691
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
618
692
|
*/
|
|
619
|
-
|
|
620
|
-
if (this.
|
|
693
|
+
Y(mask, newFlags2) {
|
|
694
|
+
if (this.c >= STATE_DIRTY)
|
|
621
695
|
return;
|
|
622
|
-
if (mask & this
|
|
623
|
-
this.
|
|
696
|
+
if (mask & this.aa) {
|
|
697
|
+
this.x(STATE_DIRTY);
|
|
624
698
|
return;
|
|
625
699
|
}
|
|
626
|
-
if (this.
|
|
700
|
+
if (this.c >= STATE_CHECK)
|
|
627
701
|
return;
|
|
628
|
-
const prevFlags = this.
|
|
702
|
+
const prevFlags = this.h & mask;
|
|
629
703
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
630
704
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
631
|
-
this.
|
|
705
|
+
this.x(STATE_CHECK);
|
|
632
706
|
} else {
|
|
633
|
-
this.
|
|
634
|
-
if (this.
|
|
635
|
-
for (let i = 0; i < this.
|
|
636
|
-
this.
|
|
707
|
+
this.h ^= deltaFlags;
|
|
708
|
+
if (this.b) {
|
|
709
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
710
|
+
this.b[i].Y(mask, newFlags2);
|
|
637
711
|
}
|
|
638
712
|
}
|
|
639
713
|
}
|
|
640
714
|
}
|
|
641
|
-
|
|
642
|
-
this.
|
|
643
|
-
|
|
715
|
+
N(error) {
|
|
716
|
+
if (ActiveTransition && !this.g) {
|
|
717
|
+
const clone = cloneGraph(this);
|
|
718
|
+
if (clone !== this)
|
|
719
|
+
return clone.N(error);
|
|
720
|
+
}
|
|
721
|
+
this.K = error;
|
|
722
|
+
this.write(UNCHANGED, this.h & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
644
723
|
}
|
|
645
724
|
/**
|
|
646
725
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -649,48 +728,48 @@ var Computation = class extends Owner {
|
|
|
649
728
|
*
|
|
650
729
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
651
730
|
*/
|
|
652
|
-
|
|
653
|
-
if (!this.
|
|
731
|
+
H() {
|
|
732
|
+
if (!this.L) {
|
|
654
733
|
return;
|
|
655
734
|
}
|
|
656
|
-
if (this.
|
|
735
|
+
if (this.c === STATE_DISPOSED) {
|
|
657
736
|
return;
|
|
658
737
|
}
|
|
659
|
-
if (this.
|
|
738
|
+
if (this.c === STATE_CLEAN) {
|
|
660
739
|
return;
|
|
661
740
|
}
|
|
662
741
|
let observerFlags = 0;
|
|
663
|
-
if (this.
|
|
742
|
+
if (this.c === STATE_CHECK) {
|
|
664
743
|
for (let i = 0; i < this.a.length; i++) {
|
|
665
744
|
const source = ActiveTransition && ActiveTransition.a.get(this.a[i]) || this.a[i];
|
|
666
|
-
source.
|
|
667
|
-
observerFlags |= source.
|
|
668
|
-
if (this.
|
|
745
|
+
source.H();
|
|
746
|
+
observerFlags |= source.h & ~UNINITIALIZED_BIT;
|
|
747
|
+
if (this.c === STATE_DIRTY) {
|
|
669
748
|
break;
|
|
670
749
|
}
|
|
671
750
|
}
|
|
672
751
|
}
|
|
673
|
-
if (this.
|
|
752
|
+
if (this.c === STATE_DIRTY) {
|
|
674
753
|
update(this);
|
|
675
754
|
} else {
|
|
676
755
|
this.write(UNCHANGED, observerFlags);
|
|
677
|
-
this.
|
|
756
|
+
this.c = STATE_CLEAN;
|
|
678
757
|
}
|
|
679
758
|
}
|
|
680
759
|
/**
|
|
681
760
|
* Remove ourselves from the owner graph and the computation graph
|
|
682
761
|
*/
|
|
683
|
-
|
|
684
|
-
if (this.
|
|
762
|
+
J() {
|
|
763
|
+
if (this.c === STATE_DISPOSED)
|
|
685
764
|
return;
|
|
686
765
|
if (this.a)
|
|
687
766
|
removeSourceObservers(this, 0);
|
|
688
|
-
super.
|
|
767
|
+
super.J();
|
|
689
768
|
}
|
|
690
769
|
};
|
|
691
770
|
function track(computation) {
|
|
692
|
-
if (ActiveTransition && computation.
|
|
693
|
-
computation = computation.
|
|
771
|
+
if (ActiveTransition && computation.g)
|
|
772
|
+
computation = computation.g;
|
|
694
773
|
if (currentObserver) {
|
|
695
774
|
if (!newSources && currentObserver.a && currentObserver.a[newSourcesIndex] === computation) {
|
|
696
775
|
newSourcesIndex++;
|
|
@@ -700,7 +779,7 @@ function track(computation) {
|
|
|
700
779
|
newSources.push(computation);
|
|
701
780
|
}
|
|
702
781
|
if (updateCheck) {
|
|
703
|
-
updateCheck.
|
|
782
|
+
updateCheck.j = computation.M > currentObserver.M;
|
|
704
783
|
}
|
|
705
784
|
}
|
|
706
785
|
}
|
|
@@ -712,13 +791,13 @@ function update(node) {
|
|
|
712
791
|
try {
|
|
713
792
|
node.dispose(false);
|
|
714
793
|
node.emptyDisposal();
|
|
715
|
-
const result = compute(node, node.
|
|
794
|
+
const result = compute(node, node.L, node);
|
|
716
795
|
node.write(result, newFlags, true);
|
|
717
796
|
} catch (error) {
|
|
718
797
|
if (error instanceof NotReadyError) {
|
|
719
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT | node.
|
|
798
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.h & UNINITIALIZED_BIT);
|
|
720
799
|
} else {
|
|
721
|
-
node.
|
|
800
|
+
node.N(error);
|
|
722
801
|
}
|
|
723
802
|
} finally {
|
|
724
803
|
if (newSources) {
|
|
@@ -734,11 +813,11 @@ function update(node) {
|
|
|
734
813
|
}
|
|
735
814
|
let source;
|
|
736
815
|
for (let i = newSourcesIndex; i < node.a.length; i++) {
|
|
737
|
-
source = node.a[i];
|
|
738
|
-
if (!source.
|
|
739
|
-
source.
|
|
816
|
+
source = ActiveTransition && ActiveTransition.a.get(node.a[i]) || node.a[i];
|
|
817
|
+
if (!source.b)
|
|
818
|
+
source.b = [node];
|
|
740
819
|
else
|
|
741
|
-
source.
|
|
820
|
+
source.b.push(node);
|
|
742
821
|
}
|
|
743
822
|
} else if (node.a && newSourcesIndex < node.a.length) {
|
|
744
823
|
removeSourceObservers(node, newSourcesIndex);
|
|
@@ -747,8 +826,23 @@ function update(node) {
|
|
|
747
826
|
newSources = prevSources;
|
|
748
827
|
newSourcesIndex = prevSourcesIndex;
|
|
749
828
|
newFlags = prevFlags;
|
|
750
|
-
node.
|
|
751
|
-
node.
|
|
829
|
+
node.M = clock + 1;
|
|
830
|
+
node.c = STATE_CLEAN;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
function removeSourceObservers(node, index) {
|
|
834
|
+
let source;
|
|
835
|
+
let swap;
|
|
836
|
+
for (let i = index; i < node.a.length; i++) {
|
|
837
|
+
source = ActiveTransition && ActiveTransition.a.get(node.a[i]) || node.a[i];
|
|
838
|
+
if (source.b) {
|
|
839
|
+
if ((swap = source.b.indexOf(node)) !== -1) {
|
|
840
|
+
source.b[swap] = source.b[source.b.length - 1];
|
|
841
|
+
source.b.pop();
|
|
842
|
+
}
|
|
843
|
+
if (!source.b.length)
|
|
844
|
+
Unobserved.push(source);
|
|
845
|
+
}
|
|
752
846
|
}
|
|
753
847
|
}
|
|
754
848
|
function isEqual(a, b) {
|
|
@@ -761,20 +855,20 @@ function untrack(fn) {
|
|
|
761
855
|
}
|
|
762
856
|
function hasUpdated(fn) {
|
|
763
857
|
const current = updateCheck;
|
|
764
|
-
updateCheck = {
|
|
858
|
+
updateCheck = { j: false };
|
|
765
859
|
try {
|
|
766
860
|
fn();
|
|
767
|
-
return updateCheck.
|
|
861
|
+
return updateCheck.j;
|
|
768
862
|
} finally {
|
|
769
863
|
updateCheck = current;
|
|
770
864
|
}
|
|
771
865
|
}
|
|
772
866
|
function pendingCheck(fn, loadingValue) {
|
|
773
867
|
const current = staleCheck;
|
|
774
|
-
staleCheck = {
|
|
868
|
+
staleCheck = { j: false };
|
|
775
869
|
try {
|
|
776
870
|
latest(fn);
|
|
777
|
-
return staleCheck.
|
|
871
|
+
return staleCheck.j;
|
|
778
872
|
} catch (err) {
|
|
779
873
|
if (!(err instanceof NotReadyError))
|
|
780
874
|
return false;
|
|
@@ -789,7 +883,7 @@ function isPending(fn, loadingValue) {
|
|
|
789
883
|
if (!currentObserver)
|
|
790
884
|
return pendingCheck(fn, loadingValue);
|
|
791
885
|
const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
|
|
792
|
-
c
|
|
886
|
+
c.aa |= LOADING_BIT;
|
|
793
887
|
return c.read();
|
|
794
888
|
}
|
|
795
889
|
function latest(fn, fallback) {
|
|
@@ -819,10 +913,10 @@ function runWithObserver(observer, run) {
|
|
|
819
913
|
if (error instanceof NotReadyError) {
|
|
820
914
|
observer.write(
|
|
821
915
|
UNCHANGED,
|
|
822
|
-
newFlags | LOADING_BIT | observer.
|
|
916
|
+
newFlags | LOADING_BIT | observer.h & UNINITIALIZED_BIT
|
|
823
917
|
);
|
|
824
918
|
} else {
|
|
825
|
-
observer.
|
|
919
|
+
observer.N(error);
|
|
826
920
|
}
|
|
827
921
|
} finally {
|
|
828
922
|
if (newSources) {
|
|
@@ -837,10 +931,10 @@ function runWithObserver(observer, run) {
|
|
|
837
931
|
let source;
|
|
838
932
|
for (let i = newSourcesIndex; i < observer.a.length; i++) {
|
|
839
933
|
source = observer.a[i];
|
|
840
|
-
if (!source.
|
|
841
|
-
source.
|
|
934
|
+
if (!source.b)
|
|
935
|
+
source.b = [observer];
|
|
842
936
|
else
|
|
843
|
-
source.
|
|
937
|
+
source.b.push(observer);
|
|
844
938
|
}
|
|
845
939
|
}
|
|
846
940
|
newSources = prevSources;
|
|
@@ -851,10 +945,10 @@ function runWithObserver(observer, run) {
|
|
|
851
945
|
function compute(owner, fn, observer) {
|
|
852
946
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
853
947
|
currentObserver = observer;
|
|
854
|
-
currentMask = observer
|
|
948
|
+
currentMask = observer?.aa ?? DEFAULT_FLAGS;
|
|
855
949
|
notStale = true;
|
|
856
950
|
try {
|
|
857
|
-
return fn(observer ? observer.
|
|
951
|
+
return fn.call(observer, observer ? observer.j : void 0);
|
|
858
952
|
} finally {
|
|
859
953
|
setOwner(prevOwner);
|
|
860
954
|
currentObserver = prevObserver;
|
|
@@ -865,120 +959,118 @@ function compute(owner, fn, observer) {
|
|
|
865
959
|
|
|
866
960
|
// src/core/effect.ts
|
|
867
961
|
var Effect = class extends Computation {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
962
|
+
ba;
|
|
963
|
+
Z;
|
|
964
|
+
O;
|
|
965
|
+
ca = false;
|
|
966
|
+
_;
|
|
967
|
+
A;
|
|
874
968
|
constructor(initialValue, compute2, effect, error, options) {
|
|
875
969
|
super(initialValue, compute2, options);
|
|
876
|
-
this.
|
|
877
|
-
this.
|
|
878
|
-
this.
|
|
879
|
-
this.
|
|
880
|
-
if (this.
|
|
881
|
-
this.
|
|
970
|
+
this.ba = effect;
|
|
971
|
+
this.Z = error;
|
|
972
|
+
this._ = initialValue;
|
|
973
|
+
this.A = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
974
|
+
if (this.A === EFFECT_RENDER) {
|
|
975
|
+
this.L = function(p) {
|
|
976
|
+
return !this.g && clock > this.l.created && !(this.h & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
977
|
+
};
|
|
882
978
|
}
|
|
883
|
-
this.
|
|
884
|
-
!options?.defer && (this.
|
|
979
|
+
this.H();
|
|
980
|
+
!options?.defer && (this.A === EFFECT_USER ? this.l.enqueue(this.A, this.C.bind(this)) : this.C(this.A));
|
|
885
981
|
}
|
|
886
982
|
write(value, flags = 0) {
|
|
887
|
-
if (this.
|
|
888
|
-
this.
|
|
889
|
-
if (this.
|
|
890
|
-
|
|
983
|
+
if (this.c == STATE_DIRTY) {
|
|
984
|
+
this.h = flags;
|
|
985
|
+
if (this.A === EFFECT_RENDER) {
|
|
986
|
+
this.l.notify(this, LOADING_BIT | ERROR_BIT, this.h);
|
|
891
987
|
}
|
|
892
988
|
}
|
|
893
989
|
if (value === UNCHANGED)
|
|
894
|
-
return this.
|
|
895
|
-
this.
|
|
896
|
-
this.
|
|
990
|
+
return this.j;
|
|
991
|
+
this.j = value;
|
|
992
|
+
this.ca = true;
|
|
993
|
+
this.K = void 0;
|
|
897
994
|
return value;
|
|
898
995
|
}
|
|
899
|
-
|
|
900
|
-
if (
|
|
901
|
-
return ActiveTransition.a.get(this).k(state, skipQueue);
|
|
902
|
-
}
|
|
903
|
-
if (this.b >= state || skipQueue)
|
|
996
|
+
x(state, skipQueue) {
|
|
997
|
+
if (this.c >= state || skipQueue)
|
|
904
998
|
return;
|
|
905
|
-
if (this.
|
|
906
|
-
|
|
907
|
-
this.
|
|
999
|
+
if (this.c === STATE_CLEAN)
|
|
1000
|
+
this.l.enqueue(this.A, this.C.bind(this));
|
|
1001
|
+
this.c = state;
|
|
908
1002
|
}
|
|
909
|
-
|
|
910
|
-
if (
|
|
911
|
-
if (this.
|
|
1003
|
+
Y(mask, newFlags2) {
|
|
1004
|
+
if (this.g) {
|
|
1005
|
+
if (this.c >= STATE_DIRTY)
|
|
912
1006
|
return;
|
|
913
1007
|
if (mask & 3) {
|
|
914
|
-
this.
|
|
1008
|
+
this.x(STATE_DIRTY);
|
|
915
1009
|
return;
|
|
916
1010
|
}
|
|
917
1011
|
}
|
|
918
|
-
super.
|
|
1012
|
+
super.Y(mask, newFlags2);
|
|
919
1013
|
}
|
|
920
|
-
|
|
921
|
-
this.
|
|
922
|
-
|
|
923
|
-
this.
|
|
924
|
-
if (this.
|
|
1014
|
+
N(error) {
|
|
1015
|
+
this.K = error;
|
|
1016
|
+
this.l.notify(this, LOADING_BIT, 0);
|
|
1017
|
+
this.h = ERROR_BIT;
|
|
1018
|
+
if (this.A === EFFECT_USER) {
|
|
925
1019
|
try {
|
|
926
|
-
return this.
|
|
927
|
-
this.
|
|
928
|
-
this.
|
|
1020
|
+
return this.Z ? this.Z(error, () => {
|
|
1021
|
+
this.O?.();
|
|
1022
|
+
this.O = void 0;
|
|
929
1023
|
}) : console.error(error);
|
|
930
1024
|
} catch (e) {
|
|
931
1025
|
error = e;
|
|
932
1026
|
}
|
|
933
1027
|
}
|
|
934
|
-
if (!
|
|
1028
|
+
if (!this.l.notify(this, ERROR_BIT, ERROR_BIT))
|
|
935
1029
|
throw error;
|
|
936
1030
|
}
|
|
937
|
-
|
|
938
|
-
if (this.
|
|
1031
|
+
J() {
|
|
1032
|
+
if (this.c === STATE_DISPOSED)
|
|
939
1033
|
return;
|
|
940
|
-
this.
|
|
941
|
-
this.
|
|
942
|
-
this.
|
|
943
|
-
this.
|
|
944
|
-
this.
|
|
945
|
-
super.
|
|
946
|
-
}
|
|
947
|
-
|
|
1034
|
+
this.ba = void 0;
|
|
1035
|
+
this._ = void 0;
|
|
1036
|
+
this.Z = void 0;
|
|
1037
|
+
this.O?.();
|
|
1038
|
+
this.O = void 0;
|
|
1039
|
+
super.J();
|
|
1040
|
+
}
|
|
1041
|
+
C(type) {
|
|
948
1042
|
if (type) {
|
|
949
|
-
|
|
950
|
-
|
|
1043
|
+
const effect = this.g || this;
|
|
1044
|
+
if (effect.ca && effect.c !== STATE_DISPOSED) {
|
|
1045
|
+
effect.O?.();
|
|
951
1046
|
try {
|
|
952
|
-
|
|
1047
|
+
effect.O = effect.ba(effect.j, effect._);
|
|
953
1048
|
} catch (e) {
|
|
954
|
-
if (!
|
|
1049
|
+
if (!effect.l.notify(effect, ERROR_BIT, ERROR_BIT))
|
|
955
1050
|
throw e;
|
|
956
1051
|
} finally {
|
|
957
|
-
|
|
958
|
-
|
|
1052
|
+
effect._ = effect.j;
|
|
1053
|
+
effect.ca = false;
|
|
959
1054
|
}
|
|
960
1055
|
}
|
|
961
1056
|
} else
|
|
962
|
-
this.
|
|
1057
|
+
this.c !== STATE_CLEAN && runTop(this);
|
|
963
1058
|
}
|
|
964
1059
|
};
|
|
965
1060
|
var EagerComputation = class extends Computation {
|
|
966
1061
|
constructor(initialValue, compute2, options) {
|
|
967
1062
|
super(initialValue, compute2, options);
|
|
968
|
-
!options?.defer && this.
|
|
1063
|
+
!options?.defer && this.H();
|
|
969
1064
|
}
|
|
970
|
-
|
|
971
|
-
if (
|
|
972
|
-
return ActiveTransition.a.get(this).k(state, skipQueue);
|
|
973
|
-
}
|
|
974
|
-
if (this.b >= state && !this.C)
|
|
1065
|
+
x(state, skipQueue) {
|
|
1066
|
+
if (this.c >= state && !this.G)
|
|
975
1067
|
return;
|
|
976
|
-
if (!skipQueue && (this.
|
|
977
|
-
|
|
978
|
-
super.
|
|
1068
|
+
if (!skipQueue && (this.c === STATE_CLEAN || this.c === STATE_CHECK && this.G))
|
|
1069
|
+
this.l.enqueue(EFFECT_PURE, this.C.bind(this));
|
|
1070
|
+
super.x(state, skipQueue);
|
|
979
1071
|
}
|
|
980
|
-
|
|
981
|
-
this.
|
|
1072
|
+
C() {
|
|
1073
|
+
this.c !== STATE_CLEAN && runTop(this);
|
|
982
1074
|
}
|
|
983
1075
|
};
|
|
984
1076
|
var FirewallComputation = class extends Computation {
|
|
@@ -986,31 +1078,28 @@ var FirewallComputation = class extends Computation {
|
|
|
986
1078
|
constructor(compute2) {
|
|
987
1079
|
super(void 0, compute2);
|
|
988
1080
|
}
|
|
989
|
-
|
|
990
|
-
if (
|
|
991
|
-
return ActiveTransition.a.get(this).k(state, skipQueue);
|
|
992
|
-
}
|
|
993
|
-
if (this.b >= state && !this.C)
|
|
1081
|
+
x(state, skipQueue) {
|
|
1082
|
+
if (this.c >= state && !this.G)
|
|
994
1083
|
return;
|
|
995
|
-
if (!skipQueue && (this.
|
|
996
|
-
|
|
997
|
-
super.
|
|
998
|
-
this.
|
|
1084
|
+
if (!skipQueue && (this.c === STATE_CLEAN || this.c === STATE_CHECK && this.G))
|
|
1085
|
+
this.l.enqueue(EFFECT_PURE, this.C.bind(this));
|
|
1086
|
+
super.x(state, true);
|
|
1087
|
+
this.G = !!skipQueue;
|
|
999
1088
|
}
|
|
1000
|
-
|
|
1001
|
-
this.
|
|
1089
|
+
C() {
|
|
1090
|
+
this.c !== STATE_CLEAN && runTop(this);
|
|
1002
1091
|
}
|
|
1003
1092
|
};
|
|
1004
1093
|
function runTop(node) {
|
|
1005
1094
|
const ancestors = [];
|
|
1006
|
-
for (let current = node; current !== null; current = current.
|
|
1007
|
-
if (current.
|
|
1095
|
+
for (let current = node; current !== null; current = current.m) {
|
|
1096
|
+
if (current.c !== STATE_CLEAN) {
|
|
1008
1097
|
ancestors.push(current);
|
|
1009
1098
|
}
|
|
1010
1099
|
}
|
|
1011
1100
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
1012
|
-
if (ancestors[i].
|
|
1013
|
-
ancestors[i].
|
|
1101
|
+
if (ancestors[i].c !== STATE_DISPOSED)
|
|
1102
|
+
ancestors[i].H();
|
|
1014
1103
|
}
|
|
1015
1104
|
}
|
|
1016
1105
|
|
|
@@ -1144,7 +1233,7 @@ var storeTraps = {
|
|
|
1144
1233
|
return desc.get.call(receiver);
|
|
1145
1234
|
}
|
|
1146
1235
|
if (Writing?.has(receiver)) {
|
|
1147
|
-
let value2 = tracked && (overridden || !proxySource) ? tracked.
|
|
1236
|
+
let value2 = tracked && (overridden || !proxySource) ? tracked.j : storeValue[property];
|
|
1148
1237
|
value2 === $DELETED && (value2 = void 0);
|
|
1149
1238
|
if (!isWrappable(value2))
|
|
1150
1239
|
return value2;
|
|
@@ -1435,6 +1524,8 @@ function applyState(next, state, keyFn, all) {
|
|
|
1435
1524
|
}
|
|
1436
1525
|
function reconcile(value, key, all = false) {
|
|
1437
1526
|
return (state) => {
|
|
1527
|
+
if (state == null)
|
|
1528
|
+
throw new Error("Cannot reconcile null or undefined state");
|
|
1438
1529
|
const keyFn = typeof key === "string" ? (item) => item[key] : key;
|
|
1439
1530
|
const eq = keyFn(state);
|
|
1440
1531
|
if (eq !== void 0 && keyFn(value) !== keyFn(state))
|
|
@@ -1674,12 +1765,12 @@ function createMemo(compute2, value, options) {
|
|
|
1674
1765
|
let resolvedValue;
|
|
1675
1766
|
return () => {
|
|
1676
1767
|
if (node) {
|
|
1677
|
-
if (node.
|
|
1768
|
+
if (node.c === STATE_DISPOSED) {
|
|
1678
1769
|
node = void 0;
|
|
1679
1770
|
return resolvedValue;
|
|
1680
1771
|
}
|
|
1681
1772
|
resolvedValue = node.wait();
|
|
1682
|
-
if (!node.a?.length && node.r?.
|
|
1773
|
+
if (!node.a?.length && node.r?.m !== node && !(node.h & UNINITIALIZED_BIT)) {
|
|
1683
1774
|
node.dispose();
|
|
1684
1775
|
node = void 0;
|
|
1685
1776
|
}
|
|
@@ -1715,8 +1806,8 @@ function createAsync(compute2, value, options) {
|
|
|
1715
1806
|
if (abort)
|
|
1716
1807
|
return;
|
|
1717
1808
|
if (transition2)
|
|
1718
|
-
return transition2.runTransition(() => node.
|
|
1719
|
-
node.
|
|
1809
|
+
return transition2.runTransition(() => node.N(error), true);
|
|
1810
|
+
node.N(error);
|
|
1720
1811
|
}
|
|
1721
1812
|
);
|
|
1722
1813
|
} else {
|
|
@@ -1740,9 +1831,13 @@ function createAsync(compute2, value, options) {
|
|
|
1740
1831
|
);
|
|
1741
1832
|
const read = node.wait.bind(node);
|
|
1742
1833
|
read.refresh = () => {
|
|
1743
|
-
|
|
1834
|
+
let n = node;
|
|
1835
|
+
if (ActiveTransition && !node.g) {
|
|
1836
|
+
n = cloneGraph(node);
|
|
1837
|
+
}
|
|
1838
|
+
n.c = STATE_DIRTY;
|
|
1744
1839
|
refreshing = true;
|
|
1745
|
-
|
|
1840
|
+
n.H();
|
|
1746
1841
|
};
|
|
1747
1842
|
return read;
|
|
1748
1843
|
}
|
|
@@ -1823,7 +1918,7 @@ function createOptimistic(initial, compute2, key) {
|
|
|
1823
1918
|
(s) => {
|
|
1824
1919
|
const value = initial();
|
|
1825
1920
|
if (!ActiveTransition)
|
|
1826
|
-
|
|
1921
|
+
reconcile({ value }, key)(s);
|
|
1827
1922
|
},
|
|
1828
1923
|
{ value: void 0 }
|
|
1829
1924
|
);
|
|
@@ -1831,9 +1926,9 @@ function createOptimistic(initial, compute2, key) {
|
|
|
1831
1926
|
[store, setStore] = createStore({ value: initial });
|
|
1832
1927
|
const reset = () => setStore(
|
|
1833
1928
|
(s) => reconcile(
|
|
1834
|
-
typeof initial === "function" ? initial() : initial,
|
|
1929
|
+
{ value: typeof initial === "function" ? initial() : initial },
|
|
1835
1930
|
key
|
|
1836
|
-
)(s
|
|
1931
|
+
)(s)
|
|
1837
1932
|
);
|
|
1838
1933
|
let lastChange = void 0;
|
|
1839
1934
|
function write(v) {
|
|
@@ -1854,196 +1949,196 @@ function createOptimistic(initial, compute2, key) {
|
|
|
1854
1949
|
function mapArray(list, map, options) {
|
|
1855
1950
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1856
1951
|
return updateKeyedMap.bind({
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1952
|
+
S: new Owner(),
|
|
1953
|
+
o: 0,
|
|
1954
|
+
ha: list,
|
|
1955
|
+
D: [],
|
|
1956
|
+
P: map,
|
|
1957
|
+
i: [],
|
|
1958
|
+
d: [],
|
|
1959
|
+
Q: keyFn,
|
|
1960
|
+
p: keyFn || options?.keyed === false ? [] : void 0,
|
|
1961
|
+
q: map.length > 1 ? [] : void 0,
|
|
1962
|
+
T: options?.fallback
|
|
1868
1963
|
});
|
|
1869
1964
|
}
|
|
1870
1965
|
var pureOptions = { pureWrite: true };
|
|
1871
1966
|
function updateKeyedMap() {
|
|
1872
|
-
const newItems = this.
|
|
1967
|
+
const newItems = this.ha() || [], newLen = newItems.length;
|
|
1873
1968
|
newItems[$TRACK];
|
|
1874
|
-
runWithOwner(this.
|
|
1875
|
-
let i, j, mapper = this.
|
|
1876
|
-
this.
|
|
1877
|
-
this.
|
|
1878
|
-
return this.
|
|
1879
|
-
Computation.prototype.read.bind(this.
|
|
1880
|
-
this.
|
|
1969
|
+
runWithOwner(this.S, () => {
|
|
1970
|
+
let i, j, mapper = this.p ? () => {
|
|
1971
|
+
this.p[j] = new Computation(newItems[j], null, pureOptions);
|
|
1972
|
+
this.q && (this.q[j] = new Computation(j, null, pureOptions));
|
|
1973
|
+
return this.P(
|
|
1974
|
+
Computation.prototype.read.bind(this.p[j]),
|
|
1975
|
+
this.q ? Computation.prototype.read.bind(this.q[j]) : void 0
|
|
1881
1976
|
);
|
|
1882
|
-
} : this.
|
|
1977
|
+
} : this.q ? () => {
|
|
1883
1978
|
const item = newItems[j];
|
|
1884
|
-
this.
|
|
1885
|
-
return this.
|
|
1979
|
+
this.q[j] = new Computation(j, null, pureOptions);
|
|
1980
|
+
return this.P(() => item, Computation.prototype.read.bind(this.q[j]));
|
|
1886
1981
|
} : () => {
|
|
1887
1982
|
const item = newItems[j];
|
|
1888
|
-
return this.
|
|
1983
|
+
return this.P(() => item);
|
|
1889
1984
|
};
|
|
1890
1985
|
if (newLen === 0) {
|
|
1891
|
-
if (this.
|
|
1892
|
-
this.
|
|
1893
|
-
this.
|
|
1894
|
-
this.
|
|
1895
|
-
this.
|
|
1896
|
-
this.
|
|
1897
|
-
this.
|
|
1898
|
-
this.
|
|
1986
|
+
if (this.o !== 0) {
|
|
1987
|
+
this.S.dispose(false);
|
|
1988
|
+
this.d = [];
|
|
1989
|
+
this.D = [];
|
|
1990
|
+
this.i = [];
|
|
1991
|
+
this.o = 0;
|
|
1992
|
+
this.p && (this.p = []);
|
|
1993
|
+
this.q && (this.q = []);
|
|
1899
1994
|
}
|
|
1900
|
-
if (this.
|
|
1901
|
-
this.
|
|
1902
|
-
this.
|
|
1903
|
-
this.
|
|
1995
|
+
if (this.T && !this.i[0]) {
|
|
1996
|
+
this.i[0] = compute(
|
|
1997
|
+
this.d[0] = new Owner(),
|
|
1998
|
+
this.T,
|
|
1904
1999
|
null
|
|
1905
2000
|
);
|
|
1906
2001
|
}
|
|
1907
|
-
} else if (this.
|
|
1908
|
-
if (this.
|
|
1909
|
-
this.
|
|
1910
|
-
this.
|
|
2002
|
+
} else if (this.o === 0) {
|
|
2003
|
+
if (this.d[0])
|
|
2004
|
+
this.d[0].dispose();
|
|
2005
|
+
this.i = new Array(newLen);
|
|
1911
2006
|
for (j = 0; j < newLen; j++) {
|
|
1912
|
-
this.
|
|
1913
|
-
this.
|
|
2007
|
+
this.D[j] = newItems[j];
|
|
2008
|
+
this.i[j] = compute(this.d[j] = new Owner(), mapper, null);
|
|
1914
2009
|
}
|
|
1915
|
-
this.
|
|
2010
|
+
this.o = newLen;
|
|
1916
2011
|
} else {
|
|
1917
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.
|
|
1918
|
-
for (start = 0, end = Math.min(this.
|
|
1919
|
-
if (this.
|
|
1920
|
-
this.
|
|
2012
|
+
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.p ? new Array(newLen) : void 0, tempIndexes = this.q ? new Array(newLen) : void 0;
|
|
2013
|
+
for (start = 0, end = Math.min(this.o, newLen); start < end && (this.D[start] === newItems[start] || this.p && compare(this.Q, this.D[start], newItems[start])); start++) {
|
|
2014
|
+
if (this.p)
|
|
2015
|
+
this.p[start].write(newItems[start]);
|
|
1921
2016
|
}
|
|
1922
|
-
for (end = this.
|
|
1923
|
-
temp[newEnd] = this.
|
|
1924
|
-
tempNodes[newEnd] = this.
|
|
1925
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1926
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
2017
|
+
for (end = this.o - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.D[end] === newItems[newEnd] || this.p && compare(this.Q, this.D[end], newItems[newEnd])); end--, newEnd--) {
|
|
2018
|
+
temp[newEnd] = this.i[end];
|
|
2019
|
+
tempNodes[newEnd] = this.d[end];
|
|
2020
|
+
tempRows && (tempRows[newEnd] = this.p[end]);
|
|
2021
|
+
tempIndexes && (tempIndexes[newEnd] = this.q[end]);
|
|
1927
2022
|
}
|
|
1928
2023
|
newIndices = /* @__PURE__ */ new Map();
|
|
1929
2024
|
newIndicesNext = new Array(newEnd + 1);
|
|
1930
2025
|
for (j = newEnd; j >= start; j--) {
|
|
1931
2026
|
item = newItems[j];
|
|
1932
|
-
key = this.
|
|
2027
|
+
key = this.Q ? this.Q(item) : item;
|
|
1933
2028
|
i = newIndices.get(key);
|
|
1934
2029
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1935
2030
|
newIndices.set(key, j);
|
|
1936
2031
|
}
|
|
1937
2032
|
for (i = start; i <= end; i++) {
|
|
1938
|
-
item = this.
|
|
1939
|
-
key = this.
|
|
2033
|
+
item = this.D[i];
|
|
2034
|
+
key = this.Q ? this.Q(item) : item;
|
|
1940
2035
|
j = newIndices.get(key);
|
|
1941
2036
|
if (j !== void 0 && j !== -1) {
|
|
1942
|
-
temp[j] = this.
|
|
1943
|
-
tempNodes[j] = this.
|
|
1944
|
-
tempRows && (tempRows[j] = this.
|
|
1945
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
2037
|
+
temp[j] = this.i[i];
|
|
2038
|
+
tempNodes[j] = this.d[i];
|
|
2039
|
+
tempRows && (tempRows[j] = this.p[i]);
|
|
2040
|
+
tempIndexes && (tempIndexes[j] = this.q[i]);
|
|
1946
2041
|
j = newIndicesNext[j];
|
|
1947
2042
|
newIndices.set(key, j);
|
|
1948
2043
|
} else
|
|
1949
|
-
this.
|
|
2044
|
+
this.d[i].dispose();
|
|
1950
2045
|
}
|
|
1951
2046
|
for (j = start; j < newLen; j++) {
|
|
1952
2047
|
if (j in temp) {
|
|
1953
|
-
this.
|
|
1954
|
-
this.
|
|
2048
|
+
this.i[j] = temp[j];
|
|
2049
|
+
this.d[j] = tempNodes[j];
|
|
1955
2050
|
if (tempRows) {
|
|
1956
|
-
this.
|
|
1957
|
-
this.
|
|
2051
|
+
this.p[j] = tempRows[j];
|
|
2052
|
+
this.p[j].write(newItems[j]);
|
|
1958
2053
|
}
|
|
1959
2054
|
if (tempIndexes) {
|
|
1960
|
-
this.
|
|
1961
|
-
this.
|
|
2055
|
+
this.q[j] = tempIndexes[j];
|
|
2056
|
+
this.q[j].write(j);
|
|
1962
2057
|
}
|
|
1963
2058
|
} else {
|
|
1964
|
-
this.
|
|
2059
|
+
this.i[j] = compute(this.d[j] = new Owner(), mapper, null);
|
|
1965
2060
|
}
|
|
1966
2061
|
}
|
|
1967
|
-
this.
|
|
1968
|
-
this.
|
|
2062
|
+
this.i = this.i.slice(0, this.o = newLen);
|
|
2063
|
+
this.D = newItems.slice(0);
|
|
1969
2064
|
}
|
|
1970
2065
|
});
|
|
1971
|
-
return this.
|
|
2066
|
+
return this.i;
|
|
1972
2067
|
}
|
|
1973
2068
|
function repeat(count, map, options) {
|
|
1974
2069
|
return updateRepeat.bind({
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2070
|
+
S: new Owner(),
|
|
2071
|
+
o: 0,
|
|
2072
|
+
y: 0,
|
|
2073
|
+
ia: count,
|
|
2074
|
+
P: map,
|
|
2075
|
+
d: [],
|
|
2076
|
+
i: [],
|
|
2077
|
+
ja: options?.from,
|
|
2078
|
+
T: options?.fallback
|
|
1984
2079
|
});
|
|
1985
2080
|
}
|
|
1986
2081
|
function updateRepeat() {
|
|
1987
|
-
const newLen = this.
|
|
1988
|
-
const from = this.
|
|
1989
|
-
runWithOwner(this.
|
|
2082
|
+
const newLen = this.ia();
|
|
2083
|
+
const from = this.ja?.() || 0;
|
|
2084
|
+
runWithOwner(this.S, () => {
|
|
1990
2085
|
if (newLen === 0) {
|
|
1991
|
-
if (this.
|
|
1992
|
-
this.
|
|
1993
|
-
this.
|
|
1994
|
-
this.
|
|
1995
|
-
this.
|
|
2086
|
+
if (this.o !== 0) {
|
|
2087
|
+
this.S.dispose(false);
|
|
2088
|
+
this.d = [];
|
|
2089
|
+
this.i = [];
|
|
2090
|
+
this.o = 0;
|
|
1996
2091
|
}
|
|
1997
|
-
if (this.
|
|
1998
|
-
this.
|
|
1999
|
-
this.
|
|
2000
|
-
this.
|
|
2092
|
+
if (this.T && !this.i[0]) {
|
|
2093
|
+
this.i[0] = compute(
|
|
2094
|
+
this.d[0] = new Owner(),
|
|
2095
|
+
this.T,
|
|
2001
2096
|
null
|
|
2002
2097
|
);
|
|
2003
2098
|
}
|
|
2004
2099
|
return;
|
|
2005
2100
|
}
|
|
2006
2101
|
const to = from + newLen;
|
|
2007
|
-
const prevTo = this.
|
|
2008
|
-
if (this.
|
|
2009
|
-
this.
|
|
2102
|
+
const prevTo = this.y + this.o;
|
|
2103
|
+
if (this.o === 0 && this.d[0])
|
|
2104
|
+
this.d[0].dispose();
|
|
2010
2105
|
for (let i = to; i < prevTo; i++)
|
|
2011
|
-
this.
|
|
2012
|
-
if (this.
|
|
2013
|
-
let i = this.
|
|
2014
|
-
while (i < from && i < this.
|
|
2015
|
-
this.
|
|
2016
|
-
this.
|
|
2017
|
-
this.
|
|
2018
|
-
} else if (this.
|
|
2019
|
-
let i = prevTo - this.
|
|
2020
|
-
let difference = this.
|
|
2021
|
-
this.
|
|
2106
|
+
this.d[i - this.y].dispose();
|
|
2107
|
+
if (this.y < from) {
|
|
2108
|
+
let i = this.y;
|
|
2109
|
+
while (i < from && i < this.o)
|
|
2110
|
+
this.d[i++].dispose();
|
|
2111
|
+
this.d.splice(0, from - this.y);
|
|
2112
|
+
this.i.splice(0, from - this.y);
|
|
2113
|
+
} else if (this.y > from) {
|
|
2114
|
+
let i = prevTo - this.y - 1;
|
|
2115
|
+
let difference = this.y - from;
|
|
2116
|
+
this.d.length = this.i.length = newLen;
|
|
2022
2117
|
while (i >= difference) {
|
|
2023
|
-
this.
|
|
2024
|
-
this.
|
|
2118
|
+
this.d[i] = this.d[i - difference];
|
|
2119
|
+
this.i[i] = this.i[i - difference];
|
|
2025
2120
|
i--;
|
|
2026
2121
|
}
|
|
2027
2122
|
for (let i2 = 0; i2 < difference; i2++) {
|
|
2028
|
-
this.
|
|
2029
|
-
this.
|
|
2030
|
-
() => this.
|
|
2123
|
+
this.i[i2] = compute(
|
|
2124
|
+
this.d[i2] = new Owner(),
|
|
2125
|
+
() => this.P(i2 + from),
|
|
2031
2126
|
null
|
|
2032
2127
|
);
|
|
2033
2128
|
}
|
|
2034
2129
|
}
|
|
2035
2130
|
for (let i = prevTo; i < to; i++) {
|
|
2036
|
-
this.
|
|
2037
|
-
this.
|
|
2038
|
-
() => this.
|
|
2131
|
+
this.i[i - from] = compute(
|
|
2132
|
+
this.d[i - from] = new Owner(),
|
|
2133
|
+
() => this.P(i),
|
|
2039
2134
|
null
|
|
2040
2135
|
);
|
|
2041
2136
|
}
|
|
2042
|
-
this.
|
|
2043
|
-
this.
|
|
2044
|
-
this.
|
|
2137
|
+
this.i = this.i.slice(0, newLen);
|
|
2138
|
+
this.y = from;
|
|
2139
|
+
this.o = newLen;
|
|
2045
2140
|
});
|
|
2046
|
-
return this.
|
|
2141
|
+
return this.i;
|
|
2047
2142
|
}
|
|
2048
2143
|
function compare(key, a, b) {
|
|
2049
2144
|
return key ? key(a) === key(b) : true;
|
|
@@ -2051,24 +2146,24 @@ function compare(key, a, b) {
|
|
|
2051
2146
|
|
|
2052
2147
|
// src/boundaries.ts
|
|
2053
2148
|
var BoundaryComputation = class extends EagerComputation {
|
|
2054
|
-
|
|
2149
|
+
U;
|
|
2055
2150
|
constructor(compute2, propagationMask) {
|
|
2056
2151
|
super(void 0, compute2, { defer: true });
|
|
2057
|
-
this.
|
|
2152
|
+
this.U = propagationMask;
|
|
2058
2153
|
}
|
|
2059
2154
|
write(value, flags) {
|
|
2060
|
-
super.write(value, flags & ~this.
|
|
2061
|
-
if (this.
|
|
2155
|
+
super.write(value, flags & ~this.U);
|
|
2156
|
+
if (this.U & LOADING_BIT && !(this.h & UNINITIALIZED_BIT)) {
|
|
2062
2157
|
flags &= ~LOADING_BIT;
|
|
2063
2158
|
}
|
|
2064
|
-
this.
|
|
2065
|
-
return this.
|
|
2159
|
+
this.l.notify(this, this.U, flags);
|
|
2160
|
+
return this.j;
|
|
2066
2161
|
}
|
|
2067
2162
|
};
|
|
2068
2163
|
function createBoundChildren(owner, fn, queue, mask) {
|
|
2069
|
-
const parentQueue = owner.
|
|
2070
|
-
parentQueue.addChild(owner.
|
|
2071
|
-
onCleanup(() => parentQueue.removeChild(owner.
|
|
2164
|
+
const parentQueue = owner.l;
|
|
2165
|
+
parentQueue.addChild(owner.l = queue);
|
|
2166
|
+
onCleanup(() => parentQueue.removeChild(owner.l));
|
|
2072
2167
|
return compute(
|
|
2073
2168
|
owner,
|
|
2074
2169
|
() => {
|
|
@@ -2079,66 +2174,79 @@ function createBoundChildren(owner, fn, queue, mask) {
|
|
|
2079
2174
|
);
|
|
2080
2175
|
}
|
|
2081
2176
|
var ConditionalQueue = class extends Queue {
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2177
|
+
t;
|
|
2178
|
+
V = /* @__PURE__ */ new Set();
|
|
2179
|
+
s = /* @__PURE__ */ new Set();
|
|
2085
2180
|
constructor(disabled) {
|
|
2086
2181
|
super();
|
|
2087
|
-
this.
|
|
2182
|
+
this.t = disabled;
|
|
2088
2183
|
}
|
|
2089
2184
|
run(type) {
|
|
2090
|
-
if (!type || this.
|
|
2185
|
+
if (!type || this.t.read())
|
|
2091
2186
|
return;
|
|
2092
2187
|
return super.run(type);
|
|
2093
2188
|
}
|
|
2094
2189
|
notify(node, type, flags) {
|
|
2095
|
-
if (
|
|
2190
|
+
if (ActiveTransition && ActiveTransition.u.has(this))
|
|
2191
|
+
return ActiveTransition.u.get(this).notify(node, type, flags);
|
|
2192
|
+
if (this.t.read()) {
|
|
2096
2193
|
if (type & LOADING_BIT) {
|
|
2097
2194
|
if (flags & LOADING_BIT) {
|
|
2098
|
-
this.
|
|
2195
|
+
this.s.add(node);
|
|
2099
2196
|
type &= ~LOADING_BIT;
|
|
2100
|
-
} else if (this.
|
|
2197
|
+
} else if (this.s.delete(node))
|
|
2101
2198
|
type &= ~LOADING_BIT;
|
|
2102
2199
|
}
|
|
2103
2200
|
if (type & ERROR_BIT) {
|
|
2104
2201
|
if (flags & ERROR_BIT) {
|
|
2105
|
-
this.
|
|
2202
|
+
this.V.add(node);
|
|
2106
2203
|
type &= ~ERROR_BIT;
|
|
2107
|
-
} else if (this.
|
|
2204
|
+
} else if (this.V.delete(node))
|
|
2108
2205
|
type &= ~ERROR_BIT;
|
|
2109
2206
|
}
|
|
2110
2207
|
}
|
|
2111
2208
|
return type ? super.notify(node, type, flags) : true;
|
|
2112
2209
|
}
|
|
2210
|
+
merge(queue) {
|
|
2211
|
+
queue.s.forEach((n) => this.notify(n, LOADING_BIT, LOADING_BIT));
|
|
2212
|
+
queue.V.forEach((n) => this.notify(n, ERROR_BIT, ERROR_BIT));
|
|
2213
|
+
super.merge(queue);
|
|
2214
|
+
}
|
|
2113
2215
|
};
|
|
2114
2216
|
var CollectionQueue = class extends Queue {
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2217
|
+
F;
|
|
2218
|
+
d = /* @__PURE__ */ new Set();
|
|
2219
|
+
t = new Computation(false, null, { pureWrite: true });
|
|
2118
2220
|
constructor(type) {
|
|
2119
2221
|
super();
|
|
2120
|
-
this.
|
|
2222
|
+
this.F = type;
|
|
2121
2223
|
}
|
|
2122
2224
|
run(type) {
|
|
2123
|
-
if (!type || this.
|
|
2225
|
+
if (!type || this.t.read())
|
|
2124
2226
|
return;
|
|
2125
2227
|
return super.run(type);
|
|
2126
2228
|
}
|
|
2127
2229
|
notify(node, type, flags) {
|
|
2128
|
-
if (
|
|
2230
|
+
if (ActiveTransition && ActiveTransition.u.has(this))
|
|
2231
|
+
return ActiveTransition.u.get(this).notify(node, type, flags);
|
|
2232
|
+
if (!(type & this.F))
|
|
2129
2233
|
return super.notify(node, type, flags);
|
|
2130
|
-
if (flags & this.
|
|
2131
|
-
this.
|
|
2132
|
-
if (this.
|
|
2133
|
-
this.
|
|
2234
|
+
if (flags & this.F) {
|
|
2235
|
+
this.d.add(node);
|
|
2236
|
+
if (this.d.size === 1)
|
|
2237
|
+
this.t.write(true);
|
|
2134
2238
|
} else {
|
|
2135
|
-
this.
|
|
2136
|
-
if (this.
|
|
2137
|
-
this.
|
|
2239
|
+
this.d.delete(node);
|
|
2240
|
+
if (this.d.size === 0)
|
|
2241
|
+
this.t.write(false);
|
|
2138
2242
|
}
|
|
2139
|
-
type &= ~this.
|
|
2243
|
+
type &= ~this.F;
|
|
2140
2244
|
return type ? super.notify(node, type, flags) : true;
|
|
2141
2245
|
}
|
|
2246
|
+
merge(queue) {
|
|
2247
|
+
queue.d.forEach((n) => this.notify(n, this.F, this.F));
|
|
2248
|
+
super.merge(queue);
|
|
2249
|
+
}
|
|
2142
2250
|
};
|
|
2143
2251
|
function createBoundary(fn, condition) {
|
|
2144
2252
|
const owner = new Owner();
|
|
@@ -2147,25 +2255,25 @@ function createBoundary(fn, condition) {
|
|
|
2147
2255
|
);
|
|
2148
2256
|
const tree = createBoundChildren(owner, fn, queue, 0);
|
|
2149
2257
|
new EagerComputation(void 0, () => {
|
|
2150
|
-
const disabled = queue.
|
|
2151
|
-
tree.
|
|
2258
|
+
const disabled = queue.t.read();
|
|
2259
|
+
tree.U = disabled ? ERROR_BIT | LOADING_BIT : 0;
|
|
2152
2260
|
if (!disabled) {
|
|
2153
|
-
queue.
|
|
2154
|
-
queue.
|
|
2155
|
-
queue.
|
|
2156
|
-
queue.
|
|
2261
|
+
queue.s.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
|
|
2262
|
+
queue.V.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
|
|
2263
|
+
queue.s.clear();
|
|
2264
|
+
queue.V.clear();
|
|
2157
2265
|
}
|
|
2158
2266
|
});
|
|
2159
|
-
return () => queue.
|
|
2267
|
+
return () => queue.t.read() ? void 0 : tree.read();
|
|
2160
2268
|
}
|
|
2161
2269
|
function createCollectionBoundary(type, fn, fallback) {
|
|
2162
2270
|
const owner = new Owner();
|
|
2163
2271
|
const queue = new CollectionQueue(type);
|
|
2164
2272
|
const tree = createBoundChildren(owner, fn, queue, type);
|
|
2165
2273
|
const decision = new Computation(void 0, () => {
|
|
2166
|
-
if (!queue.
|
|
2274
|
+
if (!queue.t.read()) {
|
|
2167
2275
|
const resolved = tree.read();
|
|
2168
|
-
if (!queue.
|
|
2276
|
+
if (!queue.t.read())
|
|
2169
2277
|
return resolved;
|
|
2170
2278
|
}
|
|
2171
2279
|
return fallback(queue);
|
|
@@ -2176,17 +2284,19 @@ function createSuspense(fn, fallback) {
|
|
|
2176
2284
|
return createCollectionBoundary(LOADING_BIT, fn, () => fallback());
|
|
2177
2285
|
}
|
|
2178
2286
|
function createErrorBoundary(fn, fallback) {
|
|
2179
|
-
return createCollectionBoundary(
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2287
|
+
return createCollectionBoundary(ERROR_BIT, fn, (queue) => {
|
|
2288
|
+
let node = queue.d.values().next().value;
|
|
2289
|
+
ActiveTransition && ActiveTransition.a.has(node) && (node = ActiveTransition.a.get(node));
|
|
2290
|
+
return fallback(node.K, () => {
|
|
2183
2291
|
incrementClock();
|
|
2184
|
-
for (let
|
|
2185
|
-
|
|
2186
|
-
|
|
2292
|
+
for (let node2 of queue.d) {
|
|
2293
|
+
if (ActiveTransition && !node2.g)
|
|
2294
|
+
node2 = cloneGraph(node2);
|
|
2295
|
+
node2.c = STATE_DIRTY;
|
|
2296
|
+
node2.l?.enqueue(node2.A, node2.C.bind(node2));
|
|
2187
2297
|
}
|
|
2188
|
-
})
|
|
2189
|
-
);
|
|
2298
|
+
});
|
|
2299
|
+
});
|
|
2190
2300
|
}
|
|
2191
2301
|
function flatten(children, options) {
|
|
2192
2302
|
if (typeof children === "function" && !children.length) {
|