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