ccstate 2.0.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/LICENSE +21 -0
- package/README.md +647 -0
- package/core/index.cjs +1022 -0
- package/core/index.d.cts +52 -0
- package/core/index.d.ts +52 -0
- package/core/index.js +1017 -0
- package/debug/index.cjs +1427 -0
- package/debug/index.d.cts +133 -0
- package/debug/index.d.ts +133 -0
- package/debug/index.js +1419 -0
- package/index.cjs +1598 -0
- package/index.d.cts +166 -0
- package/index.d.ts +166 -0
- package/index.js +1579 -0
- package/package.json +35 -0
- package/react/index.cjs +187 -0
- package/react/index.d.cts +67 -0
- package/react/index.d.ts +67 -0
- package/react/index.js +179 -0
package/debug/index.cjs
ADDED
|
@@ -0,0 +1,1427 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function nestedAtomToString(atoms) {
|
|
4
|
+
return atoms.map(function (atom) {
|
|
5
|
+
var _atom$debugLabel;
|
|
6
|
+
if (Array.isArray(atom)) {
|
|
7
|
+
return nestedAtomToString(atom);
|
|
8
|
+
}
|
|
9
|
+
return (_atom$debugLabel = atom.debugLabel) !== null && _atom$debugLabel !== void 0 ? _atom$debugLabel : 'anonymous';
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function _arrayLikeToArray(r, a) {
|
|
14
|
+
(null == a || a > r.length) && (a = r.length);
|
|
15
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
16
|
+
return n;
|
|
17
|
+
}
|
|
18
|
+
function _arrayWithHoles(r) {
|
|
19
|
+
if (Array.isArray(r)) return r;
|
|
20
|
+
}
|
|
21
|
+
function _arrayWithoutHoles(r) {
|
|
22
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
23
|
+
}
|
|
24
|
+
function _assertThisInitialized(e) {
|
|
25
|
+
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
26
|
+
return e;
|
|
27
|
+
}
|
|
28
|
+
function _callSuper(t, o, e) {
|
|
29
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
30
|
+
}
|
|
31
|
+
function _classCallCheck(a, n) {
|
|
32
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
function _construct(t, e, r) {
|
|
35
|
+
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
36
|
+
var o = [null];
|
|
37
|
+
o.push.apply(o, e);
|
|
38
|
+
var p = new (t.bind.apply(t, o))();
|
|
39
|
+
return r && _setPrototypeOf(p, r.prototype), p;
|
|
40
|
+
}
|
|
41
|
+
function _defineProperties(e, r) {
|
|
42
|
+
for (var t = 0; t < r.length; t++) {
|
|
43
|
+
var o = r[t];
|
|
44
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function _createClass(e, r, t) {
|
|
48
|
+
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
49
|
+
writable: !1
|
|
50
|
+
}), e;
|
|
51
|
+
}
|
|
52
|
+
function _createForOfIteratorHelper(r, e) {
|
|
53
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
54
|
+
if (!t) {
|
|
55
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
56
|
+
t && (r = t);
|
|
57
|
+
var n = 0,
|
|
58
|
+
F = function () {};
|
|
59
|
+
return {
|
|
60
|
+
s: F,
|
|
61
|
+
n: function () {
|
|
62
|
+
return n >= r.length ? {
|
|
63
|
+
done: !0
|
|
64
|
+
} : {
|
|
65
|
+
done: !1,
|
|
66
|
+
value: r[n++]
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
e: function (r) {
|
|
70
|
+
throw r;
|
|
71
|
+
},
|
|
72
|
+
f: F
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
76
|
+
}
|
|
77
|
+
var o,
|
|
78
|
+
a = !0,
|
|
79
|
+
u = !1;
|
|
80
|
+
return {
|
|
81
|
+
s: function () {
|
|
82
|
+
t = t.call(r);
|
|
83
|
+
},
|
|
84
|
+
n: function () {
|
|
85
|
+
var r = t.next();
|
|
86
|
+
return a = r.done, r;
|
|
87
|
+
},
|
|
88
|
+
e: function (r) {
|
|
89
|
+
u = !0, o = r;
|
|
90
|
+
},
|
|
91
|
+
f: function () {
|
|
92
|
+
try {
|
|
93
|
+
a || null == t.return || t.return();
|
|
94
|
+
} finally {
|
|
95
|
+
if (u) throw o;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function _defineProperty(e, r, t) {
|
|
101
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
102
|
+
value: t,
|
|
103
|
+
enumerable: !0,
|
|
104
|
+
configurable: !0,
|
|
105
|
+
writable: !0
|
|
106
|
+
}) : e[r] = t, e;
|
|
107
|
+
}
|
|
108
|
+
function _get() {
|
|
109
|
+
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
|
|
110
|
+
var p = _superPropBase(e, t);
|
|
111
|
+
if (p) {
|
|
112
|
+
var n = Object.getOwnPropertyDescriptor(p, t);
|
|
113
|
+
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
|
|
114
|
+
}
|
|
115
|
+
}, _get.apply(null, arguments);
|
|
116
|
+
}
|
|
117
|
+
function _getPrototypeOf(t) {
|
|
118
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
119
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
120
|
+
}, _getPrototypeOf(t);
|
|
121
|
+
}
|
|
122
|
+
function _inherits(t, e) {
|
|
123
|
+
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
124
|
+
t.prototype = Object.create(e && e.prototype, {
|
|
125
|
+
constructor: {
|
|
126
|
+
value: t,
|
|
127
|
+
writable: !0,
|
|
128
|
+
configurable: !0
|
|
129
|
+
}
|
|
130
|
+
}), Object.defineProperty(t, "prototype", {
|
|
131
|
+
writable: !1
|
|
132
|
+
}), e && _setPrototypeOf(t, e);
|
|
133
|
+
}
|
|
134
|
+
function _isNativeFunction(t) {
|
|
135
|
+
try {
|
|
136
|
+
return -1 !== Function.toString.call(t).indexOf("[native code]");
|
|
137
|
+
} catch (n) {
|
|
138
|
+
return "function" == typeof t;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function _isNativeReflectConstruct() {
|
|
142
|
+
try {
|
|
143
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
144
|
+
} catch (t) {}
|
|
145
|
+
return (_isNativeReflectConstruct = function () {
|
|
146
|
+
return !!t;
|
|
147
|
+
})();
|
|
148
|
+
}
|
|
149
|
+
function _iterableToArray(r) {
|
|
150
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
151
|
+
}
|
|
152
|
+
function _iterableToArrayLimit(r, l) {
|
|
153
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
154
|
+
if (null != t) {
|
|
155
|
+
var e,
|
|
156
|
+
n,
|
|
157
|
+
i,
|
|
158
|
+
u,
|
|
159
|
+
a = [],
|
|
160
|
+
f = !0,
|
|
161
|
+
o = !1;
|
|
162
|
+
try {
|
|
163
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
164
|
+
if (Object(t) !== t) return;
|
|
165
|
+
f = !1;
|
|
166
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
167
|
+
} catch (r) {
|
|
168
|
+
o = !0, n = r;
|
|
169
|
+
} finally {
|
|
170
|
+
try {
|
|
171
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
172
|
+
} finally {
|
|
173
|
+
if (o) throw n;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return a;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function _nonIterableRest() {
|
|
180
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
181
|
+
}
|
|
182
|
+
function _nonIterableSpread() {
|
|
183
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
184
|
+
}
|
|
185
|
+
function _possibleConstructorReturn(t, e) {
|
|
186
|
+
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
187
|
+
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
188
|
+
return _assertThisInitialized(t);
|
|
189
|
+
}
|
|
190
|
+
function _regeneratorRuntime() {
|
|
191
|
+
_regeneratorRuntime = function () {
|
|
192
|
+
return e;
|
|
193
|
+
};
|
|
194
|
+
var t,
|
|
195
|
+
e = {},
|
|
196
|
+
r = Object.prototype,
|
|
197
|
+
n = r.hasOwnProperty,
|
|
198
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
199
|
+
t[e] = r.value;
|
|
200
|
+
},
|
|
201
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
202
|
+
a = i.iterator || "@@iterator",
|
|
203
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
204
|
+
u = i.toStringTag || "@@toStringTag";
|
|
205
|
+
function define(t, e, r) {
|
|
206
|
+
return Object.defineProperty(t, e, {
|
|
207
|
+
value: r,
|
|
208
|
+
enumerable: !0,
|
|
209
|
+
configurable: !0,
|
|
210
|
+
writable: !0
|
|
211
|
+
}), t[e];
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
define({}, "");
|
|
215
|
+
} catch (t) {
|
|
216
|
+
define = function (t, e, r) {
|
|
217
|
+
return t[e] = r;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function wrap(t, e, r, n) {
|
|
221
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
222
|
+
a = Object.create(i.prototype),
|
|
223
|
+
c = new Context(n || []);
|
|
224
|
+
return o(a, "_invoke", {
|
|
225
|
+
value: makeInvokeMethod(t, r, c)
|
|
226
|
+
}), a;
|
|
227
|
+
}
|
|
228
|
+
function tryCatch(t, e, r) {
|
|
229
|
+
try {
|
|
230
|
+
return {
|
|
231
|
+
type: "normal",
|
|
232
|
+
arg: t.call(e, r)
|
|
233
|
+
};
|
|
234
|
+
} catch (t) {
|
|
235
|
+
return {
|
|
236
|
+
type: "throw",
|
|
237
|
+
arg: t
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
e.wrap = wrap;
|
|
242
|
+
var h = "suspendedStart",
|
|
243
|
+
l = "suspendedYield",
|
|
244
|
+
f = "executing",
|
|
245
|
+
s = "completed",
|
|
246
|
+
y = {};
|
|
247
|
+
function Generator() {}
|
|
248
|
+
function GeneratorFunction() {}
|
|
249
|
+
function GeneratorFunctionPrototype() {}
|
|
250
|
+
var p = {};
|
|
251
|
+
define(p, a, function () {
|
|
252
|
+
return this;
|
|
253
|
+
});
|
|
254
|
+
var d = Object.getPrototypeOf,
|
|
255
|
+
v = d && d(d(values([])));
|
|
256
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
257
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
258
|
+
function defineIteratorMethods(t) {
|
|
259
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
260
|
+
define(t, e, function (t) {
|
|
261
|
+
return this._invoke(e, t);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function AsyncIterator(t, e) {
|
|
266
|
+
function invoke(r, o, i, a) {
|
|
267
|
+
var c = tryCatch(t[r], t, o);
|
|
268
|
+
if ("throw" !== c.type) {
|
|
269
|
+
var u = c.arg,
|
|
270
|
+
h = u.value;
|
|
271
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
272
|
+
invoke("next", t, i, a);
|
|
273
|
+
}, function (t) {
|
|
274
|
+
invoke("throw", t, i, a);
|
|
275
|
+
}) : e.resolve(h).then(function (t) {
|
|
276
|
+
u.value = t, i(u);
|
|
277
|
+
}, function (t) {
|
|
278
|
+
return invoke("throw", t, i, a);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
a(c.arg);
|
|
282
|
+
}
|
|
283
|
+
var r;
|
|
284
|
+
o(this, "_invoke", {
|
|
285
|
+
value: function (t, n) {
|
|
286
|
+
function callInvokeWithMethodAndArg() {
|
|
287
|
+
return new e(function (e, r) {
|
|
288
|
+
invoke(t, n, e, r);
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function makeInvokeMethod(e, r, n) {
|
|
296
|
+
var o = h;
|
|
297
|
+
return function (i, a) {
|
|
298
|
+
if (o === f) throw Error("Generator is already running");
|
|
299
|
+
if (o === s) {
|
|
300
|
+
if ("throw" === i) throw a;
|
|
301
|
+
return {
|
|
302
|
+
value: t,
|
|
303
|
+
done: !0
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
for (n.method = i, n.arg = a;;) {
|
|
307
|
+
var c = n.delegate;
|
|
308
|
+
if (c) {
|
|
309
|
+
var u = maybeInvokeDelegate(c, n);
|
|
310
|
+
if (u) {
|
|
311
|
+
if (u === y) continue;
|
|
312
|
+
return u;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
316
|
+
if (o === h) throw o = s, n.arg;
|
|
317
|
+
n.dispatchException(n.arg);
|
|
318
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
319
|
+
o = f;
|
|
320
|
+
var p = tryCatch(e, r, n);
|
|
321
|
+
if ("normal" === p.type) {
|
|
322
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
323
|
+
return {
|
|
324
|
+
value: p.arg,
|
|
325
|
+
done: n.done
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function maybeInvokeDelegate(e, r) {
|
|
333
|
+
var n = r.method,
|
|
334
|
+
o = e.iterator[n];
|
|
335
|
+
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;
|
|
336
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
337
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
338
|
+
var a = i.arg;
|
|
339
|
+
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);
|
|
340
|
+
}
|
|
341
|
+
function pushTryEntry(t) {
|
|
342
|
+
var e = {
|
|
343
|
+
tryLoc: t[0]
|
|
344
|
+
};
|
|
345
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
346
|
+
}
|
|
347
|
+
function resetTryEntry(t) {
|
|
348
|
+
var e = t.completion || {};
|
|
349
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
350
|
+
}
|
|
351
|
+
function Context(t) {
|
|
352
|
+
this.tryEntries = [{
|
|
353
|
+
tryLoc: "root"
|
|
354
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
355
|
+
}
|
|
356
|
+
function values(e) {
|
|
357
|
+
if (e || "" === e) {
|
|
358
|
+
var r = e[a];
|
|
359
|
+
if (r) return r.call(e);
|
|
360
|
+
if ("function" == typeof e.next) return e;
|
|
361
|
+
if (!isNaN(e.length)) {
|
|
362
|
+
var o = -1,
|
|
363
|
+
i = function next() {
|
|
364
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
365
|
+
return next.value = t, next.done = !0, next;
|
|
366
|
+
};
|
|
367
|
+
return i.next = i;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
371
|
+
}
|
|
372
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
373
|
+
value: GeneratorFunctionPrototype,
|
|
374
|
+
configurable: !0
|
|
375
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
376
|
+
value: GeneratorFunction,
|
|
377
|
+
configurable: !0
|
|
378
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
379
|
+
var e = "function" == typeof t && t.constructor;
|
|
380
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
381
|
+
}, e.mark = function (t) {
|
|
382
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
383
|
+
}, e.awrap = function (t) {
|
|
384
|
+
return {
|
|
385
|
+
__await: t
|
|
386
|
+
};
|
|
387
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
388
|
+
return this;
|
|
389
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
390
|
+
void 0 === i && (i = Promise);
|
|
391
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
392
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
393
|
+
return t.done ? t.value : a.next();
|
|
394
|
+
});
|
|
395
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
396
|
+
return this;
|
|
397
|
+
}), define(g, "toString", function () {
|
|
398
|
+
return "[object Generator]";
|
|
399
|
+
}), e.keys = function (t) {
|
|
400
|
+
var e = Object(t),
|
|
401
|
+
r = [];
|
|
402
|
+
for (var n in e) r.push(n);
|
|
403
|
+
return r.reverse(), function next() {
|
|
404
|
+
for (; r.length;) {
|
|
405
|
+
var t = r.pop();
|
|
406
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
407
|
+
}
|
|
408
|
+
return next.done = !0, next;
|
|
409
|
+
};
|
|
410
|
+
}, e.values = values, Context.prototype = {
|
|
411
|
+
constructor: Context,
|
|
412
|
+
reset: function (e) {
|
|
413
|
+
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);
|
|
414
|
+
},
|
|
415
|
+
stop: function () {
|
|
416
|
+
this.done = !0;
|
|
417
|
+
var t = this.tryEntries[0].completion;
|
|
418
|
+
if ("throw" === t.type) throw t.arg;
|
|
419
|
+
return this.rval;
|
|
420
|
+
},
|
|
421
|
+
dispatchException: function (e) {
|
|
422
|
+
if (this.done) throw e;
|
|
423
|
+
var r = this;
|
|
424
|
+
function handle(n, o) {
|
|
425
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
426
|
+
}
|
|
427
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
428
|
+
var i = this.tryEntries[o],
|
|
429
|
+
a = i.completion;
|
|
430
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
431
|
+
if (i.tryLoc <= this.prev) {
|
|
432
|
+
var c = n.call(i, "catchLoc"),
|
|
433
|
+
u = n.call(i, "finallyLoc");
|
|
434
|
+
if (c && u) {
|
|
435
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
436
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
437
|
+
} else if (c) {
|
|
438
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
439
|
+
} else {
|
|
440
|
+
if (!u) throw Error("try statement without catch or finally");
|
|
441
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
abrupt: function (t, e) {
|
|
447
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
448
|
+
var o = this.tryEntries[r];
|
|
449
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
450
|
+
var i = o;
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
455
|
+
var a = i ? i.completion : {};
|
|
456
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
457
|
+
},
|
|
458
|
+
complete: function (t, e) {
|
|
459
|
+
if ("throw" === t.type) throw t.arg;
|
|
460
|
+
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;
|
|
461
|
+
},
|
|
462
|
+
finish: function (t) {
|
|
463
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
464
|
+
var r = this.tryEntries[e];
|
|
465
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
catch: function (t) {
|
|
469
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
470
|
+
var r = this.tryEntries[e];
|
|
471
|
+
if (r.tryLoc === t) {
|
|
472
|
+
var n = r.completion;
|
|
473
|
+
if ("throw" === n.type) {
|
|
474
|
+
var o = n.arg;
|
|
475
|
+
resetTryEntry(r);
|
|
476
|
+
}
|
|
477
|
+
return o;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
throw Error("illegal catch attempt");
|
|
481
|
+
},
|
|
482
|
+
delegateYield: function (e, r, n) {
|
|
483
|
+
return this.delegate = {
|
|
484
|
+
iterator: values(e),
|
|
485
|
+
resultName: r,
|
|
486
|
+
nextLoc: n
|
|
487
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
488
|
+
}
|
|
489
|
+
}, e;
|
|
490
|
+
}
|
|
491
|
+
function _setPrototypeOf(t, e) {
|
|
492
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
493
|
+
return t.__proto__ = e, t;
|
|
494
|
+
}, _setPrototypeOf(t, e);
|
|
495
|
+
}
|
|
496
|
+
function _slicedToArray(r, e) {
|
|
497
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
498
|
+
}
|
|
499
|
+
function _superPropBase(t, o) {
|
|
500
|
+
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
|
|
501
|
+
return t;
|
|
502
|
+
}
|
|
503
|
+
function _superPropGet(t, o, e, r) {
|
|
504
|
+
var p = _get(_getPrototypeOf(t.prototype ), o, e);
|
|
505
|
+
return "function" == typeof p ? function (t) {
|
|
506
|
+
return p.apply(e, t);
|
|
507
|
+
} : p;
|
|
508
|
+
}
|
|
509
|
+
function _toConsumableArray(r) {
|
|
510
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
511
|
+
}
|
|
512
|
+
function _toPrimitive(t, r) {
|
|
513
|
+
if ("object" != typeof t || !t) return t;
|
|
514
|
+
var e = t[Symbol.toPrimitive];
|
|
515
|
+
if (void 0 !== e) {
|
|
516
|
+
var i = e.call(t, r || "default");
|
|
517
|
+
if ("object" != typeof i) return i;
|
|
518
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
519
|
+
}
|
|
520
|
+
return ("string" === r ? String : Number)(t);
|
|
521
|
+
}
|
|
522
|
+
function _toPropertyKey(t) {
|
|
523
|
+
var i = _toPrimitive(t, "string");
|
|
524
|
+
return "symbol" == typeof i ? i : i + "";
|
|
525
|
+
}
|
|
526
|
+
function _typeof(o) {
|
|
527
|
+
"@babel/helpers - typeof";
|
|
528
|
+
|
|
529
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
530
|
+
return typeof o;
|
|
531
|
+
} : function (o) {
|
|
532
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
533
|
+
}, _typeof(o);
|
|
534
|
+
}
|
|
535
|
+
function _unsupportedIterableToArray(r, a) {
|
|
536
|
+
if (r) {
|
|
537
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
538
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
539
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
function _wrapNativeSuper(t) {
|
|
543
|
+
var r = "function" == typeof Map ? new Map() : void 0;
|
|
544
|
+
return _wrapNativeSuper = function (t) {
|
|
545
|
+
if (null === t || !_isNativeFunction(t)) return t;
|
|
546
|
+
if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
|
|
547
|
+
if (void 0 !== r) {
|
|
548
|
+
if (r.has(t)) return r.get(t);
|
|
549
|
+
r.set(t, Wrapper);
|
|
550
|
+
}
|
|
551
|
+
function Wrapper() {
|
|
552
|
+
return _construct(t, arguments, _getPrototypeOf(this).constructor);
|
|
553
|
+
}
|
|
554
|
+
return Wrapper.prototype = Object.create(t.prototype, {
|
|
555
|
+
constructor: {
|
|
556
|
+
value: Wrapper,
|
|
557
|
+
enumerable: !1,
|
|
558
|
+
writable: !0,
|
|
559
|
+
configurable: !0
|
|
560
|
+
}
|
|
561
|
+
}), _setPrototypeOf(Wrapper, t);
|
|
562
|
+
}, _wrapNativeSuper(t);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function canReadAsCompute(atom) {
|
|
566
|
+
return 'read' in atom;
|
|
567
|
+
}
|
|
568
|
+
function isComputedState(state) {
|
|
569
|
+
return 'dependencies' in state;
|
|
570
|
+
}
|
|
571
|
+
var AtomManager = /*#__PURE__*/function () {
|
|
572
|
+
function AtomManager(options) {
|
|
573
|
+
var _this = this;
|
|
574
|
+
_classCallCheck(this, AtomManager);
|
|
575
|
+
_defineProperty(this, "atomStateMap", new WeakMap());
|
|
576
|
+
_defineProperty(this, "tryGetCachedState", function (atom, ignoreMounted) {
|
|
577
|
+
var atomState = _this.atomStateMap.get(atom);
|
|
578
|
+
if (!atomState) {
|
|
579
|
+
return undefined;
|
|
580
|
+
}
|
|
581
|
+
if (atomState.mounted && !ignoreMounted) {
|
|
582
|
+
return atomState;
|
|
583
|
+
}
|
|
584
|
+
var _iterator = _createForOfIteratorHelper(atomState.dependencies.entries()),
|
|
585
|
+
_step;
|
|
586
|
+
try {
|
|
587
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
588
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
589
|
+
dep = _step$value[0],
|
|
590
|
+
epoch = _step$value[1];
|
|
591
|
+
var depState = _this.readAtomState(dep);
|
|
592
|
+
if (depState.epoch !== epoch) {
|
|
593
|
+
return undefined;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
} catch (err) {
|
|
597
|
+
_iterator.e(err);
|
|
598
|
+
} finally {
|
|
599
|
+
_iterator.f();
|
|
600
|
+
}
|
|
601
|
+
return atomState;
|
|
602
|
+
});
|
|
603
|
+
this.options = options;
|
|
604
|
+
}
|
|
605
|
+
return _createClass(AtomManager, [{
|
|
606
|
+
key: "readComputedAtom",
|
|
607
|
+
value: function readComputedAtom(atom) {
|
|
608
|
+
var _this$options,
|
|
609
|
+
_this2 = this;
|
|
610
|
+
var ignoreMounted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
611
|
+
var cachedState = this.tryGetCachedState(atom, ignoreMounted);
|
|
612
|
+
if (cachedState) {
|
|
613
|
+
return cachedState;
|
|
614
|
+
}
|
|
615
|
+
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;
|
|
616
|
+
if (!computedInterceptor) {
|
|
617
|
+
return this.computeComputedAtom(atom);
|
|
618
|
+
}
|
|
619
|
+
var result = {
|
|
620
|
+
called: false
|
|
621
|
+
};
|
|
622
|
+
computedInterceptor(atom, function () {
|
|
623
|
+
result = {
|
|
624
|
+
called: true,
|
|
625
|
+
data: _this2.computeComputedAtom(atom)
|
|
626
|
+
};
|
|
627
|
+
return result.data.val;
|
|
628
|
+
});
|
|
629
|
+
if (!result.called) {
|
|
630
|
+
throw new Error('interceptor must call fn sync');
|
|
631
|
+
}
|
|
632
|
+
return result.data;
|
|
633
|
+
}
|
|
634
|
+
}, {
|
|
635
|
+
key: "computeComputedAtom",
|
|
636
|
+
value: function computeComputedAtom(atom) {
|
|
637
|
+
var _this3 = this,
|
|
638
|
+
_this$options2;
|
|
639
|
+
var self = atom;
|
|
640
|
+
var atomState = this.atomStateMap.get(self);
|
|
641
|
+
if (!atomState) {
|
|
642
|
+
atomState = {
|
|
643
|
+
dependencies: new Map(),
|
|
644
|
+
epoch: -1
|
|
645
|
+
};
|
|
646
|
+
this.atomStateMap.set(self, atomState);
|
|
647
|
+
}
|
|
648
|
+
var lastDeps = atomState.dependencies;
|
|
649
|
+
var readDeps = new Map();
|
|
650
|
+
atomState.dependencies = readDeps;
|
|
651
|
+
var wrappedGet = function wrappedGet(depAtom) {
|
|
652
|
+
var depState = _this3.readAtomState(depAtom);
|
|
653
|
+
|
|
654
|
+
// get 可能发生在异步过程中,当重复调用时,只有最新的 get 过程会修改 deps
|
|
655
|
+
if (atomState.dependencies === readDeps) {
|
|
656
|
+
readDeps.set(depAtom, depState.epoch);
|
|
657
|
+
var selfMounted = !!atomState.mounted;
|
|
658
|
+
if (selfMounted && !depState.mounted) {
|
|
659
|
+
_this3.mount(depAtom).readDepts.add(self);
|
|
660
|
+
} else if (selfMounted && depState.mounted) {
|
|
661
|
+
depState.mounted.readDepts.add(self);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return depState.val;
|
|
665
|
+
};
|
|
666
|
+
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;
|
|
667
|
+
var ret = self.read(function (depAtom) {
|
|
668
|
+
if (!getInterceptor) {
|
|
669
|
+
return wrappedGet(depAtom);
|
|
670
|
+
}
|
|
671
|
+
var result = {
|
|
672
|
+
called: false
|
|
673
|
+
};
|
|
674
|
+
var fn = function fn() {
|
|
675
|
+
result = {
|
|
676
|
+
called: true,
|
|
677
|
+
data: wrappedGet(depAtom)
|
|
678
|
+
};
|
|
679
|
+
return result.data;
|
|
680
|
+
};
|
|
681
|
+
getInterceptor(depAtom, fn);
|
|
682
|
+
if (!result.called) {
|
|
683
|
+
throw new Error('interceptor must call fn sync');
|
|
684
|
+
}
|
|
685
|
+
return result.data;
|
|
686
|
+
}, {
|
|
687
|
+
get signal() {
|
|
688
|
+
var _atomState$abortContr, _self$debugLabel;
|
|
689
|
+
(_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"));
|
|
690
|
+
atomState.abortController = new AbortController();
|
|
691
|
+
return atomState.abortController.signal;
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
if (atomState.val !== ret) {
|
|
695
|
+
atomState.val = ret;
|
|
696
|
+
atomState.epoch += 1;
|
|
697
|
+
}
|
|
698
|
+
var _iterator2 = _createForOfIteratorHelper(lastDeps.keys()),
|
|
699
|
+
_step2;
|
|
700
|
+
try {
|
|
701
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
702
|
+
var key = _step2.value;
|
|
703
|
+
if (!readDeps.has(key)) {
|
|
704
|
+
var depState = this.atomStateMap.get(key);
|
|
705
|
+
if (depState !== null && depState !== void 0 && depState.mounted) {
|
|
706
|
+
depState.mounted.readDepts["delete"](self);
|
|
707
|
+
this.tryUnmount(key);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
} catch (err) {
|
|
712
|
+
_iterator2.e(err);
|
|
713
|
+
} finally {
|
|
714
|
+
_iterator2.f();
|
|
715
|
+
}
|
|
716
|
+
return atomState;
|
|
717
|
+
}
|
|
718
|
+
}, {
|
|
719
|
+
key: "readStateAtom",
|
|
720
|
+
value: function readStateAtom(atom) {
|
|
721
|
+
var atomState = this.atomStateMap.get(atom);
|
|
722
|
+
if (!atomState) {
|
|
723
|
+
var initState = {
|
|
724
|
+
val: atom.init,
|
|
725
|
+
epoch: 0
|
|
726
|
+
};
|
|
727
|
+
this.atomStateMap.set(atom, initState);
|
|
728
|
+
return initState;
|
|
729
|
+
}
|
|
730
|
+
return atomState;
|
|
731
|
+
}
|
|
732
|
+
}, {
|
|
733
|
+
key: "readAtomState",
|
|
734
|
+
value: function readAtomState(atom) {
|
|
735
|
+
var ignoreMounted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
736
|
+
if (canReadAsCompute(atom)) {
|
|
737
|
+
return this.readComputedAtom(atom, ignoreMounted);
|
|
738
|
+
}
|
|
739
|
+
return this.readStateAtom(atom);
|
|
740
|
+
}
|
|
741
|
+
}, {
|
|
742
|
+
key: "tryGetMount",
|
|
743
|
+
value: function tryGetMount(atom) {
|
|
744
|
+
var _this$atomStateMap$ge;
|
|
745
|
+
return (_this$atomStateMap$ge = this.atomStateMap.get(atom)) === null || _this$atomStateMap$ge === void 0 ? void 0 : _this$atomStateMap$ge.mounted;
|
|
746
|
+
}
|
|
747
|
+
}, {
|
|
748
|
+
key: "mount",
|
|
749
|
+
value: function mount(atom) {
|
|
750
|
+
var _this$options3, _this$options3$mount, _atomState$mounted;
|
|
751
|
+
var mounted = this.tryGetMount(atom);
|
|
752
|
+
if (mounted) {
|
|
753
|
+
return mounted;
|
|
754
|
+
}
|
|
755
|
+
(_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);
|
|
756
|
+
var atomState = this.readAtomState(atom);
|
|
757
|
+
atomState.mounted = (_atomState$mounted = atomState.mounted) !== null && _atomState$mounted !== void 0 ? _atomState$mounted : {
|
|
758
|
+
listeners: new Set(),
|
|
759
|
+
readDepts: new Set()
|
|
760
|
+
};
|
|
761
|
+
if (isComputedState(atomState)) {
|
|
762
|
+
for (var _i = 0, _Array$from = Array.from(atomState.dependencies); _i < _Array$from.length; _i++) {
|
|
763
|
+
var _Array$from$_i = _slicedToArray(_Array$from[_i], 1),
|
|
764
|
+
dep = _Array$from$_i[0];
|
|
765
|
+
var _mounted = this.mount(dep);
|
|
766
|
+
_mounted.readDepts.add(atom);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return atomState.mounted;
|
|
770
|
+
}
|
|
771
|
+
}, {
|
|
772
|
+
key: "tryUnmount",
|
|
773
|
+
value: function tryUnmount(atom) {
|
|
774
|
+
var _this$options4, _this$options4$unmoun;
|
|
775
|
+
var atomState = this.atomStateMap.get(atom);
|
|
776
|
+
if (!(atomState !== null && atomState !== void 0 && atomState.mounted) || atomState.mounted.listeners.size || atomState.mounted.readDepts.size) {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
(_this$options4 = this.options) === null || _this$options4 === void 0 || (_this$options4 = _this$options4.interceptor) === null || _this$options4 === void 0 || (_this$options4$unmoun = _this$options4.unmount) === null || _this$options4$unmoun === void 0 || _this$options4$unmoun.call(_this$options4, atom);
|
|
780
|
+
if (isComputedState(atomState)) {
|
|
781
|
+
for (var _i2 = 0, _Array$from2 = Array.from(atomState.dependencies); _i2 < _Array$from2.length; _i2++) {
|
|
782
|
+
var _depState$mounted;
|
|
783
|
+
var _Array$from2$_i = _slicedToArray(_Array$from2[_i2], 1),
|
|
784
|
+
dep = _Array$from2$_i[0];
|
|
785
|
+
var depState = this.readAtomState(dep);
|
|
786
|
+
(_depState$mounted = depState.mounted) === null || _depState$mounted === void 0 || _depState$mounted.readDepts["delete"](atom);
|
|
787
|
+
this.tryUnmount(dep);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
atomState.mounted = undefined;
|
|
791
|
+
}
|
|
792
|
+
}, {
|
|
793
|
+
key: "inited",
|
|
794
|
+
value: function inited(atom) {
|
|
795
|
+
return this.atomStateMap.has(atom);
|
|
796
|
+
}
|
|
797
|
+
}]);
|
|
798
|
+
}();
|
|
799
|
+
var ListenerManager = /*#__PURE__*/function () {
|
|
800
|
+
function ListenerManager() {
|
|
801
|
+
_classCallCheck(this, ListenerManager);
|
|
802
|
+
_defineProperty(this, "pendingListeners", new Set());
|
|
803
|
+
}
|
|
804
|
+
return _createClass(ListenerManager, [{
|
|
805
|
+
key: "markPendingListeners",
|
|
806
|
+
value: function markPendingListeners(atomManager, atom) {
|
|
807
|
+
var queue = [atom];
|
|
808
|
+
while (queue.length > 0) {
|
|
809
|
+
var nextQueue = [];
|
|
810
|
+
var _iterator3 = _createForOfIteratorHelper(queue),
|
|
811
|
+
_step3;
|
|
812
|
+
try {
|
|
813
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
814
|
+
var _atomState$mounted2, _atomState$mounted3;
|
|
815
|
+
var _atom = _step3.value;
|
|
816
|
+
var atomState = atomManager.readAtomState(_atom, true);
|
|
817
|
+
if ((_atomState$mounted2 = atomState.mounted) !== null && _atomState$mounted2 !== void 0 && _atomState$mounted2.listeners) {
|
|
818
|
+
var _iterator4 = _createForOfIteratorHelper(atomState.mounted.listeners),
|
|
819
|
+
_step4;
|
|
820
|
+
try {
|
|
821
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
822
|
+
var listener = _step4.value;
|
|
823
|
+
this.pendingListeners.add(listener);
|
|
824
|
+
}
|
|
825
|
+
} catch (err) {
|
|
826
|
+
_iterator4.e(err);
|
|
827
|
+
} finally {
|
|
828
|
+
_iterator4.f();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
var readDepts = (_atomState$mounted3 = atomState.mounted) === null || _atomState$mounted3 === void 0 ? void 0 : _atomState$mounted3.readDepts;
|
|
832
|
+
if (readDepts) {
|
|
833
|
+
for (var _i3 = 0, _Array$from3 = Array.from(readDepts); _i3 < _Array$from3.length; _i3++) {
|
|
834
|
+
var dep = _Array$from3[_i3];
|
|
835
|
+
nextQueue.push(dep);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
} catch (err) {
|
|
840
|
+
_iterator3.e(err);
|
|
841
|
+
} finally {
|
|
842
|
+
_iterator3.f();
|
|
843
|
+
}
|
|
844
|
+
queue = nextQueue;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}, {
|
|
848
|
+
key: "notify",
|
|
849
|
+
value: /*#__PURE__*/_regeneratorRuntime().mark(function notify() {
|
|
850
|
+
var pendingListeners, _iterator5, _step5, listener;
|
|
851
|
+
return _regeneratorRuntime().wrap(function notify$(_context) {
|
|
852
|
+
while (1) switch (_context.prev = _context.next) {
|
|
853
|
+
case 0:
|
|
854
|
+
pendingListeners = this.pendingListeners;
|
|
855
|
+
this.pendingListeners = new Set();
|
|
856
|
+
_iterator5 = _createForOfIteratorHelper(pendingListeners);
|
|
857
|
+
_context.prev = 3;
|
|
858
|
+
_iterator5.s();
|
|
859
|
+
case 5:
|
|
860
|
+
if ((_step5 = _iterator5.n()).done) {
|
|
861
|
+
_context.next = 11;
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
listener = _step5.value;
|
|
865
|
+
_context.next = 9;
|
|
866
|
+
return listener;
|
|
867
|
+
case 9:
|
|
868
|
+
_context.next = 5;
|
|
869
|
+
break;
|
|
870
|
+
case 11:
|
|
871
|
+
_context.next = 16;
|
|
872
|
+
break;
|
|
873
|
+
case 13:
|
|
874
|
+
_context.prev = 13;
|
|
875
|
+
_context.t0 = _context["catch"](3);
|
|
876
|
+
_iterator5.e(_context.t0);
|
|
877
|
+
case 16:
|
|
878
|
+
_context.prev = 16;
|
|
879
|
+
_iterator5.f();
|
|
880
|
+
return _context.finish(16);
|
|
881
|
+
case 19:
|
|
882
|
+
case "end":
|
|
883
|
+
return _context.stop();
|
|
884
|
+
}
|
|
885
|
+
}, notify, this, [[3, 13, 16, 19]]);
|
|
886
|
+
})
|
|
887
|
+
}]);
|
|
888
|
+
}();
|
|
889
|
+
|
|
890
|
+
var StoreImpl = /*#__PURE__*/function () {
|
|
891
|
+
function StoreImpl(atomManager, listenerManager, options) {
|
|
892
|
+
var _this = this;
|
|
893
|
+
_classCallCheck(this, StoreImpl);
|
|
894
|
+
_defineProperty(this, "innerSet", function (atom) {
|
|
895
|
+
if ('read' in atom) {
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
899
|
+
args[_key - 1] = arguments[_key];
|
|
900
|
+
}
|
|
901
|
+
if ('write' in atom) {
|
|
902
|
+
var ret = atom.write.apply(atom, [{
|
|
903
|
+
get: _this.get,
|
|
904
|
+
set: _this.set
|
|
905
|
+
}].concat(_toConsumableArray(args)));
|
|
906
|
+
return ret;
|
|
907
|
+
}
|
|
908
|
+
var newValue = typeof args[0] === 'function' ? args[0](_this.atomManager.readAtomState(atom).val) : args[0];
|
|
909
|
+
if (!_this.atomManager.inited(atom)) {
|
|
910
|
+
_this.atomManager.readAtomState(atom).val = newValue;
|
|
911
|
+
_this.listenerManager.markPendingListeners(_this.atomManager, atom);
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
var atomState = _this.atomManager.readAtomState(atom);
|
|
915
|
+
atomState.val = newValue;
|
|
916
|
+
atomState.epoch += 1;
|
|
917
|
+
_this.listenerManager.markPendingListeners(_this.atomManager, atom);
|
|
918
|
+
return undefined;
|
|
919
|
+
});
|
|
920
|
+
_defineProperty(this, "get", function (atom) {
|
|
921
|
+
var _this$options;
|
|
922
|
+
if (!((_this$options = _this.options) !== null && _this$options !== void 0 && (_this$options = _this$options.interceptor) !== null && _this$options !== void 0 && _this$options.get)) {
|
|
923
|
+
return _this.atomManager.readAtomState(atom).val;
|
|
924
|
+
}
|
|
925
|
+
var result = {
|
|
926
|
+
called: false
|
|
927
|
+
};
|
|
928
|
+
var fnWithRet = function fnWithRet() {
|
|
929
|
+
result = {
|
|
930
|
+
called: true,
|
|
931
|
+
data: _this.atomManager.readAtomState(atom).val
|
|
932
|
+
};
|
|
933
|
+
return result.data;
|
|
934
|
+
};
|
|
935
|
+
_this.options.interceptor.get(atom, fnWithRet);
|
|
936
|
+
if (!result.called) {
|
|
937
|
+
throw new Error('interceptor must call fn sync');
|
|
938
|
+
}
|
|
939
|
+
return result.data;
|
|
940
|
+
});
|
|
941
|
+
_defineProperty(this, "notify", function () {
|
|
942
|
+
var _iterator = _createForOfIteratorHelper(_this.listenerManager.notify()),
|
|
943
|
+
_step;
|
|
944
|
+
try {
|
|
945
|
+
var _loop = function _loop() {
|
|
946
|
+
var _this$options2;
|
|
947
|
+
var listener = _step.value;
|
|
948
|
+
var notifyed = false;
|
|
949
|
+
var fn = function fn() {
|
|
950
|
+
notifyed = true;
|
|
951
|
+
return listener.write({
|
|
952
|
+
get: _this.get,
|
|
953
|
+
set: _this.set
|
|
954
|
+
});
|
|
955
|
+
};
|
|
956
|
+
if ((_this$options2 = _this.options) !== null && _this$options2 !== void 0 && (_this$options2 = _this$options2.interceptor) !== null && _this$options2 !== void 0 && _this$options2.notify) {
|
|
957
|
+
_this.options.interceptor.notify(listener, fn);
|
|
958
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- notify must call fn sync
|
|
959
|
+
if (!notifyed) {
|
|
960
|
+
throw new Error('interceptor must call fn sync');
|
|
961
|
+
}
|
|
962
|
+
} else {
|
|
963
|
+
fn();
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
967
|
+
_loop();
|
|
968
|
+
}
|
|
969
|
+
} catch (err) {
|
|
970
|
+
_iterator.e(err);
|
|
971
|
+
} finally {
|
|
972
|
+
_iterator.f();
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
_defineProperty(this, "set", function (atom) {
|
|
976
|
+
var _this$options3;
|
|
977
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
978
|
+
args[_key2 - 1] = arguments[_key2];
|
|
979
|
+
}
|
|
980
|
+
var ret;
|
|
981
|
+
var fn = function fn() {
|
|
982
|
+
try {
|
|
983
|
+
ret = _this.innerSet.apply(_this, [atom].concat(args));
|
|
984
|
+
} finally {
|
|
985
|
+
_this.notify();
|
|
986
|
+
}
|
|
987
|
+
return ret;
|
|
988
|
+
};
|
|
989
|
+
if ((_this$options3 = _this.options) !== null && _this$options3 !== void 0 && (_this$options3 = _this$options3.interceptor) !== null && _this$options3 !== void 0 && _this$options3.set) {
|
|
990
|
+
if ('write' in atom) {
|
|
991
|
+
var _this$options$interce;
|
|
992
|
+
(_this$options$interce = _this.options.interceptor).set.apply(_this$options$interce, [atom, fn].concat(_toConsumableArray(args)));
|
|
993
|
+
} else {
|
|
994
|
+
_this.options.interceptor.set(atom, fn, args[0]);
|
|
995
|
+
}
|
|
996
|
+
} else {
|
|
997
|
+
fn();
|
|
998
|
+
}
|
|
999
|
+
return ret;
|
|
1000
|
+
});
|
|
1001
|
+
this.atomManager = atomManager;
|
|
1002
|
+
this.listenerManager = listenerManager;
|
|
1003
|
+
this.options = options;
|
|
1004
|
+
}
|
|
1005
|
+
return _createClass(StoreImpl, [{
|
|
1006
|
+
key: "_subSingleAtom",
|
|
1007
|
+
value: function _subSingleAtom(target$, cb$, options) {
|
|
1008
|
+
var _this2 = this,
|
|
1009
|
+
_this$options4;
|
|
1010
|
+
var unsub;
|
|
1011
|
+
var _fn2 = function fn() {
|
|
1012
|
+
var _options$signal2;
|
|
1013
|
+
var subscribed = true;
|
|
1014
|
+
var mounted = _this2.atomManager.mount(target$);
|
|
1015
|
+
mounted.listeners.add(cb$);
|
|
1016
|
+
unsub = function unsub() {
|
|
1017
|
+
var _this2$options;
|
|
1018
|
+
if (!subscribed) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
var _fn = function fn() {
|
|
1022
|
+
var _options$signal;
|
|
1023
|
+
subscribed = false;
|
|
1024
|
+
mounted.listeners["delete"](cb$);
|
|
1025
|
+
if (mounted.readDepts.size === 0 && mounted.listeners.size === 0) {
|
|
1026
|
+
_this2.atomManager.tryUnmount(target$);
|
|
1027
|
+
}
|
|
1028
|
+
options === null || options === void 0 || (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener('abort', _fn);
|
|
1029
|
+
};
|
|
1030
|
+
if ((_this2$options = _this2.options) !== null && _this2$options !== void 0 && (_this2$options = _this2$options.interceptor) !== null && _this2$options !== void 0 && _this2$options.unsub) {
|
|
1031
|
+
_this2.options.interceptor.unsub(target$, cb$, _fn);
|
|
1032
|
+
|
|
1033
|
+
// subscribed should be false if interceptor called fn sync
|
|
1034
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1035
|
+
if (subscribed) {
|
|
1036
|
+
throw new Error('interceptor must call fn sync');
|
|
1037
|
+
}
|
|
1038
|
+
} else {
|
|
1039
|
+
_fn();
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
options === null || options === void 0 || (_options$signal2 = options.signal) === null || _options$signal2 === void 0 || _options$signal2.addEventListener('abort', unsub);
|
|
1043
|
+
};
|
|
1044
|
+
if ((_this$options4 = this.options) !== null && _this$options4 !== void 0 && (_this$options4 = _this$options4.interceptor) !== null && _this$options4 !== void 0 && _this$options4.sub) {
|
|
1045
|
+
this.options.interceptor.sub(target$, cb$, _fn2);
|
|
1046
|
+
} else {
|
|
1047
|
+
_fn2();
|
|
1048
|
+
}
|
|
1049
|
+
if (!unsub) {
|
|
1050
|
+
throw new Error('interceptor must call fn sync');
|
|
1051
|
+
}
|
|
1052
|
+
return unsub;
|
|
1053
|
+
}
|
|
1054
|
+
}, {
|
|
1055
|
+
key: "sub",
|
|
1056
|
+
value: function sub(targets$, cb$, options) {
|
|
1057
|
+
var _this3 = this;
|
|
1058
|
+
if (Array.isArray(targets$) && targets$.length === 0) {
|
|
1059
|
+
return function () {
|
|
1060
|
+
return void 0;
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
if (Array.isArray(targets$) && targets$.length === 1) {
|
|
1064
|
+
return this._subSingleAtom(targets$[0], cb$, options);
|
|
1065
|
+
} else if (!Array.isArray(targets$)) {
|
|
1066
|
+
return this._subSingleAtom(targets$, cb$, options);
|
|
1067
|
+
}
|
|
1068
|
+
var unsubscribes = new Set();
|
|
1069
|
+
targets$.forEach(function (atom) {
|
|
1070
|
+
unsubscribes.add(_this3._subSingleAtom(atom, cb$, options));
|
|
1071
|
+
});
|
|
1072
|
+
var unsub = function unsub() {
|
|
1073
|
+
var _iterator2 = _createForOfIteratorHelper(unsubscribes),
|
|
1074
|
+
_step2;
|
|
1075
|
+
try {
|
|
1076
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1077
|
+
var unsubscribe = _step2.value;
|
|
1078
|
+
unsubscribe();
|
|
1079
|
+
}
|
|
1080
|
+
} catch (err) {
|
|
1081
|
+
_iterator2.e(err);
|
|
1082
|
+
} finally {
|
|
1083
|
+
_iterator2.f();
|
|
1084
|
+
}
|
|
1085
|
+
};
|
|
1086
|
+
return unsub;
|
|
1087
|
+
}
|
|
1088
|
+
}]);
|
|
1089
|
+
}();
|
|
1090
|
+
|
|
1091
|
+
var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
1092
|
+
function DebugStoreImpl() {
|
|
1093
|
+
var _this;
|
|
1094
|
+
_classCallCheck(this, DebugStoreImpl);
|
|
1095
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1096
|
+
args[_key] = arguments[_key];
|
|
1097
|
+
}
|
|
1098
|
+
_this = _callSuper(this, DebugStoreImpl, [].concat(args));
|
|
1099
|
+
_defineProperty(_this, "mountedAtomListenersCount", new Map());
|
|
1100
|
+
_defineProperty(_this, "sub", function (atoms, cb, options) {
|
|
1101
|
+
var _options$signal;
|
|
1102
|
+
var atomList = Array.isArray(atoms) ? atoms : [atoms];
|
|
1103
|
+
atomList.forEach(function (atom) {
|
|
1104
|
+
var _this$mountedAtomList;
|
|
1105
|
+
_this.mountedAtomListenersCount.set(atom, ((_this$mountedAtomList = _this.mountedAtomListenersCount.get(atom)) !== null && _this$mountedAtomList !== void 0 ? _this$mountedAtomList : 0) + 1);
|
|
1106
|
+
});
|
|
1107
|
+
var unsub = _superPropGet((DebugStoreImpl), "sub", _this)([atoms, cb, options]);
|
|
1108
|
+
var decount = function decount() {
|
|
1109
|
+
atomList.forEach(function (atom) {
|
|
1110
|
+
var _this$mountedAtomList2;
|
|
1111
|
+
var count = (_this$mountedAtomList2 = _this.mountedAtomListenersCount.get(atom)) !== null && _this$mountedAtomList2 !== void 0 ? _this$mountedAtomList2 : 0;
|
|
1112
|
+
if (count === 0) {
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
_this.mountedAtomListenersCount.set(atom, count - 1);
|
|
1116
|
+
if (count === 1) {
|
|
1117
|
+
_this.mountedAtomListenersCount["delete"](atom);
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
};
|
|
1121
|
+
options === null || options === void 0 || (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener('abort', decount);
|
|
1122
|
+
return function () {
|
|
1123
|
+
unsub();
|
|
1124
|
+
decount();
|
|
1125
|
+
};
|
|
1126
|
+
});
|
|
1127
|
+
_defineProperty(_this, "getReadDependencies", function (atom) {
|
|
1128
|
+
var atomState = _this.atomManager.readAtomState(atom);
|
|
1129
|
+
if (!('dependencies' in atomState)) {
|
|
1130
|
+
return [atom];
|
|
1131
|
+
}
|
|
1132
|
+
return [atom].concat(_toConsumableArray(Array.from(atomState.dependencies).map(function (_ref) {
|
|
1133
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
1134
|
+
key = _ref2[0];
|
|
1135
|
+
return _this.getReadDependencies(key);
|
|
1136
|
+
})));
|
|
1137
|
+
});
|
|
1138
|
+
_defineProperty(_this, "getReadDependents", function (atom) {
|
|
1139
|
+
var _atomState$mounted$re, _atomState$mounted;
|
|
1140
|
+
var atomState = _this.atomManager.readAtomState(atom);
|
|
1141
|
+
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) {
|
|
1142
|
+
return _this.getReadDependents(key);
|
|
1143
|
+
})));
|
|
1144
|
+
});
|
|
1145
|
+
_defineProperty(_this, "getSubscribeGraph", function () {
|
|
1146
|
+
var subscribedAtoms = Array.from(_this.mountedAtomListenersCount.keys());
|
|
1147
|
+
return subscribedAtoms.map(function (atom) {
|
|
1148
|
+
var atomState = _this.atomManager.readAtomState(atom);
|
|
1149
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know it's mounted
|
|
1150
|
+
var listeners = Array.from(atomState.mounted.listeners);
|
|
1151
|
+
return [atom].concat(listeners);
|
|
1152
|
+
});
|
|
1153
|
+
});
|
|
1154
|
+
_defineProperty(_this, "isMounted", function (atom) {
|
|
1155
|
+
var mountState = _this.atomManager.readAtomState(atom);
|
|
1156
|
+
return mountState.mounted !== undefined;
|
|
1157
|
+
});
|
|
1158
|
+
return _this;
|
|
1159
|
+
}
|
|
1160
|
+
_inherits(DebugStoreImpl, _StoreImpl);
|
|
1161
|
+
return _createClass(DebugStoreImpl);
|
|
1162
|
+
}(StoreImpl);
|
|
1163
|
+
function createDebugStore(interceptor) {
|
|
1164
|
+
var atomManager = new AtomManager({
|
|
1165
|
+
interceptor: interceptor
|
|
1166
|
+
});
|
|
1167
|
+
var listenerManager = new ListenerManager();
|
|
1168
|
+
return new DebugStoreImpl(atomManager, listenerManager, {
|
|
1169
|
+
interceptor: interceptor
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(watches) {
|
|
1174
|
+
var _this = this;
|
|
1175
|
+
_classCallCheck(this, ConsoleInterceptor);
|
|
1176
|
+
_defineProperty(this, "shouldLog", function (atom, action) {
|
|
1177
|
+
return _this.watches.some(function (watch) {
|
|
1178
|
+
if (typeof watch.target === 'string') {
|
|
1179
|
+
return atom.toString().includes(watch.target);
|
|
1180
|
+
}
|
|
1181
|
+
if (watch.target instanceof RegExp) {
|
|
1182
|
+
return watch.target.test(atom.toString());
|
|
1183
|
+
}
|
|
1184
|
+
return watch.target === atom && (!watch.actions || watch.actions.has(action));
|
|
1185
|
+
});
|
|
1186
|
+
});
|
|
1187
|
+
_defineProperty(this, "get", function (atom$, fn) {
|
|
1188
|
+
if (!_this.shouldLog(atom$, 'get')) {
|
|
1189
|
+
fn();
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
console.group('[R][GET] ' + atom$.toString());
|
|
1193
|
+
console.log('ret:', fn());
|
|
1194
|
+
console.groupEnd();
|
|
1195
|
+
});
|
|
1196
|
+
_defineProperty(this, "computed", function (atom$, fn) {
|
|
1197
|
+
if (!_this.shouldLog(atom$, 'computed')) {
|
|
1198
|
+
fn();
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
console.group('[R][CPT] ' + atom$.toString());
|
|
1202
|
+
console.log('ret:', fn());
|
|
1203
|
+
console.groupEnd();
|
|
1204
|
+
});
|
|
1205
|
+
_defineProperty(this, "set", function (atom$, fn) {
|
|
1206
|
+
if (!_this.shouldLog(atom$, 'set')) {
|
|
1207
|
+
fn();
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
console.group('[R][SET] ' + atom$.toString());
|
|
1211
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
1212
|
+
args[_key - 2] = arguments[_key];
|
|
1213
|
+
}
|
|
1214
|
+
console.log('arg:', args);
|
|
1215
|
+
console.log('ret:', fn());
|
|
1216
|
+
console.groupEnd();
|
|
1217
|
+
});
|
|
1218
|
+
_defineProperty(this, "sub", function (atom$, callback$, fn) {
|
|
1219
|
+
if (!_this.shouldLog(atom$, 'sub')) {
|
|
1220
|
+
fn();
|
|
1221
|
+
return;
|
|
1222
|
+
}
|
|
1223
|
+
console.group('[R][SUB] ' + atom$.toString() + ', callback=' + callback$.toString());
|
|
1224
|
+
fn();
|
|
1225
|
+
console.groupEnd();
|
|
1226
|
+
});
|
|
1227
|
+
_defineProperty(this, "unsub", function (atom$, callback$, fn) {
|
|
1228
|
+
if (!_this.shouldLog(atom$, 'unsub')) {
|
|
1229
|
+
fn();
|
|
1230
|
+
return;
|
|
1231
|
+
}
|
|
1232
|
+
console.group('[R][UNS] ' + atom$.toString() + ', callback=' + callback$.toString());
|
|
1233
|
+
fn();
|
|
1234
|
+
console.groupEnd();
|
|
1235
|
+
});
|
|
1236
|
+
_defineProperty(this, "mount", function (atom$) {
|
|
1237
|
+
if (!_this.shouldLog(atom$, 'mount')) {
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
console.log('[R][MNT] ' + atom$.toString());
|
|
1241
|
+
});
|
|
1242
|
+
_defineProperty(this, "unmount", function (atom$) {
|
|
1243
|
+
if (!_this.shouldLog(atom$, 'unmount')) {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
console.log('[R][UNM] ' + atom$.toString());
|
|
1247
|
+
});
|
|
1248
|
+
_defineProperty(this, "notify", function (callback$, fn) {
|
|
1249
|
+
if (!_this.shouldLog(callback$, 'notify')) {
|
|
1250
|
+
fn();
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
console.group('[R][NTF] ' + callback$.toString());
|
|
1254
|
+
console.log('ret:', fn());
|
|
1255
|
+
console.groupEnd();
|
|
1256
|
+
});
|
|
1257
|
+
this.watches = watches;
|
|
1258
|
+
});
|
|
1259
|
+
|
|
1260
|
+
var StoreEvent = /*#__PURE__*/function (_Event) {
|
|
1261
|
+
function StoreEvent(type, eventId, targetAtom, state, time, args, result) {
|
|
1262
|
+
var _this;
|
|
1263
|
+
_classCallCheck(this, StoreEvent);
|
|
1264
|
+
_this = _callSuper(this, StoreEvent, [type]);
|
|
1265
|
+
_this.eventId = eventId;
|
|
1266
|
+
_this.targetAtom = targetAtom;
|
|
1267
|
+
_this.state = state;
|
|
1268
|
+
_this.time = time;
|
|
1269
|
+
_this.args = args;
|
|
1270
|
+
_this.result = result;
|
|
1271
|
+
return _this;
|
|
1272
|
+
}
|
|
1273
|
+
_inherits(StoreEvent, _Event);
|
|
1274
|
+
return _createClass(StoreEvent);
|
|
1275
|
+
}(/*#__PURE__*/_wrapNativeSuper(Event));
|
|
1276
|
+
|
|
1277
|
+
var EventInterceptor = /*#__PURE__*/function () {
|
|
1278
|
+
function EventInterceptor() {
|
|
1279
|
+
var _this = this;
|
|
1280
|
+
_classCallCheck(this, EventInterceptor);
|
|
1281
|
+
_defineProperty(this, "traceId", 0);
|
|
1282
|
+
_defineProperty(this, "events", new EventTarget());
|
|
1283
|
+
_defineProperty(this, "get", function (atom$, fn) {
|
|
1284
|
+
return _this.wrapWithTrace(fn, function (eventId, time) {
|
|
1285
|
+
_this.createEvent('get', eventId, atom$.toString(), time, 'begin', [], undefined);
|
|
1286
|
+
}, function (eventId, time, result) {
|
|
1287
|
+
_this.createEvent('get', eventId, atom$.toString(), time, 'success', [], result);
|
|
1288
|
+
}, function (eventId, time, error) {
|
|
1289
|
+
_this.createEvent('get', eventId, atom$.toString(), time, 'error', [], error);
|
|
1290
|
+
});
|
|
1291
|
+
});
|
|
1292
|
+
_defineProperty(this, "computed", function (atom$, fn) {
|
|
1293
|
+
return _this.wrapWithTrace(fn, function (eventId, time) {
|
|
1294
|
+
_this.createEvent('computed', eventId, atom$.toString(), time, 'begin', [], undefined);
|
|
1295
|
+
}, function (eventId, time, result) {
|
|
1296
|
+
_this.createEvent('computed', eventId, atom$.toString(), time, 'success', [], result);
|
|
1297
|
+
}, function (eventId, time, error) {
|
|
1298
|
+
_this.createEvent('computed', eventId, atom$.toString(), time, 'error', [], error);
|
|
1299
|
+
});
|
|
1300
|
+
});
|
|
1301
|
+
_defineProperty(this, "set", function (atom$, fn) {
|
|
1302
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
1303
|
+
args[_key - 2] = arguments[_key];
|
|
1304
|
+
}
|
|
1305
|
+
return _this.wrapWithTrace(fn, function (eventId, time) {
|
|
1306
|
+
_this.createEvent('set', eventId, atom$.toString(), time, 'begin', args, undefined);
|
|
1307
|
+
}, function (eventId, time, result) {
|
|
1308
|
+
_this.createEvent('set', eventId, atom$.toString(), time, 'success', args, result);
|
|
1309
|
+
}, function (eventId, time, error) {
|
|
1310
|
+
_this.createEvent('set', eventId, atom$.toString(), time, 'error', args, error);
|
|
1311
|
+
});
|
|
1312
|
+
});
|
|
1313
|
+
_defineProperty(this, "sub", function (atom$, callback$, fn) {
|
|
1314
|
+
var eventId = _this.traceId++;
|
|
1315
|
+
_this.createEvent('sub', eventId, atom$.toString(), performance.now(), 'begin', [callback$.toString()], undefined);
|
|
1316
|
+
fn();
|
|
1317
|
+
_this.createEvent('sub', eventId, atom$.toString(), performance.now(), 'success', [callback$.toString()], undefined);
|
|
1318
|
+
});
|
|
1319
|
+
_defineProperty(this, "unsub", function (atom$, callback$, fn) {
|
|
1320
|
+
var eventId = _this.traceId++;
|
|
1321
|
+
_this.createEvent('unsub', eventId, atom$.toString(), performance.now(), 'begin', [callback$.toString()], undefined);
|
|
1322
|
+
fn();
|
|
1323
|
+
_this.createEvent('unsub', eventId, atom$.toString(), performance.now(), 'success', [callback$.toString()], undefined);
|
|
1324
|
+
});
|
|
1325
|
+
_defineProperty(this, "mount", function (atom$) {
|
|
1326
|
+
var eventId = _this.traceId++;
|
|
1327
|
+
_this.createEvent('mount', eventId, atom$.toString(), performance.now(), 'begin', [], undefined);
|
|
1328
|
+
});
|
|
1329
|
+
_defineProperty(this, "unmount", function (atom$) {
|
|
1330
|
+
var eventId = _this.traceId++;
|
|
1331
|
+
_this.createEvent('unmount', eventId, atom$.toString(), performance.now(), 'begin', [], undefined);
|
|
1332
|
+
});
|
|
1333
|
+
_defineProperty(this, "notify", function (callback$, fn) {
|
|
1334
|
+
var eventId = _this.traceId++;
|
|
1335
|
+
_this.createEvent('notify', eventId, callback$.toString(), performance.now(), 'begin', [], undefined);
|
|
1336
|
+
var ret = fn();
|
|
1337
|
+
_this.createEvent('notify', eventId, callback$.toString(), performance.now(), 'success', [], ret);
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
return _createClass(EventInterceptor, [{
|
|
1341
|
+
key: "createEvent",
|
|
1342
|
+
value: function createEvent(type, eventId, atom, time, state, args, result) {
|
|
1343
|
+
var event = new StoreEvent(type, eventId, atom, state, time, args, result);
|
|
1344
|
+
this.events.dispatchEvent(event);
|
|
1345
|
+
return event;
|
|
1346
|
+
}
|
|
1347
|
+
}, {
|
|
1348
|
+
key: "wrapWithTrace",
|
|
1349
|
+
value: function wrapWithTrace(fn, createBeginEvent, createSuccessEvent, createErrorEvent) {
|
|
1350
|
+
var eventId = this.traceId++;
|
|
1351
|
+
createBeginEvent(eventId, performance.now());
|
|
1352
|
+
try {
|
|
1353
|
+
var result = fn();
|
|
1354
|
+
createSuccessEvent(eventId, performance.now(), result);
|
|
1355
|
+
return result;
|
|
1356
|
+
} catch (e) {
|
|
1357
|
+
createErrorEvent(eventId, performance.now(), e);
|
|
1358
|
+
throw e;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}, {
|
|
1362
|
+
key: "addEventListener",
|
|
1363
|
+
value: function addEventListener(type, listener, options) {
|
|
1364
|
+
this.events.addEventListener(type, listener, options);
|
|
1365
|
+
}
|
|
1366
|
+
}, {
|
|
1367
|
+
key: "removeEventListener",
|
|
1368
|
+
value: function removeEventListener(type, listener, options) {
|
|
1369
|
+
this.events.removeEventListener(type, listener, options);
|
|
1370
|
+
}
|
|
1371
|
+
}]);
|
|
1372
|
+
}();
|
|
1373
|
+
|
|
1374
|
+
var GLOBAL_CCSTATE_INTERCEPED_KEY = '__CCSTATE_INTERCEPED__';
|
|
1375
|
+
function setupDevtoolsInterceptor(targetWindow, signal) {
|
|
1376
|
+
var interceptor = new EventInterceptor();
|
|
1377
|
+
var watchedAtoms = new Set();
|
|
1378
|
+
targetWindow.addEventListener('message', function (_ref) {
|
|
1379
|
+
var data = _ref.data;
|
|
1380
|
+
if (!data || _typeof(data) !== 'object' || !('source' in data) || data.source !== 'ccstate-devtools') {
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
var payload = data.payload;
|
|
1384
|
+
watchedAtoms.add(payload.args[0]);
|
|
1385
|
+
}, {
|
|
1386
|
+
signal: signal
|
|
1387
|
+
});
|
|
1388
|
+
function handleStoreEvent(event) {
|
|
1389
|
+
var debugLabel = event.targetAtom.substring(event.targetAtom.indexOf(':') + 1);
|
|
1390
|
+
if (watchedAtoms.has(debugLabel)) {
|
|
1391
|
+
console.group("[CCState] ".concat(event.type, " ").concat(event.targetAtom, " ").concat(event.state));
|
|
1392
|
+
console.log('args', event.args);
|
|
1393
|
+
console.log('result', event.result);
|
|
1394
|
+
console.groupEnd();
|
|
1395
|
+
}
|
|
1396
|
+
var message = {
|
|
1397
|
+
source: 'ccstate-store',
|
|
1398
|
+
payload: {
|
|
1399
|
+
type: event.type,
|
|
1400
|
+
eventId: event.eventId,
|
|
1401
|
+
targetAtom: event.targetAtom,
|
|
1402
|
+
time: event.time,
|
|
1403
|
+
state: event.state
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
targetWindow.postMessage(message);
|
|
1407
|
+
}
|
|
1408
|
+
interceptor.addEventListener('get', handleStoreEvent);
|
|
1409
|
+
interceptor.addEventListener('computed', handleStoreEvent);
|
|
1410
|
+
interceptor.addEventListener('set', handleStoreEvent);
|
|
1411
|
+
interceptor.addEventListener('sub', handleStoreEvent);
|
|
1412
|
+
interceptor.addEventListener('unsub', handleStoreEvent);
|
|
1413
|
+
interceptor.addEventListener('mount', handleStoreEvent);
|
|
1414
|
+
interceptor.addEventListener('unmount', handleStoreEvent);
|
|
1415
|
+
interceptor.addEventListener('notify', handleStoreEvent);
|
|
1416
|
+
targetWindow[GLOBAL_CCSTATE_INTERCEPED_KEY] = true;
|
|
1417
|
+
console.warn('[CCSTATE] Interceptor injected, DO NOT USE THIS IN PRODUCTION');
|
|
1418
|
+
return interceptor;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
exports.ConsoleInterceptor = ConsoleInterceptor;
|
|
1422
|
+
exports.EventInterceptor = EventInterceptor;
|
|
1423
|
+
exports.GLOBAL_CCSTATE_INTERCEPED_KEY = GLOBAL_CCSTATE_INTERCEPED_KEY;
|
|
1424
|
+
exports.StoreEvent = StoreEvent;
|
|
1425
|
+
exports.createDebugStore = createDebugStore;
|
|
1426
|
+
exports.nestedAtomToString = nestedAtomToString;
|
|
1427
|
+
exports.setupDevtoolsInterceptor = setupDevtoolsInterceptor;
|