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