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