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