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