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