ccstate 4.1.0 → 4.2.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 +576 -789
- package/core/index.cjs.map +1 -1
- package/core/index.d.cts +6 -3
- package/core/index.d.ts +6 -3
- package/core/index.js +576 -789
- package/core/index.js.map +1 -1
- package/debug/index.cjs +581 -795
- package/debug/index.cjs.map +1 -1
- package/debug/index.d.cts +6 -3
- package/debug/index.d.ts +6 -3
- package/debug/index.js +581 -795
- package/debug/index.js.map +1 -1
- package/index.cjs +589 -800
- package/index.cjs.map +1 -1
- package/index.d.cts +6 -3
- package/index.d.ts +6 -3
- package/index.js +589 -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,619 @@ 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(_toConsumableArray(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
|
-
var
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
var _iterator = _createForOfIteratorHelper(atomState.dependencies.entries()),
|
|
569
|
-
_step;
|
|
570
|
-
try {
|
|
571
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
572
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
573
|
-
dep = _step$value[0],
|
|
574
|
-
epoch = _step$value[1];
|
|
575
|
-
var depState = _this.readAtomState(dep);
|
|
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 checkEpoch(readComputed, computedState, context, mutation) {
|
|
403
|
+
var _iterator = _createForOfIteratorHelper(computedState.dependencies.entries()),
|
|
404
|
+
_step;
|
|
405
|
+
try {
|
|
406
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
407
|
+
var _context$stateMap$get;
|
|
408
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
409
|
+
dep = _step$value[0],
|
|
410
|
+
epoch = _step$value[1];
|
|
411
|
+
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;
|
|
412
|
+
if (depEpoch !== epoch) {
|
|
413
|
+
return false;
|
|
584
414
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
415
|
+
}
|
|
416
|
+
} catch (err) {
|
|
417
|
+
_iterator.e(err);
|
|
418
|
+
} finally {
|
|
419
|
+
_iterator.f();
|
|
588
420
|
}
|
|
589
|
-
return
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
function tryGetCached(readComputed, computed$, context, mutation) {
|
|
424
|
+
var signalState = context.stateMap.get(computed$);
|
|
425
|
+
if (!signalState) {
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
if (mutation !== null && mutation !== void 0 && mutation.dirtyMarkers.has(computed$.id)) {
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
431
|
+
if (signalState.mounted) {
|
|
432
|
+
return signalState;
|
|
433
|
+
}
|
|
434
|
+
if (checkEpoch(readComputed, signalState, context, mutation)) {
|
|
435
|
+
return signalState;
|
|
436
|
+
}
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
function wrapGet(readSignal, mount, callerComputed$, callerState, context, mutation) {
|
|
440
|
+
var readDeps = new Map();
|
|
441
|
+
return [function (dep$) {
|
|
442
|
+
var depState = readSignal(dep$, context, mutation);
|
|
443
|
+
if (callerState.dependencies === readDeps) {
|
|
444
|
+
readDeps.set(dep$, depState.epoch);
|
|
445
|
+
var callerMounted = !!callerState.mounted;
|
|
446
|
+
if (callerMounted && !depState.mounted) {
|
|
447
|
+
mount(dep$, context, mutation).readDepts.add(callerComputed$);
|
|
448
|
+
} else if (callerMounted && depState.mounted) {
|
|
449
|
+
depState.mounted.readDepts.add(callerComputed$);
|
|
602
450
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
451
|
+
}
|
|
452
|
+
return depState.val;
|
|
453
|
+
}, readDeps];
|
|
454
|
+
}
|
|
455
|
+
function getOrInitComputedState(computed$, context) {
|
|
456
|
+
var computedState = context.stateMap.get(computed$);
|
|
457
|
+
if (!computedState) {
|
|
458
|
+
computedState = {
|
|
459
|
+
dependencies: new Map(),
|
|
460
|
+
epoch: -1
|
|
461
|
+
};
|
|
462
|
+
context.stateMap.set(computed$, computedState);
|
|
463
|
+
}
|
|
464
|
+
return computedState;
|
|
465
|
+
}
|
|
466
|
+
function cleanupMissingDependencies(unmount, computed$, lastDeps, currDeps, context, mutation) {
|
|
467
|
+
var _iterator2 = _createForOfIteratorHelper(lastDeps.keys()),
|
|
468
|
+
_step2;
|
|
469
|
+
try {
|
|
470
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
471
|
+
var key = _step2.value;
|
|
472
|
+
if (!currDeps.has(key)) {
|
|
473
|
+
var _depState$mounted;
|
|
474
|
+
var depState = context.stateMap.get(key);
|
|
475
|
+
depState === null || depState === void 0 || (_depState$mounted = depState.mounted) === null || _depState$mounted === void 0 || _depState$mounted.readDepts["delete"](computed$);
|
|
476
|
+
unmount(key, context, mutation);
|
|
615
477
|
}
|
|
616
|
-
return result.data;
|
|
617
478
|
}
|
|
479
|
+
} catch (err) {
|
|
480
|
+
_iterator2.e(err);
|
|
481
|
+
} finally {
|
|
482
|
+
_iterator2.f();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
function evaluateComputed(readSignal, mount, unmount, computed$, context, mutation) {
|
|
486
|
+
var computedState = getOrInitComputedState(computed$, context);
|
|
487
|
+
var lastDeps = computedState.dependencies;
|
|
488
|
+
var _wrapGet = wrapGet(readSignal, mount, computed$, computedState, context, mutation),
|
|
489
|
+
_wrapGet2 = _slicedToArray(_wrapGet, 2),
|
|
490
|
+
_get = _wrapGet2[0],
|
|
491
|
+
dependencies = _wrapGet2[1];
|
|
492
|
+
computedState.dependencies = dependencies;
|
|
493
|
+
var evalVal = computed$.read(function (depAtom) {
|
|
494
|
+
var _context$interceptor;
|
|
495
|
+
return withGeValInterceptor(function () {
|
|
496
|
+
return _get(depAtom);
|
|
497
|
+
}, depAtom, (_context$interceptor = context.interceptor) === null || _context$interceptor === void 0 ? void 0 : _context$interceptor.get);
|
|
618
498
|
}, {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
this.atomStateMap.set(self, atomState);
|
|
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);
|
|
499
|
+
get signal() {
|
|
500
|
+
var _computedState$abortC, _computed$$debugLabel;
|
|
501
|
+
(_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"));
|
|
502
|
+
computedState.abortController = new AbortController();
|
|
503
|
+
return computedState.abortController.signal;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
cleanupMissingDependencies(unmount, computed$, lastDeps, dependencies, context, mutation);
|
|
507
|
+
computedState.val = evalVal;
|
|
508
|
+
computedState.epoch += 1;
|
|
509
|
+
return computedState;
|
|
510
|
+
}
|
|
638
511
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
512
|
+
function pushDirtyMarkers(signalState, context, mutation) {
|
|
513
|
+
var _signalState$mounted$, _signalState$mounted;
|
|
514
|
+
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$ : []);
|
|
515
|
+
while (queue.length > 0) {
|
|
516
|
+
var nextQueue = [];
|
|
517
|
+
var _iterator = _createForOfIteratorHelper(queue),
|
|
518
|
+
_step;
|
|
519
|
+
try {
|
|
520
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
521
|
+
var computed$ = _step.value;
|
|
522
|
+
mutation.dirtyMarkers.add(computed$.id);
|
|
523
|
+
var computedState = context.stateMap.get(computed$);
|
|
524
|
+
// This computed$ is read from other computed$'s readDepts, so it must not be null and must have mounted
|
|
525
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
526
|
+
var _iterator2 = _createForOfIteratorHelper(computedState.mounted.readDepts),
|
|
527
|
+
_step2;
|
|
528
|
+
try {
|
|
529
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
530
|
+
var dep = _step2.value;
|
|
531
|
+
nextQueue.push(dep);
|
|
647
532
|
}
|
|
533
|
+
} catch (err) {
|
|
534
|
+
_iterator2.e(err);
|
|
535
|
+
} finally {
|
|
536
|
+
_iterator2.f();
|
|
648
537
|
}
|
|
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
538
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
539
|
+
} catch (err) {
|
|
540
|
+
_iterator.e(err);
|
|
541
|
+
} finally {
|
|
542
|
+
_iterator.f();
|
|
543
|
+
}
|
|
544
|
+
queue = nextQueue;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
548
|
+
var _signalState$mounted$2, _signalState$mounted2, _signalState$mounted$3, _signalState$mounted3;
|
|
549
|
+
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 : []);
|
|
550
|
+
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 : []),
|
|
551
|
+
_step3;
|
|
552
|
+
try {
|
|
553
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
554
|
+
var _listener = _step3.value;
|
|
555
|
+
mutation.pendingListeners.add(_listener);
|
|
556
|
+
}
|
|
557
|
+
} catch (err) {
|
|
558
|
+
_iterator3.e(err);
|
|
559
|
+
} finally {
|
|
560
|
+
_iterator3.f();
|
|
561
|
+
}
|
|
562
|
+
while (queue.length > 0) {
|
|
563
|
+
var nextQueue = [];
|
|
564
|
+
var _iterator4 = _createForOfIteratorHelper(queue),
|
|
565
|
+
_step4;
|
|
566
|
+
try {
|
|
567
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
568
|
+
var _computedState$mounte, _computedState$mounte2;
|
|
569
|
+
var computed$ = _step4.value;
|
|
570
|
+
var computedState = readComputed(computed$, context, mutation);
|
|
571
|
+
if ((_computedState$mounte = computedState.mounted) !== null && _computedState$mounte !== void 0 && _computedState$mounte.listeners) {
|
|
572
|
+
var _iterator5 = _createForOfIteratorHelper(computedState.mounted.listeners),
|
|
573
|
+
_step5;
|
|
574
|
+
try {
|
|
575
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
576
|
+
var listener = _step5.value;
|
|
577
|
+
mutation.pendingListeners.add(listener);
|
|
693
578
|
}
|
|
579
|
+
} catch (err) {
|
|
580
|
+
_iterator5.e(err);
|
|
581
|
+
} finally {
|
|
582
|
+
_iterator5.f();
|
|
694
583
|
}
|
|
695
584
|
}
|
|
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);
|
|
585
|
+
var readDepts = (_computedState$mounte2 = computedState.mounted) === null || _computedState$mounte2 === void 0 ? void 0 : _computedState$mounte2.readDepts;
|
|
586
|
+
if (readDepts) {
|
|
587
|
+
for (var _i = 0, _Array$from = Array.from(readDepts); _i < _Array$from.length; _i++) {
|
|
588
|
+
var dep = _Array$from[_i];
|
|
589
|
+
nextQueue.push(dep);
|
|
590
|
+
}
|
|
752
591
|
}
|
|
753
592
|
}
|
|
754
|
-
|
|
593
|
+
} catch (err) {
|
|
594
|
+
_iterator4.e(err);
|
|
595
|
+
} finally {
|
|
596
|
+
_iterator4.f();
|
|
755
597
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
598
|
+
queue = nextQueue;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function propagationChanges(readComputed, signalState, context, mutation) {
|
|
602
|
+
pushDirtyMarkers(signalState, context, mutation);
|
|
603
|
+
pullEvaluate(readComputed, signalState, context, mutation);
|
|
604
|
+
}
|
|
605
|
+
function innerSetState(readComputed, signal$, context, mutation, val) {
|
|
606
|
+
var _ref, _context$stateMap$get;
|
|
607
|
+
var newValue = typeof val === 'function' ? val((_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) : val;
|
|
608
|
+
var signalState = context.stateMap.get(signal$);
|
|
609
|
+
if (!signalState) {
|
|
610
|
+
context.stateMap.set(signal$, {
|
|
611
|
+
val: newValue,
|
|
612
|
+
epoch: 0
|
|
613
|
+
});
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
signalState.val = newValue;
|
|
617
|
+
signalState.epoch += 1;
|
|
618
|
+
propagationChanges(readComputed, signalState, context, mutation);
|
|
619
|
+
return undefined;
|
|
620
|
+
}
|
|
621
|
+
function set(readComputed, writable$, context, mutation) {
|
|
622
|
+
if ('read' in writable$) {
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
for (var _len = arguments.length, args = new Array(_len > 4 ? _len - 4 : 0), _key = 4; _key < _len; _key++) {
|
|
626
|
+
args[_key - 4] = arguments[_key];
|
|
627
|
+
}
|
|
628
|
+
if ('write' in writable$) {
|
|
629
|
+
return writable$.write.apply(writable$, [mutation.visitor].concat(_toConsumableArray(args)));
|
|
630
|
+
}
|
|
631
|
+
innerSetState(readComputed, writable$, context, mutation, args[0]);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Creates a mutation operation context. The Mutation remains unique throughout
|
|
637
|
+
* the mutation cycle and can track side effects produced by this mutation operation
|
|
638
|
+
*
|
|
639
|
+
* This tracking is implemented by coloring the visitor function, so the Mutation
|
|
640
|
+
* needs to wrap get & set functions and ensure that all get & set operations
|
|
641
|
+
* executed in the mutation context come from the same Mutation
|
|
642
|
+
*
|
|
643
|
+
* @param context
|
|
644
|
+
* @param get
|
|
645
|
+
* @param set
|
|
646
|
+
* @returns
|
|
647
|
+
*/
|
|
648
|
+
function createMutation(context, _get, _set) {
|
|
649
|
+
var mutation = {
|
|
650
|
+
dirtyMarkers: new Set(),
|
|
651
|
+
pendingListeners: new Set(),
|
|
652
|
+
visitor: {
|
|
653
|
+
get: function get(signal$) {
|
|
654
|
+
return _get(signal$, context, mutation);
|
|
655
|
+
},
|
|
656
|
+
set: function set(signal$) {
|
|
657
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
658
|
+
args[_key2 - 1] = arguments[_key2];
|
|
773
659
|
}
|
|
660
|
+
return _set.apply(void 0, [signal$, context].concat(args));
|
|
774
661
|
}
|
|
775
|
-
atomState.mounted = undefined;
|
|
776
662
|
}
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
var
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
663
|
+
};
|
|
664
|
+
return mutation;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function readState(state, context) {
|
|
668
|
+
var atomState = context.stateMap.get(state);
|
|
669
|
+
if (!atomState) {
|
|
670
|
+
var initState = {
|
|
671
|
+
val: state.init,
|
|
672
|
+
epoch: 0
|
|
673
|
+
};
|
|
674
|
+
context.stateMap.set(state, initState);
|
|
675
|
+
return initState;
|
|
788
676
|
}
|
|
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
|
-
|
|
677
|
+
return atomState;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function unmountComputedDependencies(computed$, computedState, context, mutation) {
|
|
681
|
+
for (var _i = 0, _Array$from = Array.from(computedState.dependencies); _i < _Array$from.length; _i++) {
|
|
682
|
+
var _context$stateMap$get;
|
|
683
|
+
var _Array$from$_i = _slicedToArray(_Array$from[_i], 1),
|
|
684
|
+
dep = _Array$from$_i[0];
|
|
685
|
+
(_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$);
|
|
686
|
+
unmount(dep, context);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function mountComputedDependencies(readSignal, computed$, computedState, context, mutation) {
|
|
690
|
+
for (var _i2 = 0, _Array$from2 = Array.from(computedState.dependencies); _i2 < _Array$from2.length; _i2++) {
|
|
691
|
+
var _Array$from2$_i = _slicedToArray(_Array$from2[_i2], 1),
|
|
692
|
+
dep = _Array$from2$_i[0];
|
|
693
|
+
var mounted = mount$1(readSignal, dep, context, mutation);
|
|
694
|
+
mounted.readDepts.add(computed$);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function initMount(readSignal, signal$, context, mutation) {
|
|
698
|
+
var _context$interceptor, _context$interceptor$, _signalState$mounted;
|
|
699
|
+
(_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$);
|
|
700
|
+
var signalState = readSignal(signal$, context, mutation);
|
|
701
|
+
signalState.mounted = (_signalState$mounted = signalState.mounted) !== null && _signalState$mounted !== void 0 ? _signalState$mounted : {
|
|
702
|
+
listeners: new Set(),
|
|
703
|
+
readDepts: new Set()
|
|
704
|
+
};
|
|
705
|
+
if (isComputedState(signalState)) {
|
|
706
|
+
mountComputedDependencies(readSignal, signal$, signalState, context, mutation);
|
|
707
|
+
}
|
|
708
|
+
return signalState.mounted;
|
|
709
|
+
}
|
|
710
|
+
function mount$1(readSignal, signal$, context, mutation) {
|
|
711
|
+
var _context$stateMap$get2;
|
|
712
|
+
var mounted = (_context$stateMap$get2 = context.stateMap.get(signal$)) === null || _context$stateMap$get2 === void 0 ? void 0 : _context$stateMap$get2.mounted;
|
|
713
|
+
if (mounted) {
|
|
714
|
+
return mounted;
|
|
715
|
+
}
|
|
716
|
+
return initMount(readSignal, signal$, context, mutation);
|
|
717
|
+
}
|
|
718
|
+
function doUnmount(signal$, signalState, context, mutation) {
|
|
719
|
+
var _context$interceptor2, _context$interceptor3;
|
|
720
|
+
(_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$);
|
|
721
|
+
if (isComputedState(signalState)) {
|
|
722
|
+
unmountComputedDependencies(signal$, signalState, context);
|
|
723
|
+
}
|
|
724
|
+
signalState.mounted = undefined;
|
|
725
|
+
}
|
|
726
|
+
function unmount(signal$, context, mutation) {
|
|
727
|
+
var signalState = context.stateMap.get(signal$);
|
|
728
|
+
if (!(signalState !== null && signalState !== void 0 && signalState.mounted) || signalState.mounted.listeners.size || signalState.mounted.readDepts.size) {
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
doUnmount(signal$, signalState, context);
|
|
732
|
+
}
|
|
733
|
+
function subSingleSignal(readSignal, signal$, callback$, context, signal) {
|
|
734
|
+
var _context$interceptor5;
|
|
735
|
+
withSubInterceptor(function () {
|
|
736
|
+
var mounted = mount$1(readSignal, signal$, context);
|
|
737
|
+
mounted.listeners.add(callback$);
|
|
738
|
+
var unsub = function unsub() {
|
|
739
|
+
var _context$interceptor4;
|
|
740
|
+
withUnsubInterceptor(function () {
|
|
741
|
+
mounted.listeners["delete"](callback$);
|
|
742
|
+
if (mounted.readDepts.size === 0 && mounted.listeners.size === 0) {
|
|
743
|
+
unmount(signal$, context);
|
|
828
744
|
}
|
|
829
|
-
|
|
830
|
-
|
|
745
|
+
}, signal$, callback$, (_context$interceptor4 = context.interceptor) === null || _context$interceptor4 === void 0 ? void 0 : _context$interceptor4.unsub);
|
|
746
|
+
};
|
|
747
|
+
signal.addEventListener('abort', unsub, {
|
|
748
|
+
once: true
|
|
749
|
+
});
|
|
750
|
+
}, signal$, callback$, (_context$interceptor5 = context.interceptor) === null || _context$interceptor5 === void 0 ? void 0 : _context$interceptor5.sub);
|
|
751
|
+
}
|
|
752
|
+
function notify(context, mutation) {
|
|
753
|
+
var pendingListeners = mutation.pendingListeners;
|
|
754
|
+
mutation.pendingListeners = new Set();
|
|
755
|
+
var _iterator = _createForOfIteratorHelper(pendingListeners),
|
|
756
|
+
_step;
|
|
757
|
+
try {
|
|
758
|
+
var _loop = function _loop() {
|
|
759
|
+
var _context$interceptor6;
|
|
760
|
+
var listener = _step.value;
|
|
761
|
+
withNotifyInterceptor(function () {
|
|
762
|
+
return listener.write(mutation.visitor);
|
|
763
|
+
}, listener, (_context$interceptor6 = context.interceptor) === null || _context$interceptor6 === void 0 ? void 0 : _context$interceptor6.notify);
|
|
764
|
+
};
|
|
765
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
766
|
+
_loop();
|
|
831
767
|
}
|
|
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
|
-
}();
|
|
768
|
+
} catch (err) {
|
|
769
|
+
_iterator.e(err);
|
|
770
|
+
} finally {
|
|
771
|
+
_iterator.f();
|
|
772
|
+
}
|
|
773
|
+
}
|
|
874
774
|
|
|
775
|
+
var _readComputed = function readComputed(computed$, context, mutation) {
|
|
776
|
+
var _context$interceptor;
|
|
777
|
+
var cachedState = tryGetCached(_readComputed, computed$, context, mutation);
|
|
778
|
+
if (cachedState) {
|
|
779
|
+
return cachedState;
|
|
780
|
+
}
|
|
781
|
+
mutation === null || mutation === void 0 || mutation.dirtyMarkers["delete"](computed$.id);
|
|
782
|
+
return withComputedInterceptor(function () {
|
|
783
|
+
return evaluateComputed(readSignal, mount, unmount, computed$, context, mutation);
|
|
784
|
+
}, computed$, (_context$interceptor = context.interceptor) === null || _context$interceptor === void 0 ? void 0 : _context$interceptor.computed);
|
|
785
|
+
};
|
|
786
|
+
function readSignal(signal$, context, mutation) {
|
|
787
|
+
if (canReadAsCompute(signal$)) {
|
|
788
|
+
return _readComputed(signal$, context, mutation);
|
|
789
|
+
}
|
|
790
|
+
return readState(signal$, context);
|
|
791
|
+
}
|
|
792
|
+
function mount(signal$, context, mutation) {
|
|
793
|
+
return mount$1(readSignal, signal$, context, mutation);
|
|
794
|
+
}
|
|
795
|
+
function _sub(signals$, callback$, context, options) {
|
|
796
|
+
if (Array.isArray(signals$) && signals$.length === 0) {
|
|
797
|
+
return function () {
|
|
798
|
+
return void 0;
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
var controller = new AbortController();
|
|
802
|
+
var signal = options !== null && options !== void 0 && options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
803
|
+
if (!Array.isArray(signals$)) {
|
|
804
|
+
subSingleSignal(readSignal, signals$, callback$, context, signal);
|
|
805
|
+
} else {
|
|
806
|
+
signals$.forEach(function (atom) {
|
|
807
|
+
subSingleSignal(readSignal, atom, callback$, context, signal);
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
return function () {
|
|
811
|
+
controller.abort();
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
var get = function get(signal, context, mutation) {
|
|
815
|
+
var _context$interceptor2;
|
|
816
|
+
return withGetInterceptor(function () {
|
|
817
|
+
return readSignal(signal, context, mutation).val;
|
|
818
|
+
}, signal, (_context$interceptor2 = context.interceptor) === null || _context$interceptor2 === void 0 ? void 0 : _context$interceptor2.get);
|
|
819
|
+
};
|
|
820
|
+
var _set = function set$1(atom, context) {
|
|
821
|
+
var _context$interceptor3;
|
|
822
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
823
|
+
args[_key - 2] = arguments[_key];
|
|
824
|
+
}
|
|
825
|
+
return withSetInterceptor.apply(void 0, [function () {
|
|
826
|
+
var mutation = createMutation(context, get, _set);
|
|
827
|
+
var ret;
|
|
828
|
+
try {
|
|
829
|
+
ret = set.apply(void 0, [_readComputed, atom, context, mutation].concat(args));
|
|
830
|
+
} finally {
|
|
831
|
+
notify(context, mutation);
|
|
832
|
+
}
|
|
833
|
+
return ret;
|
|
834
|
+
}, atom, (_context$interceptor3 = context.interceptor) === null || _context$interceptor3 === void 0 ? void 0 : _context$interceptor3.set].concat(args));
|
|
835
|
+
};
|
|
875
836
|
var StoreImpl = /*#__PURE__*/function () {
|
|
876
|
-
function StoreImpl(
|
|
877
|
-
var _this = this
|
|
837
|
+
function StoreImpl(options) {
|
|
838
|
+
var _this = this,
|
|
839
|
+
_this$options;
|
|
878
840
|
_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
|
-
});
|
|
841
|
+
_defineProperty(this, "stateMap", new WeakMap());
|
|
905
842
|
_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
|
-
}
|
|
843
|
+
return get(atom, _this.context);
|
|
959
844
|
});
|
|
960
845
|
_defineProperty(this, "set", function (atom) {
|
|
961
|
-
var _this$options3;
|
|
962
846
|
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
963
847
|
args[_key2 - 1] = arguments[_key2];
|
|
964
848
|
}
|
|
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;
|
|
849
|
+
return _set.apply(void 0, [atom, _this.context].concat(args));
|
|
985
850
|
});
|
|
986
|
-
this.atomManager = atomManager;
|
|
987
|
-
this.listenerManager = listenerManager;
|
|
988
851
|
this.options = options;
|
|
852
|
+
this.context = {
|
|
853
|
+
stateMap: this.stateMap,
|
|
854
|
+
interceptor: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.interceptor
|
|
855
|
+
};
|
|
989
856
|
}
|
|
990
857
|
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
858
|
key: "sub",
|
|
1041
859
|
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;
|
|
860
|
+
return _sub(targets$, cb$, this.context, options);
|
|
1072
861
|
}
|
|
1073
862
|
}]);
|
|
1074
863
|
}();
|
|
1075
864
|
function createStore() {
|
|
1076
|
-
|
|
1077
|
-
var listenerManager = new ListenerManager();
|
|
1078
|
-
return new StoreImpl(atomManager, listenerManager);
|
|
865
|
+
return new StoreImpl();
|
|
1079
866
|
}
|
|
1080
867
|
var defaultStore = undefined;
|
|
1081
868
|
function getDefaultStore() {
|
|
@@ -1122,7 +909,10 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1122
909
|
};
|
|
1123
910
|
});
|
|
1124
911
|
_defineProperty(_this, "getReadDependencies", function (atom) {
|
|
1125
|
-
var atomState = _this.
|
|
912
|
+
var atomState = _this.context.stateMap.get(atom);
|
|
913
|
+
if (!atomState) {
|
|
914
|
+
return [atom];
|
|
915
|
+
}
|
|
1126
916
|
if (!('dependencies' in atomState)) {
|
|
1127
917
|
return [atom];
|
|
1128
918
|
}
|
|
@@ -1134,7 +924,10 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1134
924
|
});
|
|
1135
925
|
_defineProperty(_this, "getReadDependents", function (atom) {
|
|
1136
926
|
var _atomState$mounted$re, _atomState$mounted;
|
|
1137
|
-
var atomState = _this.
|
|
927
|
+
var atomState = _this.context.stateMap.get(atom);
|
|
928
|
+
if (!atomState) {
|
|
929
|
+
return [atom];
|
|
930
|
+
}
|
|
1138
931
|
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
932
|
return _this.getReadDependents(key);
|
|
1140
933
|
})));
|
|
@@ -1142,15 +935,15 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1142
935
|
_defineProperty(_this, "getSubscribeGraph", function () {
|
|
1143
936
|
var subscribedAtoms = Array.from(_this.mountedAtomListenersCount.keys());
|
|
1144
937
|
return subscribedAtoms.map(function (atom) {
|
|
1145
|
-
var atomState = _this.
|
|
1146
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
938
|
+
var atomState = _this.context.stateMap.get(atom);
|
|
939
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1147
940
|
var listeners = Array.from(atomState.mounted.listeners);
|
|
1148
941
|
return [atom].concat(listeners);
|
|
1149
942
|
});
|
|
1150
943
|
});
|
|
1151
944
|
_defineProperty(_this, "isMounted", function (atom) {
|
|
1152
|
-
var mountState = _this.
|
|
1153
|
-
return mountState.mounted !== undefined;
|
|
945
|
+
var mountState = _this.stateMap.get(atom);
|
|
946
|
+
return (mountState === null || mountState === void 0 ? void 0 : mountState.mounted) !== undefined;
|
|
1154
947
|
});
|
|
1155
948
|
return _this;
|
|
1156
949
|
}
|
|
@@ -1158,11 +951,7 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1158
951
|
return _createClass(DebugStoreImpl);
|
|
1159
952
|
}(StoreImpl);
|
|
1160
953
|
function createDebugStoreInternal(interceptor) {
|
|
1161
|
-
|
|
1162
|
-
interceptor: interceptor
|
|
1163
|
-
});
|
|
1164
|
-
var listenerManager = new ListenerManager();
|
|
1165
|
-
return new DebugStoreImpl(atomManager, listenerManager, {
|
|
954
|
+
return new DebugStoreImpl({
|
|
1166
955
|
interceptor: interceptor
|
|
1167
956
|
});
|
|
1168
957
|
}
|