ccstate 4.1.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/core/index.cjs +595 -801
- package/core/index.cjs.map +1 -1
- package/core/index.d.cts +10 -5
- package/core/index.d.ts +10 -5
- package/core/index.js +595 -801
- package/core/index.js.map +1 -1
- package/debug/index.cjs +633 -792
- package/debug/index.cjs.map +1 -1
- package/debug/index.d.cts +16 -5
- package/debug/index.d.ts +16 -5
- package/debug/index.js +633 -792
- package/debug/index.js.map +1 -1
- package/index.cjs +644 -800
- package/index.cjs.map +1 -1
- package/index.d.cts +17 -5
- package/index.d.ts +17 -5
- package/index.js +644 -800
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var globalId = 0;
|
|
4
|
-
var generateToString = function generateToString(prefix, debugLabel) {
|
|
5
|
-
var id = globalId++;
|
|
4
|
+
var generateToString = function generateToString(id, prefix, debugLabel) {
|
|
6
5
|
var label = "".concat(prefix).concat(String(id)).concat(debugLabel ? ':' + debugLabel : '');
|
|
7
6
|
return function () {
|
|
8
7
|
return label;
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
10
|
function state(init, options) {
|
|
11
|
+
var id = globalId++;
|
|
12
12
|
var ret = {
|
|
13
|
+
id: id,
|
|
13
14
|
init: init,
|
|
14
|
-
toString: generateToString('
|
|
15
|
+
toString: generateToString(id, 'S', options === null || options === void 0 ? void 0 : options.debugLabel)
|
|
15
16
|
};
|
|
16
17
|
if (options !== null && options !== void 0 && options.debugLabel) {
|
|
17
18
|
ret.debugLabel = options.debugLabel;
|
|
@@ -19,9 +20,11 @@ function state(init, options) {
|
|
|
19
20
|
return ret;
|
|
20
21
|
}
|
|
21
22
|
function computed(read, options) {
|
|
23
|
+
var id = globalId++;
|
|
22
24
|
var ret = {
|
|
25
|
+
id: id,
|
|
23
26
|
read: read,
|
|
24
|
-
toString: generateToString('
|
|
27
|
+
toString: generateToString(id, 'CPT', options === null || options === void 0 ? void 0 : options.debugLabel)
|
|
25
28
|
};
|
|
26
29
|
if (options !== null && options !== void 0 && options.debugLabel) {
|
|
27
30
|
ret.debugLabel = options.debugLabel;
|
|
@@ -29,9 +32,11 @@ function computed(read, options) {
|
|
|
29
32
|
return ret;
|
|
30
33
|
}
|
|
31
34
|
function command(write, options) {
|
|
35
|
+
var id = globalId++;
|
|
32
36
|
var ret = {
|
|
37
|
+
id: id,
|
|
33
38
|
write: write,
|
|
34
|
-
toString: generateToString('
|
|
39
|
+
toString: generateToString(id, 'CMD', options === null || options === void 0 ? void 0 : options.debugLabel)
|
|
35
40
|
};
|
|
36
41
|
if (options !== null && options !== void 0 && options.debugLabel) {
|
|
37
42
|
ret.debugLabel = options.debugLabel;
|
|
@@ -202,307 +207,6 @@ function _possibleConstructorReturn(t, e) {
|
|
|
202
207
|
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
203
208
|
return _assertThisInitialized(t);
|
|
204
209
|
}
|
|
205
|
-
function _regeneratorRuntime() {
|
|
206
|
-
_regeneratorRuntime = function () {
|
|
207
|
-
return e;
|
|
208
|
-
};
|
|
209
|
-
var t,
|
|
210
|
-
e = {},
|
|
211
|
-
r = Object.prototype,
|
|
212
|
-
n = r.hasOwnProperty,
|
|
213
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
214
|
-
t[e] = r.value;
|
|
215
|
-
},
|
|
216
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
217
|
-
a = i.iterator || "@@iterator",
|
|
218
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
219
|
-
u = i.toStringTag || "@@toStringTag";
|
|
220
|
-
function define(t, e, r) {
|
|
221
|
-
return Object.defineProperty(t, e, {
|
|
222
|
-
value: r,
|
|
223
|
-
enumerable: !0,
|
|
224
|
-
configurable: !0,
|
|
225
|
-
writable: !0
|
|
226
|
-
}), t[e];
|
|
227
|
-
}
|
|
228
|
-
try {
|
|
229
|
-
define({}, "");
|
|
230
|
-
} catch (t) {
|
|
231
|
-
define = function (t, e, r) {
|
|
232
|
-
return t[e] = r;
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function wrap(t, e, r, n) {
|
|
236
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
237
|
-
a = Object.create(i.prototype),
|
|
238
|
-
c = new Context(n || []);
|
|
239
|
-
return o(a, "_invoke", {
|
|
240
|
-
value: makeInvokeMethod(t, r, c)
|
|
241
|
-
}), a;
|
|
242
|
-
}
|
|
243
|
-
function tryCatch(t, e, r) {
|
|
244
|
-
try {
|
|
245
|
-
return {
|
|
246
|
-
type: "normal",
|
|
247
|
-
arg: t.call(e, r)
|
|
248
|
-
};
|
|
249
|
-
} catch (t) {
|
|
250
|
-
return {
|
|
251
|
-
type: "throw",
|
|
252
|
-
arg: t
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
e.wrap = wrap;
|
|
257
|
-
var h = "suspendedStart",
|
|
258
|
-
l = "suspendedYield",
|
|
259
|
-
f = "executing",
|
|
260
|
-
s = "completed",
|
|
261
|
-
y = {};
|
|
262
|
-
function Generator() {}
|
|
263
|
-
function GeneratorFunction() {}
|
|
264
|
-
function GeneratorFunctionPrototype() {}
|
|
265
|
-
var p = {};
|
|
266
|
-
define(p, a, function () {
|
|
267
|
-
return this;
|
|
268
|
-
});
|
|
269
|
-
var d = Object.getPrototypeOf,
|
|
270
|
-
v = d && d(d(values([])));
|
|
271
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
272
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
273
|
-
function defineIteratorMethods(t) {
|
|
274
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
275
|
-
define(t, e, function (t) {
|
|
276
|
-
return this._invoke(e, t);
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
function AsyncIterator(t, e) {
|
|
281
|
-
function invoke(r, o, i, a) {
|
|
282
|
-
var c = tryCatch(t[r], t, o);
|
|
283
|
-
if ("throw" !== c.type) {
|
|
284
|
-
var u = c.arg,
|
|
285
|
-
h = u.value;
|
|
286
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
287
|
-
invoke("next", t, i, a);
|
|
288
|
-
}, function (t) {
|
|
289
|
-
invoke("throw", t, i, a);
|
|
290
|
-
}) : e.resolve(h).then(function (t) {
|
|
291
|
-
u.value = t, i(u);
|
|
292
|
-
}, function (t) {
|
|
293
|
-
return invoke("throw", t, i, a);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
a(c.arg);
|
|
297
|
-
}
|
|
298
|
-
var r;
|
|
299
|
-
o(this, "_invoke", {
|
|
300
|
-
value: function (t, n) {
|
|
301
|
-
function callInvokeWithMethodAndArg() {
|
|
302
|
-
return new e(function (e, r) {
|
|
303
|
-
invoke(t, n, e, r);
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
function makeInvokeMethod(e, r, n) {
|
|
311
|
-
var o = h;
|
|
312
|
-
return function (i, a) {
|
|
313
|
-
if (o === f) throw Error("Generator is already running");
|
|
314
|
-
if (o === s) {
|
|
315
|
-
if ("throw" === i) throw a;
|
|
316
|
-
return {
|
|
317
|
-
value: t,
|
|
318
|
-
done: !0
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
for (n.method = i, n.arg = a;;) {
|
|
322
|
-
var c = n.delegate;
|
|
323
|
-
if (c) {
|
|
324
|
-
var u = maybeInvokeDelegate(c, n);
|
|
325
|
-
if (u) {
|
|
326
|
-
if (u === y) continue;
|
|
327
|
-
return u;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
331
|
-
if (o === h) throw o = s, n.arg;
|
|
332
|
-
n.dispatchException(n.arg);
|
|
333
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
334
|
-
o = f;
|
|
335
|
-
var p = tryCatch(e, r, n);
|
|
336
|
-
if ("normal" === p.type) {
|
|
337
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
338
|
-
return {
|
|
339
|
-
value: p.arg,
|
|
340
|
-
done: n.done
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
function maybeInvokeDelegate(e, r) {
|
|
348
|
-
var n = r.method,
|
|
349
|
-
o = e.iterator[n];
|
|
350
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
351
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
352
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
353
|
-
var a = i.arg;
|
|
354
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
355
|
-
}
|
|
356
|
-
function pushTryEntry(t) {
|
|
357
|
-
var e = {
|
|
358
|
-
tryLoc: t[0]
|
|
359
|
-
};
|
|
360
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
361
|
-
}
|
|
362
|
-
function resetTryEntry(t) {
|
|
363
|
-
var e = t.completion || {};
|
|
364
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
365
|
-
}
|
|
366
|
-
function Context(t) {
|
|
367
|
-
this.tryEntries = [{
|
|
368
|
-
tryLoc: "root"
|
|
369
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
370
|
-
}
|
|
371
|
-
function values(e) {
|
|
372
|
-
if (e || "" === e) {
|
|
373
|
-
var r = e[a];
|
|
374
|
-
if (r) return r.call(e);
|
|
375
|
-
if ("function" == typeof e.next) return e;
|
|
376
|
-
if (!isNaN(e.length)) {
|
|
377
|
-
var o = -1,
|
|
378
|
-
i = function next() {
|
|
379
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
380
|
-
return next.value = t, next.done = !0, next;
|
|
381
|
-
};
|
|
382
|
-
return i.next = i;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
386
|
-
}
|
|
387
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
388
|
-
value: GeneratorFunctionPrototype,
|
|
389
|
-
configurable: !0
|
|
390
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
391
|
-
value: GeneratorFunction,
|
|
392
|
-
configurable: !0
|
|
393
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
394
|
-
var e = "function" == typeof t && t.constructor;
|
|
395
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
396
|
-
}, e.mark = function (t) {
|
|
397
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
398
|
-
}, e.awrap = function (t) {
|
|
399
|
-
return {
|
|
400
|
-
__await: t
|
|
401
|
-
};
|
|
402
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
403
|
-
return this;
|
|
404
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
405
|
-
void 0 === i && (i = Promise);
|
|
406
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
407
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
408
|
-
return t.done ? t.value : a.next();
|
|
409
|
-
});
|
|
410
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
411
|
-
return this;
|
|
412
|
-
}), define(g, "toString", function () {
|
|
413
|
-
return "[object Generator]";
|
|
414
|
-
}), e.keys = function (t) {
|
|
415
|
-
var e = Object(t),
|
|
416
|
-
r = [];
|
|
417
|
-
for (var n in e) r.push(n);
|
|
418
|
-
return r.reverse(), function next() {
|
|
419
|
-
for (; r.length;) {
|
|
420
|
-
var t = r.pop();
|
|
421
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
422
|
-
}
|
|
423
|
-
return next.done = !0, next;
|
|
424
|
-
};
|
|
425
|
-
}, e.values = values, Context.prototype = {
|
|
426
|
-
constructor: Context,
|
|
427
|
-
reset: function (e) {
|
|
428
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
429
|
-
},
|
|
430
|
-
stop: function () {
|
|
431
|
-
this.done = !0;
|
|
432
|
-
var t = this.tryEntries[0].completion;
|
|
433
|
-
if ("throw" === t.type) throw t.arg;
|
|
434
|
-
return this.rval;
|
|
435
|
-
},
|
|
436
|
-
dispatchException: function (e) {
|
|
437
|
-
if (this.done) throw e;
|
|
438
|
-
var r = this;
|
|
439
|
-
function handle(n, o) {
|
|
440
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
441
|
-
}
|
|
442
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
443
|
-
var i = this.tryEntries[o],
|
|
444
|
-
a = i.completion;
|
|
445
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
446
|
-
if (i.tryLoc <= this.prev) {
|
|
447
|
-
var c = n.call(i, "catchLoc"),
|
|
448
|
-
u = n.call(i, "finallyLoc");
|
|
449
|
-
if (c && u) {
|
|
450
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
451
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
452
|
-
} else if (c) {
|
|
453
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
454
|
-
} else {
|
|
455
|
-
if (!u) throw Error("try statement without catch or finally");
|
|
456
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
abrupt: function (t, e) {
|
|
462
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
463
|
-
var o = this.tryEntries[r];
|
|
464
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
465
|
-
var i = o;
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
470
|
-
var a = i ? i.completion : {};
|
|
471
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
472
|
-
},
|
|
473
|
-
complete: function (t, e) {
|
|
474
|
-
if ("throw" === t.type) throw t.arg;
|
|
475
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
476
|
-
},
|
|
477
|
-
finish: function (t) {
|
|
478
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
479
|
-
var r = this.tryEntries[e];
|
|
480
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
481
|
-
}
|
|
482
|
-
},
|
|
483
|
-
catch: function (t) {
|
|
484
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
485
|
-
var r = this.tryEntries[e];
|
|
486
|
-
if (r.tryLoc === t) {
|
|
487
|
-
var n = r.completion;
|
|
488
|
-
if ("throw" === n.type) {
|
|
489
|
-
var o = n.arg;
|
|
490
|
-
resetTryEntry(r);
|
|
491
|
-
}
|
|
492
|
-
return o;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
throw Error("illegal catch attempt");
|
|
496
|
-
},
|
|
497
|
-
delegateYield: function (e, r, n) {
|
|
498
|
-
return this.delegate = {
|
|
499
|
-
iterator: values(e),
|
|
500
|
-
resultName: r,
|
|
501
|
-
nextLoc: n
|
|
502
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
503
|
-
}
|
|
504
|
-
}, e;
|
|
505
|
-
}
|
|
506
210
|
function _setPrototypeOf(t, e) {
|
|
507
211
|
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
508
212
|
return t.__proto__ = e, t;
|
|
@@ -546,536 +250,638 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
546
250
|
}
|
|
547
251
|
}
|
|
548
252
|
|
|
253
|
+
function withSetInterceptor(fn, writable$, interceptor) {
|
|
254
|
+
if (!interceptor) {
|
|
255
|
+
return fn();
|
|
256
|
+
}
|
|
257
|
+
var result = {
|
|
258
|
+
called: false
|
|
259
|
+
};
|
|
260
|
+
var wrappedFn = function wrappedFn() {
|
|
261
|
+
result = {
|
|
262
|
+
called: true,
|
|
263
|
+
data: fn()
|
|
264
|
+
};
|
|
265
|
+
return result.data;
|
|
266
|
+
};
|
|
267
|
+
for (var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
268
|
+
args[_key - 3] = arguments[_key];
|
|
269
|
+
}
|
|
270
|
+
if ('write' in writable$) {
|
|
271
|
+
interceptor.apply(void 0, [writable$, wrappedFn].concat(args));
|
|
272
|
+
} else {
|
|
273
|
+
interceptor(writable$, wrappedFn, args[0]);
|
|
274
|
+
}
|
|
275
|
+
if (!result.called) {
|
|
276
|
+
throw new Error('interceptor must call fn sync');
|
|
277
|
+
}
|
|
278
|
+
return result.data;
|
|
279
|
+
}
|
|
280
|
+
function withGetInterceptor(fn, signal, interceptor) {
|
|
281
|
+
if (!interceptor) {
|
|
282
|
+
return fn();
|
|
283
|
+
}
|
|
284
|
+
var result = {
|
|
285
|
+
called: false
|
|
286
|
+
};
|
|
287
|
+
interceptor(signal, function () {
|
|
288
|
+
result = {
|
|
289
|
+
called: true,
|
|
290
|
+
data: fn()
|
|
291
|
+
};
|
|
292
|
+
return result.data;
|
|
293
|
+
});
|
|
294
|
+
if (!result.called) {
|
|
295
|
+
throw new Error('interceptor must call fn sync');
|
|
296
|
+
}
|
|
297
|
+
return result.data;
|
|
298
|
+
}
|
|
299
|
+
function withComputedInterceptor(fn, signal, interceptor) {
|
|
300
|
+
if (!interceptor) {
|
|
301
|
+
return fn();
|
|
302
|
+
}
|
|
303
|
+
var result = {
|
|
304
|
+
called: false
|
|
305
|
+
};
|
|
306
|
+
interceptor(signal, function () {
|
|
307
|
+
result = {
|
|
308
|
+
called: true,
|
|
309
|
+
data: fn()
|
|
310
|
+
};
|
|
311
|
+
return result.data.val;
|
|
312
|
+
});
|
|
313
|
+
if (!result.called) {
|
|
314
|
+
throw new Error('interceptor must call fn sync');
|
|
315
|
+
}
|
|
316
|
+
return result.data;
|
|
317
|
+
}
|
|
318
|
+
function withGeValInterceptor(fn, signal, interceptor) {
|
|
319
|
+
if (!interceptor) {
|
|
320
|
+
return fn();
|
|
321
|
+
}
|
|
322
|
+
var result = {
|
|
323
|
+
called: false
|
|
324
|
+
};
|
|
325
|
+
interceptor(signal, function () {
|
|
326
|
+
result = {
|
|
327
|
+
called: true,
|
|
328
|
+
data: fn()
|
|
329
|
+
};
|
|
330
|
+
return result.data;
|
|
331
|
+
});
|
|
332
|
+
if (!result.called) {
|
|
333
|
+
throw new Error('interceptor must call fn sync');
|
|
334
|
+
}
|
|
335
|
+
return result.data;
|
|
336
|
+
}
|
|
337
|
+
function withSubInterceptor(fn, signal, callback$, interceptor) {
|
|
338
|
+
if (!interceptor) {
|
|
339
|
+
fn();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
var result = {
|
|
343
|
+
called: false
|
|
344
|
+
};
|
|
345
|
+
interceptor(signal, callback$, function () {
|
|
346
|
+
result = {
|
|
347
|
+
called: true,
|
|
348
|
+
data: undefined
|
|
349
|
+
};
|
|
350
|
+
fn();
|
|
351
|
+
});
|
|
352
|
+
if (!result.called) {
|
|
353
|
+
throw new Error('interceptor must call fn sync');
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function withUnsubInterceptor(fn, signal, callback$, interceptor) {
|
|
357
|
+
if (!interceptor) {
|
|
358
|
+
fn();
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
var result = {
|
|
362
|
+
called: false
|
|
363
|
+
};
|
|
364
|
+
interceptor(signal, callback$, function () {
|
|
365
|
+
result = {
|
|
366
|
+
called: true,
|
|
367
|
+
data: undefined
|
|
368
|
+
};
|
|
369
|
+
fn();
|
|
370
|
+
});
|
|
371
|
+
if (!result.called) {
|
|
372
|
+
throw new Error('interceptor must call fn sync');
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function withNotifyInterceptor(fn, callback$, interceptor) {
|
|
376
|
+
if (!interceptor) {
|
|
377
|
+
return fn();
|
|
378
|
+
}
|
|
379
|
+
var result = {
|
|
380
|
+
called: false
|
|
381
|
+
};
|
|
382
|
+
interceptor(callback$, function () {
|
|
383
|
+
result = {
|
|
384
|
+
called: true,
|
|
385
|
+
data: fn()
|
|
386
|
+
};
|
|
387
|
+
return result.data;
|
|
388
|
+
});
|
|
389
|
+
if (!result.called) {
|
|
390
|
+
throw new Error('interceptor must call fn sync');
|
|
391
|
+
}
|
|
392
|
+
return result.data;
|
|
393
|
+
}
|
|
394
|
+
|
|
549
395
|
function canReadAsCompute(atom) {
|
|
550
396
|
return 'read' in atom;
|
|
551
397
|
}
|
|
552
398
|
function isComputedState(state) {
|
|
553
399
|
return 'dependencies' in state;
|
|
554
400
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (depState.epoch !== epoch) {
|
|
577
|
-
return undefined;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
} catch (err) {
|
|
581
|
-
_iterator.e(err);
|
|
582
|
-
} finally {
|
|
583
|
-
_iterator.f();
|
|
401
|
+
|
|
402
|
+
function currentValue(signal, context) {
|
|
403
|
+
var _context$stateMap$get;
|
|
404
|
+
return (_context$stateMap$get = context.stateMap.get(signal)) === null || _context$stateMap$get === void 0 ? void 0 : _context$stateMap$get.val;
|
|
405
|
+
}
|
|
406
|
+
function shouldDistinct(signal, value, context) {
|
|
407
|
+
return currentValue(signal, context) === value;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function checkEpoch(readComputed, computedState, context, mutation) {
|
|
411
|
+
var _iterator = _createForOfIteratorHelper(computedState.dependencies.entries()),
|
|
412
|
+
_step;
|
|
413
|
+
try {
|
|
414
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
415
|
+
var _context$stateMap$get;
|
|
416
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
417
|
+
dep = _step$value[0],
|
|
418
|
+
epoch = _step$value[1];
|
|
419
|
+
var depEpoch = canReadAsCompute(dep) ? readComputed(dep, context, mutation).epoch : (_context$stateMap$get = context.stateMap.get(dep)) === null || _context$stateMap$get === void 0 ? void 0 : _context$stateMap$get.epoch;
|
|
420
|
+
if (depEpoch !== epoch) {
|
|
421
|
+
return false;
|
|
584
422
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
423
|
+
}
|
|
424
|
+
} catch (err) {
|
|
425
|
+
_iterator.e(err);
|
|
426
|
+
} finally {
|
|
427
|
+
_iterator.f();
|
|
588
428
|
}
|
|
589
|
-
return
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
function tryGetCached(readComputed, computed$, context, mutation) {
|
|
432
|
+
var signalState = context.stateMap.get(computed$);
|
|
433
|
+
if (!signalState) {
|
|
434
|
+
return undefined;
|
|
435
|
+
}
|
|
436
|
+
if (mutation !== null && mutation !== void 0 && mutation.dirtyMarkers.has(computed$.id)) {
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
if (signalState.mounted) {
|
|
440
|
+
return signalState;
|
|
441
|
+
}
|
|
442
|
+
if (checkEpoch(readComputed, signalState, context, mutation)) {
|
|
443
|
+
return signalState;
|
|
444
|
+
}
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
function wrapGet(readSignal, mount, callerComputed$, callerState, context, mutation) {
|
|
448
|
+
var readDeps = new Map();
|
|
449
|
+
return [function (dep$) {
|
|
450
|
+
var depState = readSignal(dep$, context, mutation);
|
|
451
|
+
if (callerState.dependencies === readDeps) {
|
|
452
|
+
readDeps.set(dep$, depState.epoch);
|
|
453
|
+
var callerMounted = !!callerState.mounted;
|
|
454
|
+
if (callerMounted && !depState.mounted) {
|
|
455
|
+
mount(dep$, context, mutation).readDepts.add(callerComputed$);
|
|
456
|
+
} else if (callerMounted && depState.mounted) {
|
|
457
|
+
depState.mounted.readDepts.add(callerComputed$);
|
|
602
458
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
459
|
+
}
|
|
460
|
+
return depState.val;
|
|
461
|
+
}, readDeps];
|
|
462
|
+
}
|
|
463
|
+
function getOrInitComputedState(computed$, context) {
|
|
464
|
+
var computedState = context.stateMap.get(computed$);
|
|
465
|
+
if (!computedState) {
|
|
466
|
+
computedState = {
|
|
467
|
+
dependencies: new Map(),
|
|
468
|
+
epoch: -1
|
|
469
|
+
};
|
|
470
|
+
context.stateMap.set(computed$, computedState);
|
|
471
|
+
}
|
|
472
|
+
return computedState;
|
|
473
|
+
}
|
|
474
|
+
function cleanupMissingDependencies(unmount, computed$, lastDeps, currDeps, context, mutation) {
|
|
475
|
+
var _iterator2 = _createForOfIteratorHelper(lastDeps.keys()),
|
|
476
|
+
_step2;
|
|
477
|
+
try {
|
|
478
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
479
|
+
var key = _step2.value;
|
|
480
|
+
if (!currDeps.has(key)) {
|
|
481
|
+
var _depState$mounted;
|
|
482
|
+
var depState = context.stateMap.get(key);
|
|
483
|
+
depState === null || depState === void 0 || (_depState$mounted = depState.mounted) === null || _depState$mounted === void 0 || _depState$mounted.readDepts["delete"](computed$);
|
|
484
|
+
unmount(key, context, mutation);
|
|
615
485
|
}
|
|
616
|
-
return result.data;
|
|
617
486
|
}
|
|
487
|
+
} catch (err) {
|
|
488
|
+
_iterator2.e(err);
|
|
489
|
+
} finally {
|
|
490
|
+
_iterator2.f();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
function evaluateComputed(readSignal, mount, unmount, computed$, context, mutation) {
|
|
494
|
+
var computedState = getOrInitComputedState(computed$, context);
|
|
495
|
+
var lastDeps = computedState.dependencies;
|
|
496
|
+
var _wrapGet = wrapGet(readSignal, mount, computed$, computedState, context, mutation),
|
|
497
|
+
_wrapGet2 = _slicedToArray(_wrapGet, 2),
|
|
498
|
+
_get = _wrapGet2[0],
|
|
499
|
+
dependencies = _wrapGet2[1];
|
|
500
|
+
computedState.dependencies = dependencies;
|
|
501
|
+
var evalVal = computed$.read(function (depAtom) {
|
|
502
|
+
var _context$interceptor;
|
|
503
|
+
return withGeValInterceptor(function () {
|
|
504
|
+
return _get(depAtom);
|
|
505
|
+
}, depAtom, (_context$interceptor = context.interceptor) === null || _context$interceptor === void 0 ? void 0 : _context$interceptor.get);
|
|
618
506
|
}, {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
var lastDeps = atomState.dependencies;
|
|
634
|
-
var readDeps = new Map();
|
|
635
|
-
atomState.dependencies = readDeps;
|
|
636
|
-
var wrappedGet = function wrappedGet(depAtom) {
|
|
637
|
-
var depState = _this3.readAtomState(depAtom, ignoreMounted);
|
|
507
|
+
get signal() {
|
|
508
|
+
var _computedState$abortC, _computed$$debugLabel;
|
|
509
|
+
(_computedState$abortC = computedState.abortController) === null || _computedState$abortC === void 0 || _computedState$abortC.abort("abort ".concat((_computed$$debugLabel = computed$.debugLabel) !== null && _computed$$debugLabel !== void 0 ? _computed$$debugLabel : 'anonymous', " atom"));
|
|
510
|
+
computedState.abortController = new AbortController();
|
|
511
|
+
return computedState.abortController.signal;
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
cleanupMissingDependencies(unmount, computed$, lastDeps, dependencies, context, mutation);
|
|
515
|
+
if (!shouldDistinct(computed$, evalVal, context)) {
|
|
516
|
+
computedState.val = evalVal;
|
|
517
|
+
computedState.epoch += 1;
|
|
518
|
+
}
|
|
519
|
+
return computedState;
|
|
520
|
+
}
|
|
638
521
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
522
|
+
function pushDirtyMarkers(signalState, context, mutation) {
|
|
523
|
+
var _signalState$mounted$, _signalState$mounted;
|
|
524
|
+
var queue = Array.from((_signalState$mounted$ = (_signalState$mounted = signalState.mounted) === null || _signalState$mounted === void 0 ? void 0 : _signalState$mounted.readDepts) !== null && _signalState$mounted$ !== void 0 ? _signalState$mounted$ : []);
|
|
525
|
+
while (queue.length > 0) {
|
|
526
|
+
var nextQueue = [];
|
|
527
|
+
var _iterator = _createForOfIteratorHelper(queue),
|
|
528
|
+
_step;
|
|
529
|
+
try {
|
|
530
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
531
|
+
var computed$ = _step.value;
|
|
532
|
+
mutation.dirtyMarkers.add(computed$.id);
|
|
533
|
+
var computedState = context.stateMap.get(computed$);
|
|
534
|
+
// This computed$ is read from other computed$'s readDepts, so it must not be null and must have mounted
|
|
535
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
536
|
+
var _iterator2 = _createForOfIteratorHelper(computedState.mounted.readDepts),
|
|
537
|
+
_step2;
|
|
538
|
+
try {
|
|
539
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
540
|
+
var dep = _step2.value;
|
|
541
|
+
nextQueue.push(dep);
|
|
647
542
|
}
|
|
543
|
+
} catch (err) {
|
|
544
|
+
_iterator2.e(err);
|
|
545
|
+
} finally {
|
|
546
|
+
_iterator2.f();
|
|
648
547
|
}
|
|
649
|
-
return depState.val;
|
|
650
|
-
};
|
|
651
|
-
var getInterceptor = (_this$options2 = this.options) === null || _this$options2 === void 0 || (_this$options2 = _this$options2.interceptor) === null || _this$options2 === void 0 ? void 0 : _this$options2.get;
|
|
652
|
-
var ret = self.read(function (depAtom) {
|
|
653
|
-
if (!getInterceptor) {
|
|
654
|
-
return wrappedGet(depAtom);
|
|
655
|
-
}
|
|
656
|
-
var result = {
|
|
657
|
-
called: false
|
|
658
|
-
};
|
|
659
|
-
var fn = function fn() {
|
|
660
|
-
result = {
|
|
661
|
-
called: true,
|
|
662
|
-
data: wrappedGet(depAtom)
|
|
663
|
-
};
|
|
664
|
-
return result.data;
|
|
665
|
-
};
|
|
666
|
-
getInterceptor(depAtom, fn);
|
|
667
|
-
if (!result.called) {
|
|
668
|
-
throw new Error('interceptor must call fn sync');
|
|
669
|
-
}
|
|
670
|
-
return result.data;
|
|
671
|
-
}, {
|
|
672
|
-
get signal() {
|
|
673
|
-
var _atomState$abortContr, _self$debugLabel;
|
|
674
|
-
(_atomState$abortContr = atomState.abortController) === null || _atomState$abortContr === void 0 || _atomState$abortContr.abort("abort ".concat((_self$debugLabel = self.debugLabel) !== null && _self$debugLabel !== void 0 ? _self$debugLabel : 'anonymous', " atom"));
|
|
675
|
-
atomState.abortController = new AbortController();
|
|
676
|
-
return atomState.abortController.signal;
|
|
677
|
-
}
|
|
678
|
-
});
|
|
679
|
-
if (atomState.val !== ret) {
|
|
680
|
-
atomState.val = ret;
|
|
681
|
-
atomState.epoch += 1;
|
|
682
548
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
549
|
+
} catch (err) {
|
|
550
|
+
_iterator.e(err);
|
|
551
|
+
} finally {
|
|
552
|
+
_iterator.f();
|
|
553
|
+
}
|
|
554
|
+
queue = nextQueue;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
558
|
+
var _signalState$mounted$2, _signalState$mounted2, _signalState$mounted$3, _signalState$mounted3;
|
|
559
|
+
var queue = Array.from((_signalState$mounted$2 = (_signalState$mounted2 = signalState.mounted) === null || _signalState$mounted2 === void 0 ? void 0 : _signalState$mounted2.readDepts) !== null && _signalState$mounted$2 !== void 0 ? _signalState$mounted$2 : []);
|
|
560
|
+
var _iterator3 = _createForOfIteratorHelper((_signalState$mounted$3 = (_signalState$mounted3 = signalState.mounted) === null || _signalState$mounted3 === void 0 ? void 0 : _signalState$mounted3.listeners) !== null && _signalState$mounted$3 !== void 0 ? _signalState$mounted$3 : []),
|
|
561
|
+
_step3;
|
|
562
|
+
try {
|
|
563
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
564
|
+
var _listener = _step3.value;
|
|
565
|
+
mutation.pendingListeners.add(_listener);
|
|
566
|
+
}
|
|
567
|
+
} catch (err) {
|
|
568
|
+
_iterator3.e(err);
|
|
569
|
+
} finally {
|
|
570
|
+
_iterator3.f();
|
|
571
|
+
}
|
|
572
|
+
while (queue.length > 0) {
|
|
573
|
+
var nextQueue = [];
|
|
574
|
+
var _iterator4 = _createForOfIteratorHelper(queue),
|
|
575
|
+
_step4;
|
|
576
|
+
try {
|
|
577
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
578
|
+
var _computedState$mounte, _computedState$mounte2;
|
|
579
|
+
var computed$ = _step4.value;
|
|
580
|
+
var computedState = readComputed(computed$, context, mutation);
|
|
581
|
+
if ((_computedState$mounte = computedState.mounted) !== null && _computedState$mounte !== void 0 && _computedState$mounte.listeners) {
|
|
582
|
+
var _iterator5 = _createForOfIteratorHelper(computedState.mounted.listeners),
|
|
583
|
+
_step5;
|
|
584
|
+
try {
|
|
585
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
586
|
+
var listener = _step5.value;
|
|
587
|
+
mutation.pendingListeners.add(listener);
|
|
693
588
|
}
|
|
589
|
+
} catch (err) {
|
|
590
|
+
_iterator5.e(err);
|
|
591
|
+
} finally {
|
|
592
|
+
_iterator5.f();
|
|
694
593
|
}
|
|
695
594
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
}, {
|
|
704
|
-
key: "readStateAtom",
|
|
705
|
-
value: function readStateAtom(atom) {
|
|
706
|
-
var atomState = this.atomStateMap.get(atom);
|
|
707
|
-
if (!atomState) {
|
|
708
|
-
var initState = {
|
|
709
|
-
val: atom.init,
|
|
710
|
-
epoch: 0
|
|
711
|
-
};
|
|
712
|
-
this.atomStateMap.set(atom, initState);
|
|
713
|
-
return initState;
|
|
714
|
-
}
|
|
715
|
-
return atomState;
|
|
716
|
-
}
|
|
717
|
-
}, {
|
|
718
|
-
key: "readAtomState",
|
|
719
|
-
value: function readAtomState(atom) {
|
|
720
|
-
var ignoreMounted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
721
|
-
if (canReadAsCompute(atom)) {
|
|
722
|
-
return this.readComputedAtom(atom, ignoreMounted);
|
|
723
|
-
}
|
|
724
|
-
return this.readStateAtom(atom);
|
|
725
|
-
}
|
|
726
|
-
}, {
|
|
727
|
-
key: "tryGetMount",
|
|
728
|
-
value: function tryGetMount(atom) {
|
|
729
|
-
var _this$atomStateMap$ge;
|
|
730
|
-
return (_this$atomStateMap$ge = this.atomStateMap.get(atom)) === null || _this$atomStateMap$ge === void 0 ? void 0 : _this$atomStateMap$ge.mounted;
|
|
731
|
-
}
|
|
732
|
-
}, {
|
|
733
|
-
key: "mount",
|
|
734
|
-
value: function mount(atom) {
|
|
735
|
-
var _this$options3, _this$options3$mount, _atomState$mounted;
|
|
736
|
-
var mounted = this.tryGetMount(atom);
|
|
737
|
-
if (mounted) {
|
|
738
|
-
return mounted;
|
|
739
|
-
}
|
|
740
|
-
(_this$options3 = this.options) === null || _this$options3 === void 0 || (_this$options3 = _this$options3.interceptor) === null || _this$options3 === void 0 || (_this$options3$mount = _this$options3.mount) === null || _this$options3$mount === void 0 || _this$options3$mount.call(_this$options3, atom);
|
|
741
|
-
var atomState = this.readAtomState(atom);
|
|
742
|
-
atomState.mounted = (_atomState$mounted = atomState.mounted) !== null && _atomState$mounted !== void 0 ? _atomState$mounted : {
|
|
743
|
-
listeners: new Set(),
|
|
744
|
-
readDepts: new Set()
|
|
745
|
-
};
|
|
746
|
-
if (isComputedState(atomState)) {
|
|
747
|
-
for (var _i = 0, _Array$from = Array.from(atomState.dependencies); _i < _Array$from.length; _i++) {
|
|
748
|
-
var _Array$from$_i = _slicedToArray(_Array$from[_i], 1),
|
|
749
|
-
dep = _Array$from$_i[0];
|
|
750
|
-
var _mounted = this.mount(dep);
|
|
751
|
-
_mounted.readDepts.add(atom);
|
|
595
|
+
var readDepts = (_computedState$mounte2 = computedState.mounted) === null || _computedState$mounte2 === void 0 ? void 0 : _computedState$mounte2.readDepts;
|
|
596
|
+
if (readDepts) {
|
|
597
|
+
for (var _i = 0, _Array$from = Array.from(readDepts); _i < _Array$from.length; _i++) {
|
|
598
|
+
var dep = _Array$from[_i];
|
|
599
|
+
nextQueue.push(dep);
|
|
600
|
+
}
|
|
752
601
|
}
|
|
753
602
|
}
|
|
754
|
-
|
|
603
|
+
} catch (err) {
|
|
604
|
+
_iterator4.e(err);
|
|
605
|
+
} finally {
|
|
606
|
+
_iterator4.f();
|
|
755
607
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
608
|
+
queue = nextQueue;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
function propagationChanges(readComputed, signalState, context, mutation) {
|
|
612
|
+
pushDirtyMarkers(signalState, context, mutation);
|
|
613
|
+
pullEvaluate(readComputed, signalState, context, mutation);
|
|
614
|
+
}
|
|
615
|
+
function innerSetState(readComputed, signal$, context, mutation, val) {
|
|
616
|
+
var newValue;
|
|
617
|
+
if (typeof val === 'function') {
|
|
618
|
+
var _ref, _context$stateMap$get;
|
|
619
|
+
var updater = val;
|
|
620
|
+
newValue = updater((_ref = (_context$stateMap$get = context.stateMap.get(signal$)) === null || _context$stateMap$get === void 0 ? void 0 : _context$stateMap$get.val) !== null && _ref !== void 0 ? _ref : signal$.init);
|
|
621
|
+
} else {
|
|
622
|
+
newValue = val;
|
|
623
|
+
}
|
|
624
|
+
if (shouldDistinct(signal$, newValue, context)) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
var signalState = context.stateMap.get(signal$);
|
|
628
|
+
if (!signalState) {
|
|
629
|
+
context.stateMap.set(signal$, {
|
|
630
|
+
val: newValue,
|
|
631
|
+
epoch: 0
|
|
632
|
+
});
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
signalState.val = newValue;
|
|
636
|
+
signalState.epoch += 1;
|
|
637
|
+
propagationChanges(readComputed, signalState, context, mutation);
|
|
638
|
+
return undefined;
|
|
639
|
+
}
|
|
640
|
+
function set(readComputed, writable$, context, mutation) {
|
|
641
|
+
if ('read' in writable$) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
for (var _len = arguments.length, args = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++) {
|
|
645
|
+
args[_key - 4] = arguments[_key];
|
|
646
|
+
}
|
|
647
|
+
if ('write' in writable$) {
|
|
648
|
+
return writable$.write.apply(writable$, [mutation.visitor].concat(args));
|
|
649
|
+
}
|
|
650
|
+
innerSetState(readComputed, writable$, context, mutation, args[0]);
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Creates a mutation operation context. The Mutation remains unique throughout
|
|
656
|
+
* the mutation cycle and can track side effects produced by this mutation operation
|
|
657
|
+
*
|
|
658
|
+
* This tracking is implemented by coloring the visitor function, so the Mutation
|
|
659
|
+
* needs to wrap get & set functions and ensure that all get & set operations
|
|
660
|
+
* executed in the mutation context come from the same Mutation
|
|
661
|
+
*
|
|
662
|
+
* @param context
|
|
663
|
+
* @param get
|
|
664
|
+
* @param set
|
|
665
|
+
* @returns
|
|
666
|
+
*/
|
|
667
|
+
function createMutation(context, _get, _set) {
|
|
668
|
+
var mutation = {
|
|
669
|
+
dirtyMarkers: new Set(),
|
|
670
|
+
pendingListeners: new Set(),
|
|
671
|
+
visitor: {
|
|
672
|
+
get: function get(signal$) {
|
|
673
|
+
return _get(signal$, context, mutation);
|
|
674
|
+
},
|
|
675
|
+
set: function set(signal$) {
|
|
676
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
677
|
+
args[_key2 - 1] = arguments[_key2];
|
|
773
678
|
}
|
|
679
|
+
return _set.apply(void 0, [signal$, context].concat(args));
|
|
774
680
|
}
|
|
775
|
-
atomState.mounted = undefined;
|
|
776
681
|
}
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
var
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
682
|
+
};
|
|
683
|
+
return mutation;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function readState(state, context) {
|
|
687
|
+
var atomState = context.stateMap.get(state);
|
|
688
|
+
if (!atomState) {
|
|
689
|
+
var initState = {
|
|
690
|
+
val: state.init,
|
|
691
|
+
epoch: 0
|
|
692
|
+
};
|
|
693
|
+
context.stateMap.set(state, initState);
|
|
694
|
+
return initState;
|
|
788
695
|
}
|
|
789
|
-
return
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
696
|
+
return atomState;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function unmountComputedDependencies(computed$, computedState, context, mutation) {
|
|
700
|
+
for (var _i = 0, _Array$from = Array.from(computedState.dependencies); _i < _Array$from.length; _i++) {
|
|
701
|
+
var _context$stateMap$get;
|
|
702
|
+
var _Array$from$_i = _slicedToArray(_Array$from[_i], 1),
|
|
703
|
+
dep = _Array$from$_i[0];
|
|
704
|
+
(_context$stateMap$get = context.stateMap.get(dep)) === null || _context$stateMap$get === void 0 || (_context$stateMap$get = _context$stateMap$get.mounted) === null || _context$stateMap$get === void 0 || _context$stateMap$get.readDepts["delete"](computed$);
|
|
705
|
+
unmount(dep, context);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
function mountComputedDependencies(readSignal, computed$, computedState, context, mutation) {
|
|
709
|
+
for (var _i2 = 0, _Array$from2 = Array.from(computedState.dependencies); _i2 < _Array$from2.length; _i2++) {
|
|
710
|
+
var _Array$from2$_i = _slicedToArray(_Array$from2[_i2], 1),
|
|
711
|
+
dep = _Array$from2$_i[0];
|
|
712
|
+
var mounted = mount$1(readSignal, dep, context, mutation);
|
|
713
|
+
mounted.readDepts.add(computed$);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
function initMount(readSignal, signal$, context, mutation) {
|
|
717
|
+
var _context$interceptor, _context$interceptor$, _signalState$mounted;
|
|
718
|
+
(_context$interceptor = context.interceptor) === null || _context$interceptor === void 0 || (_context$interceptor$ = _context$interceptor.mount) === null || _context$interceptor$ === void 0 || _context$interceptor$.call(_context$interceptor, signal$);
|
|
719
|
+
var signalState = readSignal(signal$, context, mutation);
|
|
720
|
+
signalState.mounted = (_signalState$mounted = signalState.mounted) !== null && _signalState$mounted !== void 0 ? _signalState$mounted : {
|
|
721
|
+
listeners: new Set(),
|
|
722
|
+
readDepts: new Set()
|
|
723
|
+
};
|
|
724
|
+
if (isComputedState(signalState)) {
|
|
725
|
+
mountComputedDependencies(readSignal, signal$, signalState, context, mutation);
|
|
726
|
+
}
|
|
727
|
+
return signalState.mounted;
|
|
728
|
+
}
|
|
729
|
+
function mount$1(readSignal, signal$, context, mutation) {
|
|
730
|
+
var _context$stateMap$get2;
|
|
731
|
+
var mounted = (_context$stateMap$get2 = context.stateMap.get(signal$)) === null || _context$stateMap$get2 === void 0 ? void 0 : _context$stateMap$get2.mounted;
|
|
732
|
+
if (mounted) {
|
|
733
|
+
return mounted;
|
|
734
|
+
}
|
|
735
|
+
return initMount(readSignal, signal$, context, mutation);
|
|
736
|
+
}
|
|
737
|
+
function doUnmount(signal$, signalState, context, mutation) {
|
|
738
|
+
var _context$interceptor2, _context$interceptor3;
|
|
739
|
+
(_context$interceptor2 = context.interceptor) === null || _context$interceptor2 === void 0 || (_context$interceptor3 = _context$interceptor2.unmount) === null || _context$interceptor3 === void 0 || _context$interceptor3.call(_context$interceptor2, signal$);
|
|
740
|
+
if (isComputedState(signalState)) {
|
|
741
|
+
unmountComputedDependencies(signal$, signalState, context);
|
|
742
|
+
}
|
|
743
|
+
signalState.mounted = undefined;
|
|
744
|
+
}
|
|
745
|
+
function unmount(signal$, context, mutation) {
|
|
746
|
+
var signalState = context.stateMap.get(signal$);
|
|
747
|
+
if (!(signalState !== null && signalState !== void 0 && signalState.mounted) || signalState.mounted.listeners.size || signalState.mounted.readDepts.size) {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
doUnmount(signal$, signalState, context);
|
|
751
|
+
}
|
|
752
|
+
function subSingleSignal(readSignal, signal$, callback$, context, signal) {
|
|
753
|
+
var _context$interceptor5;
|
|
754
|
+
withSubInterceptor(function () {
|
|
755
|
+
var mounted = mount$1(readSignal, signal$, context);
|
|
756
|
+
mounted.listeners.add(callback$);
|
|
757
|
+
var unsub = function unsub() {
|
|
758
|
+
var _context$interceptor4;
|
|
759
|
+
withUnsubInterceptor(function () {
|
|
760
|
+
mounted.listeners["delete"](callback$);
|
|
761
|
+
if (mounted.readDepts.size === 0 && mounted.listeners.size === 0) {
|
|
762
|
+
unmount(signal$, context);
|
|
828
763
|
}
|
|
829
|
-
|
|
830
|
-
|
|
764
|
+
}, signal$, callback$, (_context$interceptor4 = context.interceptor) === null || _context$interceptor4 === void 0 ? void 0 : _context$interceptor4.unsub);
|
|
765
|
+
};
|
|
766
|
+
signal.addEventListener('abort', unsub, {
|
|
767
|
+
once: true
|
|
768
|
+
});
|
|
769
|
+
}, signal$, callback$, (_context$interceptor5 = context.interceptor) === null || _context$interceptor5 === void 0 ? void 0 : _context$interceptor5.sub);
|
|
770
|
+
}
|
|
771
|
+
function notify(context, mutation) {
|
|
772
|
+
var pendingListeners = mutation.pendingListeners;
|
|
773
|
+
mutation.pendingListeners = new Set();
|
|
774
|
+
var _iterator = _createForOfIteratorHelper(pendingListeners),
|
|
775
|
+
_step;
|
|
776
|
+
try {
|
|
777
|
+
var _loop = function _loop() {
|
|
778
|
+
var _context$interceptor6;
|
|
779
|
+
var listener = _step.value;
|
|
780
|
+
withNotifyInterceptor(function () {
|
|
781
|
+
return listener.write(mutation.visitor);
|
|
782
|
+
}, listener, (_context$interceptor6 = context.interceptor) === null || _context$interceptor6 === void 0 ? void 0 : _context$interceptor6.notify);
|
|
783
|
+
};
|
|
784
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
785
|
+
_loop();
|
|
831
786
|
}
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
case 0:
|
|
839
|
-
pendingListeners = this.pendingListeners;
|
|
840
|
-
this.pendingListeners = new Set();
|
|
841
|
-
_iterator5 = _createForOfIteratorHelper(pendingListeners);
|
|
842
|
-
_context.prev = 3;
|
|
843
|
-
_iterator5.s();
|
|
844
|
-
case 5:
|
|
845
|
-
if ((_step5 = _iterator5.n()).done) {
|
|
846
|
-
_context.next = 11;
|
|
847
|
-
break;
|
|
848
|
-
}
|
|
849
|
-
listener = _step5.value;
|
|
850
|
-
_context.next = 9;
|
|
851
|
-
return listener;
|
|
852
|
-
case 9:
|
|
853
|
-
_context.next = 5;
|
|
854
|
-
break;
|
|
855
|
-
case 11:
|
|
856
|
-
_context.next = 16;
|
|
857
|
-
break;
|
|
858
|
-
case 13:
|
|
859
|
-
_context.prev = 13;
|
|
860
|
-
_context.t0 = _context["catch"](3);
|
|
861
|
-
_iterator5.e(_context.t0);
|
|
862
|
-
case 16:
|
|
863
|
-
_context.prev = 16;
|
|
864
|
-
_iterator5.f();
|
|
865
|
-
return _context.finish(16);
|
|
866
|
-
case 19:
|
|
867
|
-
case "end":
|
|
868
|
-
return _context.stop();
|
|
869
|
-
}
|
|
870
|
-
}, notify, this, [[3, 13, 16, 19]]);
|
|
871
|
-
})
|
|
872
|
-
}]);
|
|
873
|
-
}();
|
|
787
|
+
} catch (err) {
|
|
788
|
+
_iterator.e(err);
|
|
789
|
+
} finally {
|
|
790
|
+
_iterator.f();
|
|
791
|
+
}
|
|
792
|
+
}
|
|
874
793
|
|
|
794
|
+
var _readComputed = function readComputed(computed$, context, mutation) {
|
|
795
|
+
var _context$interceptor;
|
|
796
|
+
var cachedState = tryGetCached(_readComputed, computed$, context, mutation);
|
|
797
|
+
if (cachedState) {
|
|
798
|
+
return cachedState;
|
|
799
|
+
}
|
|
800
|
+
mutation === null || mutation === void 0 || mutation.dirtyMarkers["delete"](computed$.id);
|
|
801
|
+
return withComputedInterceptor(function () {
|
|
802
|
+
return evaluateComputed(readSignal, mount, unmount, computed$, context, mutation);
|
|
803
|
+
}, computed$, (_context$interceptor = context.interceptor) === null || _context$interceptor === void 0 ? void 0 : _context$interceptor.computed);
|
|
804
|
+
};
|
|
805
|
+
function readSignal(signal$, context, mutation) {
|
|
806
|
+
if (canReadAsCompute(signal$)) {
|
|
807
|
+
return _readComputed(signal$, context, mutation);
|
|
808
|
+
}
|
|
809
|
+
return readState(signal$, context);
|
|
810
|
+
}
|
|
811
|
+
function mount(signal$, context, mutation) {
|
|
812
|
+
return mount$1(readSignal, signal$, context, mutation);
|
|
813
|
+
}
|
|
814
|
+
function _sub(signals$, callback$, context, options) {
|
|
815
|
+
if (Array.isArray(signals$) && signals$.length === 0) {
|
|
816
|
+
return function () {
|
|
817
|
+
return void 0;
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
var controller = new AbortController();
|
|
821
|
+
var signal = options !== null && options !== void 0 && options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
822
|
+
if (!Array.isArray(signals$)) {
|
|
823
|
+
subSingleSignal(readSignal, signals$, callback$, context, signal);
|
|
824
|
+
} else {
|
|
825
|
+
signals$.forEach(function (atom) {
|
|
826
|
+
subSingleSignal(readSignal, atom, callback$, context, signal);
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
return function () {
|
|
830
|
+
controller.abort();
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
var get = function get(signal, context, mutation) {
|
|
834
|
+
var _context$interceptor2;
|
|
835
|
+
return withGetInterceptor(function () {
|
|
836
|
+
return readSignal(signal, context, mutation).val;
|
|
837
|
+
}, signal, (_context$interceptor2 = context.interceptor) === null || _context$interceptor2 === void 0 ? void 0 : _context$interceptor2.get);
|
|
838
|
+
};
|
|
839
|
+
var _set = function set$1(atom, context) {
|
|
840
|
+
var _context$interceptor3;
|
|
841
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
842
|
+
args[_key - 2] = arguments[_key];
|
|
843
|
+
}
|
|
844
|
+
return withSetInterceptor.apply(void 0, [function () {
|
|
845
|
+
var mutation = createMutation(context, get, _set);
|
|
846
|
+
var ret;
|
|
847
|
+
try {
|
|
848
|
+
ret = set.apply(void 0, [_readComputed, atom, context, mutation].concat(args));
|
|
849
|
+
} finally {
|
|
850
|
+
notify(context, mutation);
|
|
851
|
+
}
|
|
852
|
+
return ret;
|
|
853
|
+
}, atom, (_context$interceptor3 = context.interceptor) === null || _context$interceptor3 === void 0 ? void 0 : _context$interceptor3.set].concat(args));
|
|
854
|
+
};
|
|
875
855
|
var StoreImpl = /*#__PURE__*/function () {
|
|
876
|
-
function StoreImpl(
|
|
877
|
-
var _this = this
|
|
856
|
+
function StoreImpl(options) {
|
|
857
|
+
var _this = this,
|
|
858
|
+
_this$options;
|
|
878
859
|
_classCallCheck(this, StoreImpl);
|
|
879
|
-
_defineProperty(this, "
|
|
880
|
-
if ('read' in atom) {
|
|
881
|
-
return;
|
|
882
|
-
}
|
|
883
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
884
|
-
args[_key - 1] = arguments[_key];
|
|
885
|
-
}
|
|
886
|
-
if ('write' in atom) {
|
|
887
|
-
var ret = atom.write.apply(atom, [{
|
|
888
|
-
get: _this.get,
|
|
889
|
-
set: _this.set
|
|
890
|
-
}].concat(_toConsumableArray(args)));
|
|
891
|
-
return ret;
|
|
892
|
-
}
|
|
893
|
-
var newValue = typeof args[0] === 'function' ? args[0](_this.atomManager.readAtomState(atom).val) : args[0];
|
|
894
|
-
if (!_this.atomManager.inited(atom)) {
|
|
895
|
-
_this.atomManager.readAtomState(atom).val = newValue;
|
|
896
|
-
_this.listenerManager.markPendingListeners(_this.atomManager, atom);
|
|
897
|
-
return;
|
|
898
|
-
}
|
|
899
|
-
var atomState = _this.atomManager.readAtomState(atom);
|
|
900
|
-
atomState.val = newValue;
|
|
901
|
-
atomState.epoch += 1;
|
|
902
|
-
_this.listenerManager.markPendingListeners(_this.atomManager, atom);
|
|
903
|
-
return undefined;
|
|
904
|
-
});
|
|
860
|
+
_defineProperty(this, "stateMap", new WeakMap());
|
|
905
861
|
_defineProperty(this, "get", function (atom) {
|
|
906
|
-
|
|
907
|
-
if (!((_this$options = _this.options) !== null && _this$options !== void 0 && (_this$options = _this$options.interceptor) !== null && _this$options !== void 0 && _this$options.get)) {
|
|
908
|
-
return _this.atomManager.readAtomState(atom).val;
|
|
909
|
-
}
|
|
910
|
-
var result = {
|
|
911
|
-
called: false
|
|
912
|
-
};
|
|
913
|
-
var fnWithRet = function fnWithRet() {
|
|
914
|
-
result = {
|
|
915
|
-
called: true,
|
|
916
|
-
data: _this.atomManager.readAtomState(atom).val
|
|
917
|
-
};
|
|
918
|
-
return result.data;
|
|
919
|
-
};
|
|
920
|
-
_this.options.interceptor.get(atom, fnWithRet);
|
|
921
|
-
if (!result.called) {
|
|
922
|
-
throw new Error('interceptor must call fn sync');
|
|
923
|
-
}
|
|
924
|
-
return result.data;
|
|
925
|
-
});
|
|
926
|
-
_defineProperty(this, "notify", function () {
|
|
927
|
-
var _iterator = _createForOfIteratorHelper(_this.listenerManager.notify()),
|
|
928
|
-
_step;
|
|
929
|
-
try {
|
|
930
|
-
var _loop = function _loop() {
|
|
931
|
-
var _this$options2;
|
|
932
|
-
var listener = _step.value;
|
|
933
|
-
var notifyed = false;
|
|
934
|
-
var fn = function fn() {
|
|
935
|
-
notifyed = true;
|
|
936
|
-
return listener.write({
|
|
937
|
-
get: _this.get,
|
|
938
|
-
set: _this.set
|
|
939
|
-
});
|
|
940
|
-
};
|
|
941
|
-
if ((_this$options2 = _this.options) !== null && _this$options2 !== void 0 && (_this$options2 = _this$options2.interceptor) !== null && _this$options2 !== void 0 && _this$options2.notify) {
|
|
942
|
-
_this.options.interceptor.notify(listener, fn);
|
|
943
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- notify must call fn sync
|
|
944
|
-
if (!notifyed) {
|
|
945
|
-
throw new Error('interceptor must call fn sync');
|
|
946
|
-
}
|
|
947
|
-
} else {
|
|
948
|
-
fn();
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
952
|
-
_loop();
|
|
953
|
-
}
|
|
954
|
-
} catch (err) {
|
|
955
|
-
_iterator.e(err);
|
|
956
|
-
} finally {
|
|
957
|
-
_iterator.f();
|
|
958
|
-
}
|
|
862
|
+
return get(atom, _this.context);
|
|
959
863
|
});
|
|
960
864
|
_defineProperty(this, "set", function (atom) {
|
|
961
|
-
var _this$options3;
|
|
962
865
|
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
963
866
|
args[_key2 - 1] = arguments[_key2];
|
|
964
867
|
}
|
|
965
|
-
|
|
966
|
-
var fn = function fn() {
|
|
967
|
-
try {
|
|
968
|
-
ret = _this.innerSet.apply(_this, [atom].concat(args));
|
|
969
|
-
} finally {
|
|
970
|
-
_this.notify();
|
|
971
|
-
}
|
|
972
|
-
return ret;
|
|
973
|
-
};
|
|
974
|
-
if ((_this$options3 = _this.options) !== null && _this$options3 !== void 0 && (_this$options3 = _this$options3.interceptor) !== null && _this$options3 !== void 0 && _this$options3.set) {
|
|
975
|
-
if ('write' in atom) {
|
|
976
|
-
var _this$options$interce;
|
|
977
|
-
(_this$options$interce = _this.options.interceptor).set.apply(_this$options$interce, [atom, fn].concat(_toConsumableArray(args)));
|
|
978
|
-
} else {
|
|
979
|
-
_this.options.interceptor.set(atom, fn, args[0]);
|
|
980
|
-
}
|
|
981
|
-
} else {
|
|
982
|
-
fn();
|
|
983
|
-
}
|
|
984
|
-
return ret;
|
|
868
|
+
return _set.apply(void 0, [atom, _this.context].concat(args));
|
|
985
869
|
});
|
|
986
|
-
this.atomManager = atomManager;
|
|
987
|
-
this.listenerManager = listenerManager;
|
|
988
870
|
this.options = options;
|
|
871
|
+
this.context = {
|
|
872
|
+
stateMap: this.stateMap,
|
|
873
|
+
interceptor: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.interceptor
|
|
874
|
+
};
|
|
989
875
|
}
|
|
990
876
|
return _createClass(StoreImpl, [{
|
|
991
|
-
key: "_subSingleAtom",
|
|
992
|
-
value: function _subSingleAtom(target$, cb$, options) {
|
|
993
|
-
var _this2 = this,
|
|
994
|
-
_this$options4;
|
|
995
|
-
var unsub;
|
|
996
|
-
var _fn2 = function fn() {
|
|
997
|
-
var _options$signal2;
|
|
998
|
-
var subscribed = true;
|
|
999
|
-
var mounted = _this2.atomManager.mount(target$);
|
|
1000
|
-
mounted.listeners.add(cb$);
|
|
1001
|
-
unsub = function unsub() {
|
|
1002
|
-
var _this2$options;
|
|
1003
|
-
if (!subscribed) {
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
var _fn = function fn() {
|
|
1007
|
-
var _options$signal;
|
|
1008
|
-
subscribed = false;
|
|
1009
|
-
mounted.listeners["delete"](cb$);
|
|
1010
|
-
if (mounted.readDepts.size === 0 && mounted.listeners.size === 0) {
|
|
1011
|
-
_this2.atomManager.tryUnmount(target$);
|
|
1012
|
-
}
|
|
1013
|
-
options === null || options === void 0 || (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener('abort', _fn);
|
|
1014
|
-
};
|
|
1015
|
-
if ((_this2$options = _this2.options) !== null && _this2$options !== void 0 && (_this2$options = _this2$options.interceptor) !== null && _this2$options !== void 0 && _this2$options.unsub) {
|
|
1016
|
-
_this2.options.interceptor.unsub(target$, cb$, _fn);
|
|
1017
|
-
|
|
1018
|
-
// subscribed should be false if interceptor called fn sync
|
|
1019
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1020
|
-
if (subscribed) {
|
|
1021
|
-
throw new Error('interceptor must call fn sync');
|
|
1022
|
-
}
|
|
1023
|
-
} else {
|
|
1024
|
-
_fn();
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
options === null || options === void 0 || (_options$signal2 = options.signal) === null || _options$signal2 === void 0 || _options$signal2.addEventListener('abort', unsub);
|
|
1028
|
-
};
|
|
1029
|
-
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && (_this$options4 = _this$options4.interceptor) !== null && _this$options4 !== void 0 && _this$options4.sub) {
|
|
1030
|
-
this.options.interceptor.sub(target$, cb$, _fn2);
|
|
1031
|
-
} else {
|
|
1032
|
-
_fn2();
|
|
1033
|
-
}
|
|
1034
|
-
if (!unsub) {
|
|
1035
|
-
throw new Error('interceptor must call fn sync');
|
|
1036
|
-
}
|
|
1037
|
-
return unsub;
|
|
1038
|
-
}
|
|
1039
|
-
}, {
|
|
1040
877
|
key: "sub",
|
|
1041
878
|
value: function sub(targets$, cb$, options) {
|
|
1042
|
-
|
|
1043
|
-
if (Array.isArray(targets$) && targets$.length === 0) {
|
|
1044
|
-
return function () {
|
|
1045
|
-
return void 0;
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
if (Array.isArray(targets$) && targets$.length === 1) {
|
|
1049
|
-
return this._subSingleAtom(targets$[0], cb$, options);
|
|
1050
|
-
} else if (!Array.isArray(targets$)) {
|
|
1051
|
-
return this._subSingleAtom(targets$, cb$, options);
|
|
1052
|
-
}
|
|
1053
|
-
var unsubscribes = new Set();
|
|
1054
|
-
targets$.forEach(function (atom) {
|
|
1055
|
-
unsubscribes.add(_this3._subSingleAtom(atom, cb$, options));
|
|
1056
|
-
});
|
|
1057
|
-
var unsub = function unsub() {
|
|
1058
|
-
var _iterator2 = _createForOfIteratorHelper(unsubscribes),
|
|
1059
|
-
_step2;
|
|
1060
|
-
try {
|
|
1061
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1062
|
-
var unsubscribe = _step2.value;
|
|
1063
|
-
unsubscribe();
|
|
1064
|
-
}
|
|
1065
|
-
} catch (err) {
|
|
1066
|
-
_iterator2.e(err);
|
|
1067
|
-
} finally {
|
|
1068
|
-
_iterator2.f();
|
|
1069
|
-
}
|
|
1070
|
-
};
|
|
1071
|
-
return unsub;
|
|
879
|
+
return _sub(targets$, cb$, this.context, options);
|
|
1072
880
|
}
|
|
1073
881
|
}]);
|
|
1074
882
|
}();
|
|
1075
883
|
function createStore() {
|
|
1076
|
-
|
|
1077
|
-
var listenerManager = new ListenerManager();
|
|
1078
|
-
return new StoreImpl(atomManager, listenerManager);
|
|
884
|
+
return new StoreImpl();
|
|
1079
885
|
}
|
|
1080
886
|
var defaultStore = undefined;
|
|
1081
887
|
function getDefaultStore() {
|
|
@@ -1122,7 +928,10 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1122
928
|
};
|
|
1123
929
|
});
|
|
1124
930
|
_defineProperty(_this, "getReadDependencies", function (atom) {
|
|
1125
|
-
var atomState = _this.
|
|
931
|
+
var atomState = _this.context.stateMap.get(atom);
|
|
932
|
+
if (!atomState) {
|
|
933
|
+
return [atom];
|
|
934
|
+
}
|
|
1126
935
|
if (!('dependencies' in atomState)) {
|
|
1127
936
|
return [atom];
|
|
1128
937
|
}
|
|
@@ -1134,7 +943,10 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1134
943
|
});
|
|
1135
944
|
_defineProperty(_this, "getReadDependents", function (atom) {
|
|
1136
945
|
var _atomState$mounted$re, _atomState$mounted;
|
|
1137
|
-
var atomState = _this.
|
|
946
|
+
var atomState = _this.context.stateMap.get(atom);
|
|
947
|
+
if (!atomState) {
|
|
948
|
+
return [atom];
|
|
949
|
+
}
|
|
1138
950
|
return [atom].concat(_toConsumableArray(Array.from((_atomState$mounted$re = (_atomState$mounted = atomState.mounted) === null || _atomState$mounted === void 0 ? void 0 : _atomState$mounted.readDepts) !== null && _atomState$mounted$re !== void 0 ? _atomState$mounted$re : []).map(function (key) {
|
|
1139
951
|
return _this.getReadDependents(key);
|
|
1140
952
|
})));
|
|
@@ -1142,15 +954,51 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1142
954
|
_defineProperty(_this, "getSubscribeGraph", function () {
|
|
1143
955
|
var subscribedAtoms = Array.from(_this.mountedAtomListenersCount.keys());
|
|
1144
956
|
return subscribedAtoms.map(function (atom) {
|
|
1145
|
-
var atomState = _this.
|
|
1146
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
957
|
+
var atomState = _this.context.stateMap.get(atom);
|
|
958
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1147
959
|
var listeners = Array.from(atomState.mounted.listeners);
|
|
1148
960
|
return [atom].concat(listeners);
|
|
1149
961
|
});
|
|
1150
962
|
});
|
|
1151
963
|
_defineProperty(_this, "isMounted", function (atom) {
|
|
1152
|
-
var mountState = _this.
|
|
1153
|
-
return mountState.mounted !== undefined;
|
|
964
|
+
var mountState = _this.stateMap.get(atom);
|
|
965
|
+
return (mountState === null || mountState === void 0 ? void 0 : mountState.mounted) !== undefined;
|
|
966
|
+
});
|
|
967
|
+
_defineProperty(_this, "getDependenciesGraph", function (computed$) {
|
|
968
|
+
var stateMap = _this.context.stateMap;
|
|
969
|
+
function fillDependenciesGraph(computed$, result) {
|
|
970
|
+
var computedState = stateMap.get(computed$);
|
|
971
|
+
var _iterator = _createForOfIteratorHelper(computedState.dependencies.entries()),
|
|
972
|
+
_step;
|
|
973
|
+
try {
|
|
974
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
975
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
976
|
+
child$ = _step$value[0],
|
|
977
|
+
epoch = _step$value[1];
|
|
978
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
|
|
979
|
+
var childState = stateMap.get(child$);
|
|
980
|
+
result.push([{
|
|
981
|
+
signal: computed$,
|
|
982
|
+
val: computedState.val,
|
|
983
|
+
epoch: computedState.epoch
|
|
984
|
+
}, {
|
|
985
|
+
signal: child$,
|
|
986
|
+
val: childState.val,
|
|
987
|
+
epoch: childState.epoch
|
|
988
|
+
}, epoch]);
|
|
989
|
+
if (canReadAsCompute(child$)) {
|
|
990
|
+
fillDependenciesGraph(child$, result);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
} catch (err) {
|
|
994
|
+
_iterator.e(err);
|
|
995
|
+
} finally {
|
|
996
|
+
_iterator.f();
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
var result = [];
|
|
1000
|
+
fillDependenciesGraph(computed$, result);
|
|
1001
|
+
return result;
|
|
1154
1002
|
});
|
|
1155
1003
|
return _this;
|
|
1156
1004
|
}
|
|
@@ -1158,11 +1006,7 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1158
1006
|
return _createClass(DebugStoreImpl);
|
|
1159
1007
|
}(StoreImpl);
|
|
1160
1008
|
function createDebugStoreInternal(interceptor) {
|
|
1161
|
-
|
|
1162
|
-
interceptor: interceptor
|
|
1163
|
-
});
|
|
1164
|
-
var listenerManager = new ListenerManager();
|
|
1165
|
-
return new DebugStoreImpl(atomManager, listenerManager, {
|
|
1009
|
+
return new DebugStoreImpl({
|
|
1166
1010
|
interceptor: interceptor
|
|
1167
1011
|
});
|
|
1168
1012
|
}
|