ccstate 4.13.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -77
- package/core/index.cjs +69 -215
- package/core/index.cjs.map +1 -1
- package/core/index.d.cts +6 -6
- package/core/index.d.ts +6 -6
- package/core/index.js +70 -215
- package/core/index.js.map +1 -1
- package/debug/index.cjs +85 -286
- package/debug/index.cjs.map +1 -1
- package/debug/index.d.cts +6 -6
- package/debug/index.d.ts +6 -6
- package/debug/index.js +85 -286
- package/debug/index.js.map +1 -1
- package/index.cjs +67 -296
- package/index.cjs.map +1 -1
- package/index.d.cts +7 -8
- package/index.d.ts +7 -8
- package/index.js +68 -296
- package/index.js.map +1 -1
- package/package.json +2 -2
package/debug/index.cjs
CHANGED
|
@@ -21,14 +21,8 @@ function _callSuper(t, o, e) {
|
|
|
21
21
|
function _classCallCheck(a, n) {
|
|
22
22
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
23
23
|
}
|
|
24
|
-
function _defineProperties(e, r) {
|
|
25
|
-
for (var t = 0; t < r.length; t++) {
|
|
26
|
-
var o = r[t];
|
|
27
|
-
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
24
|
function _createClass(e, r, t) {
|
|
31
|
-
return
|
|
25
|
+
return Object.defineProperty(e, "prototype", {
|
|
32
26
|
writable: !1
|
|
33
27
|
}), e;
|
|
34
28
|
}
|
|
@@ -88,15 +82,6 @@ function _defineProperty(e, r, t) {
|
|
|
88
82
|
writable: !0
|
|
89
83
|
}) : e[r] = t, e;
|
|
90
84
|
}
|
|
91
|
-
function _get() {
|
|
92
|
-
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
|
|
93
|
-
var p = _superPropBase(e, t);
|
|
94
|
-
if (p) {
|
|
95
|
-
var n = Object.getOwnPropertyDescriptor(p, t);
|
|
96
|
-
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
|
|
97
|
-
}
|
|
98
|
-
}, _get.apply(null, arguments);
|
|
99
|
-
}
|
|
100
85
|
function _getPrototypeOf(t) {
|
|
101
86
|
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
102
87
|
return t.__proto__ || Object.getPrototypeOf(t);
|
|
@@ -171,16 +156,6 @@ function _setPrototypeOf(t, e) {
|
|
|
171
156
|
function _slicedToArray(r, e) {
|
|
172
157
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
173
158
|
}
|
|
174
|
-
function _superPropBase(t, o) {
|
|
175
|
-
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
|
|
176
|
-
return t;
|
|
177
|
-
}
|
|
178
|
-
function _superPropGet(t, o, e, r) {
|
|
179
|
-
var p = _get(_getPrototypeOf(t.prototype ), o, e);
|
|
180
|
-
return "function" == typeof p ? function (t) {
|
|
181
|
-
return p.apply(e, t);
|
|
182
|
-
} : p;
|
|
183
|
-
}
|
|
184
159
|
function _toConsumableArray(r) {
|
|
185
160
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
186
161
|
}
|
|
@@ -290,63 +265,6 @@ function withGeValInterceptor(fn, signal, interceptor) {
|
|
|
290
265
|
}
|
|
291
266
|
return result.data;
|
|
292
267
|
}
|
|
293
|
-
function withSubInterceptor(fn, signal, callback$, interceptor) {
|
|
294
|
-
if (!interceptor) {
|
|
295
|
-
fn();
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
var result = {
|
|
299
|
-
called: false
|
|
300
|
-
};
|
|
301
|
-
interceptor(signal, callback$, function () {
|
|
302
|
-
result = {
|
|
303
|
-
called: true,
|
|
304
|
-
data: undefined
|
|
305
|
-
};
|
|
306
|
-
fn();
|
|
307
|
-
});
|
|
308
|
-
if (!result.called) {
|
|
309
|
-
throw new Error('interceptor must call fn sync');
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
function withUnsubInterceptor(fn, signal, callback$, interceptor) {
|
|
313
|
-
if (!interceptor) {
|
|
314
|
-
fn();
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
var result = {
|
|
318
|
-
called: false
|
|
319
|
-
};
|
|
320
|
-
interceptor(signal, callback$, function () {
|
|
321
|
-
result = {
|
|
322
|
-
called: true,
|
|
323
|
-
data: undefined
|
|
324
|
-
};
|
|
325
|
-
fn();
|
|
326
|
-
});
|
|
327
|
-
if (!result.called) {
|
|
328
|
-
throw new Error('interceptor must call fn sync');
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
function withNotifyInterceptor(fn, callback$, interceptor) {
|
|
332
|
-
if (!interceptor) {
|
|
333
|
-
return fn();
|
|
334
|
-
}
|
|
335
|
-
var result = {
|
|
336
|
-
called: false
|
|
337
|
-
};
|
|
338
|
-
interceptor(callback$, function () {
|
|
339
|
-
result = {
|
|
340
|
-
called: true,
|
|
341
|
-
data: fn()
|
|
342
|
-
};
|
|
343
|
-
return result.data;
|
|
344
|
-
});
|
|
345
|
-
if (!result.called) {
|
|
346
|
-
throw new Error('interceptor must call fn sync');
|
|
347
|
-
}
|
|
348
|
-
return result.data;
|
|
349
|
-
}
|
|
350
268
|
|
|
351
269
|
function canReadAsCompute(atom) {
|
|
352
270
|
return 'read' in atom;
|
|
@@ -544,30 +462,18 @@ function pushDirtyMarkers(signalState, context, mutation) {
|
|
|
544
462
|
}
|
|
545
463
|
}
|
|
546
464
|
function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
547
|
-
var _signalState$mounted$2, _signalState$mounted2, _signalState$mounted$3, _signalState$mounted3
|
|
465
|
+
var _signalState$mounted$2, _signalState$mounted2, _signalState$mounted$3, _signalState$mounted3;
|
|
548
466
|
var queue = Array.from((_signalState$mounted$2 = (_signalState$mounted2 = signalState.mounted) === null || _signalState$mounted2 === void 0 ? void 0 : _signalState$mounted2.readDepts) !== null && _signalState$mounted$2 !== void 0 ? _signalState$mounted$2 : []);
|
|
549
|
-
var _iterator3 = _createForOfIteratorHelper((_signalState$mounted$4 = (_signalState$mounted4 = signalState.mounted) === null || _signalState$mounted4 === void 0 ? void 0 : _signalState$mounted4.listeners) !== null && _signalState$mounted$4 !== void 0 ? _signalState$mounted$4 : []),
|
|
550
|
-
_step3;
|
|
551
|
-
try {
|
|
552
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
553
|
-
var _listener = _step3.value;
|
|
554
|
-
mutation.pendingListeners.add(_listener);
|
|
555
|
-
}
|
|
556
|
-
} catch (err) {
|
|
557
|
-
_iterator3.e(err);
|
|
558
|
-
} finally {
|
|
559
|
-
_iterator3.f();
|
|
560
|
-
}
|
|
561
467
|
var oldValues = new Map();
|
|
562
468
|
var oldErrors = new Map();
|
|
563
469
|
while (queue.length > 0) {
|
|
564
470
|
var nextQueue = [];
|
|
565
|
-
var
|
|
566
|
-
|
|
471
|
+
var _iterator3 = _createForOfIteratorHelper(queue),
|
|
472
|
+
_step3;
|
|
567
473
|
try {
|
|
568
|
-
for (
|
|
474
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
569
475
|
var _context$stateMap$get;
|
|
570
|
-
var computed$ =
|
|
476
|
+
var computed$ = _step3.value;
|
|
571
477
|
var oldState = context.stateMap.get(computed$);
|
|
572
478
|
oldValues.set(computed$, oldState === null || oldState === void 0 ? void 0 : oldState.val);
|
|
573
479
|
oldErrors.set(computed$, oldState === null || oldState === void 0 ? void 0 : oldState.error);
|
|
@@ -580,42 +486,28 @@ function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
|
580
486
|
}
|
|
581
487
|
}
|
|
582
488
|
} catch (err) {
|
|
583
|
-
|
|
489
|
+
_iterator3.e(err);
|
|
584
490
|
} finally {
|
|
585
|
-
|
|
491
|
+
_iterator3.f();
|
|
586
492
|
}
|
|
587
493
|
queue = nextQueue;
|
|
588
494
|
}
|
|
589
495
|
queue = Array.from((_signalState$mounted$3 = (_signalState$mounted3 = signalState.mounted) === null || _signalState$mounted3 === void 0 ? void 0 : _signalState$mounted3.readDepts) !== null && _signalState$mounted$3 !== void 0 ? _signalState$mounted$3 : []);
|
|
590
496
|
while (queue.length > 0) {
|
|
591
497
|
var _nextQueue = [];
|
|
592
|
-
var
|
|
593
|
-
|
|
498
|
+
var _iterator4 = _createForOfIteratorHelper(queue),
|
|
499
|
+
_step4;
|
|
594
500
|
try {
|
|
595
|
-
for (
|
|
596
|
-
var _computedState$mounte
|
|
597
|
-
var _computed$ =
|
|
501
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
502
|
+
var _computedState$mounte;
|
|
503
|
+
var _computed$ = _step4.value;
|
|
598
504
|
var computedState = readComputed(_computed$, context, mutation);
|
|
599
505
|
var isSameWithOldValue = !computedState.error && oldValues.has(_computed$) && oldValues.get(_computed$) === computedState.val;
|
|
600
506
|
var isSameError = computedState.error && Boolean(oldErrors.get(_computed$));
|
|
601
507
|
if (isSameWithOldValue || isSameError) {
|
|
602
508
|
continue;
|
|
603
509
|
}
|
|
604
|
-
|
|
605
|
-
var _iterator6 = _createForOfIteratorHelper(computedState.mounted.listeners),
|
|
606
|
-
_step6;
|
|
607
|
-
try {
|
|
608
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
609
|
-
var listener = _step6.value;
|
|
610
|
-
mutation.pendingListeners.add(listener);
|
|
611
|
-
}
|
|
612
|
-
} catch (err) {
|
|
613
|
-
_iterator6.e(err);
|
|
614
|
-
} finally {
|
|
615
|
-
_iterator6.f();
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
var _readDepts = (_computedState$mounte2 = computedState.mounted) === null || _computedState$mounte2 === void 0 ? void 0 : _computedState$mounte2.readDepts;
|
|
510
|
+
var _readDepts = (_computedState$mounte = computedState.mounted) === null || _computedState$mounte === void 0 ? void 0 : _computedState$mounte.readDepts;
|
|
619
511
|
if (_readDepts) {
|
|
620
512
|
for (var _i2 = 0, _Array$from2 = Array.from(_readDepts); _i2 < _Array$from2.length; _i2++) {
|
|
621
513
|
var _dep = _Array$from2[_i2];
|
|
@@ -624,9 +516,9 @@ function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
|
624
516
|
}
|
|
625
517
|
}
|
|
626
518
|
} catch (err) {
|
|
627
|
-
|
|
519
|
+
_iterator4.e(err);
|
|
628
520
|
} finally {
|
|
629
|
-
|
|
521
|
+
_iterator4.f();
|
|
630
522
|
}
|
|
631
523
|
queue = _nextQueue;
|
|
632
524
|
}
|
|
@@ -690,7 +582,6 @@ function set(readComputed, writable$, context, mutation) {
|
|
|
690
582
|
function createMutation(context, _get, _set) {
|
|
691
583
|
var mutation = {
|
|
692
584
|
potentialDirtyIds: new Set(),
|
|
693
|
-
pendingListeners: new Set(),
|
|
694
585
|
visitor: {
|
|
695
586
|
get: function get(signal$) {
|
|
696
587
|
return _get(signal$, context, mutation);
|
|
@@ -737,11 +628,10 @@ function mountComputedDependencies(readSignal, computed$, computedState, context
|
|
|
737
628
|
}
|
|
738
629
|
}
|
|
739
630
|
function initMount(readSignal, signal$, context, mutation) {
|
|
740
|
-
var _context$interceptor, _context$interceptor
|
|
631
|
+
var _context$interceptor, _context$interceptor$;
|
|
741
632
|
(_context$interceptor = context.interceptor) === null || _context$interceptor === void 0 || (_context$interceptor$ = _context$interceptor.mount) === null || _context$interceptor$ === void 0 || _context$interceptor$.call(_context$interceptor, signal$);
|
|
742
633
|
var signalState = readSignal(signal$, context, mutation);
|
|
743
|
-
signalState.mounted =
|
|
744
|
-
listeners: new Set(),
|
|
634
|
+
signalState.mounted = {
|
|
745
635
|
readDepts: new Set()
|
|
746
636
|
};
|
|
747
637
|
if (isComputedState(signalState)) {
|
|
@@ -767,51 +657,30 @@ function doUnmount(signal$, signalState, context, mutation) {
|
|
|
767
657
|
}
|
|
768
658
|
function unmount(signal$, context, mutation) {
|
|
769
659
|
var signalState = context.stateMap.get(signal$);
|
|
770
|
-
if (!(signalState !== null && signalState !== void 0 && signalState.mounted) || signalState.mounted.
|
|
660
|
+
if (!(signalState !== null && signalState !== void 0 && signalState.mounted) || signalState.mounted.readDepts.size) {
|
|
771
661
|
return;
|
|
772
662
|
}
|
|
773
663
|
doUnmount(signal$, signalState, context);
|
|
774
664
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}, signal$, callback$, (_context$interceptor5 = context.interceptor) === null || _context$interceptor5 === void 0 ? void 0 : _context$interceptor5.sub);
|
|
793
|
-
}
|
|
794
|
-
function notify(context, mutation) {
|
|
795
|
-
var pendingListeners = mutation.pendingListeners;
|
|
796
|
-
mutation.pendingListeners = new Set();
|
|
797
|
-
var _iterator = _createForOfIteratorHelper(pendingListeners),
|
|
798
|
-
_step;
|
|
799
|
-
try {
|
|
800
|
-
var _loop = function _loop() {
|
|
801
|
-
var _context$interceptor6;
|
|
802
|
-
var listener = _step.value;
|
|
803
|
-
withNotifyInterceptor(function () {
|
|
804
|
-
return listener.write(mutation.visitor);
|
|
805
|
-
}, listener, (_context$interceptor6 = context.interceptor) === null || _context$interceptor6 === void 0 ? void 0 : _context$interceptor6.notify);
|
|
806
|
-
};
|
|
807
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
808
|
-
_loop();
|
|
809
|
-
}
|
|
810
|
-
} catch (err) {
|
|
811
|
-
_iterator.e(err);
|
|
812
|
-
} finally {
|
|
813
|
-
_iterator.f();
|
|
665
|
+
|
|
666
|
+
var globalId = 0;
|
|
667
|
+
var generateToString = function generateToString(id, prefix, debugLabel) {
|
|
668
|
+
var label = "".concat(prefix).concat(String(id)).concat(debugLabel ? ':' + debugLabel : '');
|
|
669
|
+
return function () {
|
|
670
|
+
return label;
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
function computed(read, options) {
|
|
674
|
+
var id = globalId++;
|
|
675
|
+
var ret = {
|
|
676
|
+
id: id,
|
|
677
|
+
read: read,
|
|
678
|
+
toString: generateToString(id, 'CPT', options === null || options === void 0 ? void 0 : options.debugLabel)
|
|
679
|
+
};
|
|
680
|
+
if (options !== null && options !== void 0 && options.debugLabel) {
|
|
681
|
+
ret.debugLabel = options.debugLabel;
|
|
814
682
|
}
|
|
683
|
+
return ret;
|
|
815
684
|
}
|
|
816
685
|
|
|
817
686
|
var _readComputed = function readComputed(computed$, context, mutation) {
|
|
@@ -833,26 +702,7 @@ function readSignal(signal$, context, mutation) {
|
|
|
833
702
|
function mount(signal$, context, mutation) {
|
|
834
703
|
return mount$1(readSignal, signal$, context, mutation);
|
|
835
704
|
}
|
|
836
|
-
function
|
|
837
|
-
if (Array.isArray(signals$) && signals$.length === 0) {
|
|
838
|
-
return function () {
|
|
839
|
-
return void 0;
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
var controller = new AbortController();
|
|
843
|
-
var signal = options !== null && options !== void 0 && options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
844
|
-
if (!Array.isArray(signals$)) {
|
|
845
|
-
subSingleSignal(readSignal, signals$, callback$, context, signal);
|
|
846
|
-
} else {
|
|
847
|
-
signals$.forEach(function (atom) {
|
|
848
|
-
subSingleSignal(readSignal, atom, callback$, context, signal);
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
return function () {
|
|
852
|
-
controller.abort();
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
var get = function get(signal, context, mutation) {
|
|
705
|
+
var storeGet = function storeGet(signal, context, mutation) {
|
|
856
706
|
var _context$interceptor2;
|
|
857
707
|
return withGetInterceptor(function () {
|
|
858
708
|
var signalState = readSignal(signal, context, mutation);
|
|
@@ -862,50 +712,63 @@ var get = function get(signal, context, mutation) {
|
|
|
862
712
|
return signalState.val;
|
|
863
713
|
}, signal, (_context$interceptor2 = context.interceptor) === null || _context$interceptor2 === void 0 ? void 0 : _context$interceptor2.get);
|
|
864
714
|
};
|
|
865
|
-
var
|
|
715
|
+
var _storeSet = function storeSet(atom, context) {
|
|
866
716
|
var _context$interceptor3;
|
|
867
717
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
868
718
|
args[_key - 2] = arguments[_key];
|
|
869
719
|
}
|
|
870
720
|
return withSetInterceptor.apply(void 0, [function () {
|
|
871
|
-
var mutation = createMutation(context,
|
|
872
|
-
|
|
873
|
-
try {
|
|
874
|
-
ret = set.apply(void 0, [_readComputed, atom, context, mutation].concat(args));
|
|
875
|
-
} finally {
|
|
876
|
-
notify(context, mutation);
|
|
877
|
-
}
|
|
878
|
-
return ret;
|
|
721
|
+
var mutation = createMutation(context, storeGet, _storeSet);
|
|
722
|
+
return set.apply(void 0, [_readComputed, atom, context, mutation].concat(args));
|
|
879
723
|
}, atom, (_context$interceptor3 = context.interceptor) === null || _context$interceptor3 === void 0 ? void 0 : _context$interceptor3.set].concat(args));
|
|
880
724
|
};
|
|
881
|
-
var
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
args[_key2 - 1] = arguments[_key2];
|
|
725
|
+
var storeWatch = function storeWatch(watchFn, context, options) {
|
|
726
|
+
var _options$signal;
|
|
727
|
+
var computed$ = computed(function (get, _ref) {
|
|
728
|
+
var signal = _ref.signal;
|
|
729
|
+
var childSignal;
|
|
730
|
+
var obOptions = {
|
|
731
|
+
get signal() {
|
|
732
|
+
if (!childSignal) {
|
|
733
|
+
childSignal = options !== null && options !== void 0 && options.signal ? AbortSignal.any([options.signal, signal]) : signal;
|
|
734
|
+
}
|
|
735
|
+
return childSignal;
|
|
893
736
|
}
|
|
894
|
-
return _set.apply(void 0, [atom, _this.context].concat(args));
|
|
895
|
-
});
|
|
896
|
-
this.options = options;
|
|
897
|
-
this.context = {
|
|
898
|
-
stateMap: this.stateMap,
|
|
899
|
-
interceptor: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.interceptor
|
|
900
737
|
};
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
738
|
+
watchFn(get, obOptions);
|
|
739
|
+
}, {
|
|
740
|
+
debugLabel: options === null || options === void 0 ? void 0 : options.debugLabel
|
|
741
|
+
});
|
|
742
|
+
mount$1(readSignal, computed$, context);
|
|
743
|
+
options === null || options === void 0 || (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener('abort', function () {
|
|
744
|
+
unmount(computed$, context);
|
|
745
|
+
}, {
|
|
746
|
+
once: true
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
var StoreImpl = /*#__PURE__*/_createClass(function StoreImpl(_options) {
|
|
750
|
+
var _this = this,
|
|
751
|
+
_this$options;
|
|
752
|
+
_classCallCheck(this, StoreImpl);
|
|
753
|
+
_defineProperty(this, "stateMap", new WeakMap());
|
|
754
|
+
_defineProperty(this, "get", function (atom) {
|
|
755
|
+
return storeGet(atom, _this.context);
|
|
756
|
+
});
|
|
757
|
+
_defineProperty(this, "set", function (atom) {
|
|
758
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
759
|
+
args[_key2 - 1] = arguments[_key2];
|
|
906
760
|
}
|
|
907
|
-
|
|
908
|
-
}
|
|
761
|
+
return _storeSet.apply(void 0, [atom, _this.context].concat(args));
|
|
762
|
+
});
|
|
763
|
+
_defineProperty(this, "watch", function (watchFn, options) {
|
|
764
|
+
storeWatch(watchFn, _this.context, options);
|
|
765
|
+
});
|
|
766
|
+
this.options = _options;
|
|
767
|
+
this.context = {
|
|
768
|
+
stateMap: this.stateMap,
|
|
769
|
+
interceptor: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.interceptor
|
|
770
|
+
};
|
|
771
|
+
});
|
|
909
772
|
|
|
910
773
|
var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
911
774
|
function DebugStoreImpl() {
|
|
@@ -915,34 +778,6 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
915
778
|
args[_key] = arguments[_key];
|
|
916
779
|
}
|
|
917
780
|
_this = _callSuper(this, DebugStoreImpl, [].concat(args));
|
|
918
|
-
_defineProperty(_this, "mountedAtomListenersCount", new Map());
|
|
919
|
-
_defineProperty(_this, "sub", function (atoms, cb, options) {
|
|
920
|
-
var _options$signal;
|
|
921
|
-
var atomList = Array.isArray(atoms) ? atoms : [atoms];
|
|
922
|
-
atomList.forEach(function (atom) {
|
|
923
|
-
var _this$mountedAtomList;
|
|
924
|
-
_this.mountedAtomListenersCount.set(atom, ((_this$mountedAtomList = _this.mountedAtomListenersCount.get(atom)) !== null && _this$mountedAtomList !== void 0 ? _this$mountedAtomList : 0) + 1);
|
|
925
|
-
});
|
|
926
|
-
var unsub = _superPropGet((DebugStoreImpl), "sub", _this)([atoms, cb, options]);
|
|
927
|
-
var decount = function decount() {
|
|
928
|
-
atomList.forEach(function (atom) {
|
|
929
|
-
var _this$mountedAtomList2;
|
|
930
|
-
var count = (_this$mountedAtomList2 = _this.mountedAtomListenersCount.get(atom)) !== null && _this$mountedAtomList2 !== void 0 ? _this$mountedAtomList2 : 0;
|
|
931
|
-
if (count === 0) {
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
_this.mountedAtomListenersCount.set(atom, count - 1);
|
|
935
|
-
if (count === 1) {
|
|
936
|
-
_this.mountedAtomListenersCount["delete"](atom);
|
|
937
|
-
}
|
|
938
|
-
});
|
|
939
|
-
};
|
|
940
|
-
options === null || options === void 0 || (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener('abort', decount);
|
|
941
|
-
return function () {
|
|
942
|
-
unsub();
|
|
943
|
-
decount();
|
|
944
|
-
};
|
|
945
|
-
});
|
|
946
781
|
_defineProperty(_this, "getReadDependencies", function (atom) {
|
|
947
782
|
var atomState = _this.context.stateMap.get(atom);
|
|
948
783
|
if (!atomState) {
|
|
@@ -967,15 +802,6 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
967
802
|
return _this.getReadDependents(key);
|
|
968
803
|
})));
|
|
969
804
|
});
|
|
970
|
-
_defineProperty(_this, "getSubscribeGraph", function () {
|
|
971
|
-
var subscribedAtoms = Array.from(_this.mountedAtomListenersCount.keys());
|
|
972
|
-
return subscribedAtoms.map(function (atom) {
|
|
973
|
-
var atomState = _this.context.stateMap.get(atom);
|
|
974
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
975
|
-
var listeners = Array.from(atomState.mounted.listeners);
|
|
976
|
-
return [atom].concat(listeners);
|
|
977
|
-
});
|
|
978
|
-
});
|
|
979
805
|
_defineProperty(_this, "isMounted", function (atom) {
|
|
980
806
|
var mountState = _this.stateMap.get(atom);
|
|
981
807
|
return (mountState === null || mountState === void 0 ? void 0 : mountState.mounted) !== undefined;
|
|
@@ -1077,24 +903,6 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1077
903
|
console.log('ret:', fn());
|
|
1078
904
|
console.groupEnd();
|
|
1079
905
|
});
|
|
1080
|
-
_defineProperty(this, "sub", function (atom$, callback$, fn) {
|
|
1081
|
-
if (!_this.shouldLog(atom$, 'sub')) {
|
|
1082
|
-
fn();
|
|
1083
|
-
return;
|
|
1084
|
-
}
|
|
1085
|
-
console.group('[R][SUB] ' + atom$.toString() + ', callback=' + callback$.toString());
|
|
1086
|
-
fn();
|
|
1087
|
-
console.groupEnd();
|
|
1088
|
-
});
|
|
1089
|
-
_defineProperty(this, "unsub", function (atom$, callback$, fn) {
|
|
1090
|
-
if (!_this.shouldLog(atom$, 'unsub')) {
|
|
1091
|
-
fn();
|
|
1092
|
-
return;
|
|
1093
|
-
}
|
|
1094
|
-
console.group('[R][UNS] ' + atom$.toString() + ', callback=' + callback$.toString());
|
|
1095
|
-
fn();
|
|
1096
|
-
console.groupEnd();
|
|
1097
|
-
});
|
|
1098
906
|
_defineProperty(this, "mount", function (atom$) {
|
|
1099
907
|
if (!_this.shouldLog(atom$, 'mount')) {
|
|
1100
908
|
return;
|
|
@@ -1107,15 +915,6 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1107
915
|
}
|
|
1108
916
|
console.log('[R][UNM] ' + atom$.toString());
|
|
1109
917
|
});
|
|
1110
|
-
_defineProperty(this, "notify", function (callback$, fn) {
|
|
1111
|
-
if (!_this.shouldLog(callback$, 'notify')) {
|
|
1112
|
-
fn();
|
|
1113
|
-
return;
|
|
1114
|
-
}
|
|
1115
|
-
console.group('[R][NTF] ' + callback$.toString());
|
|
1116
|
-
console.log('ret:', fn());
|
|
1117
|
-
console.groupEnd();
|
|
1118
|
-
});
|
|
1119
918
|
this.watches = watches;
|
|
1120
919
|
});
|
|
1121
920
|
function createDebugStore() {
|