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/index.cjs
CHANGED
|
@@ -65,14 +65,8 @@ function _callSuper(t, o, e) {
|
|
|
65
65
|
function _classCallCheck(a, n) {
|
|
66
66
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
67
67
|
}
|
|
68
|
-
function _defineProperties(e, r) {
|
|
69
|
-
for (var t = 0; t < r.length; t++) {
|
|
70
|
-
var o = r[t];
|
|
71
|
-
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
68
|
function _createClass(e, r, t) {
|
|
75
|
-
return
|
|
69
|
+
return Object.defineProperty(e, "prototype", {
|
|
76
70
|
writable: !1
|
|
77
71
|
}), e;
|
|
78
72
|
}
|
|
@@ -132,15 +126,6 @@ function _defineProperty(e, r, t) {
|
|
|
132
126
|
writable: !0
|
|
133
127
|
}) : e[r] = t, e;
|
|
134
128
|
}
|
|
135
|
-
function _get() {
|
|
136
|
-
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
|
|
137
|
-
var p = _superPropBase(e, t);
|
|
138
|
-
if (p) {
|
|
139
|
-
var n = Object.getOwnPropertyDescriptor(p, t);
|
|
140
|
-
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
|
|
141
|
-
}
|
|
142
|
-
}, _get.apply(null, arguments);
|
|
143
|
-
}
|
|
144
129
|
function _getPrototypeOf(t) {
|
|
145
130
|
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
146
131
|
return t.__proto__ || Object.getPrototypeOf(t);
|
|
@@ -215,16 +200,6 @@ function _setPrototypeOf(t, e) {
|
|
|
215
200
|
function _slicedToArray(r, e) {
|
|
216
201
|
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
217
202
|
}
|
|
218
|
-
function _superPropBase(t, o) {
|
|
219
|
-
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
|
|
220
|
-
return t;
|
|
221
|
-
}
|
|
222
|
-
function _superPropGet(t, o, e, r) {
|
|
223
|
-
var p = _get(_getPrototypeOf(t.prototype ), o, e);
|
|
224
|
-
return "function" == typeof p ? function (t) {
|
|
225
|
-
return p.apply(e, t);
|
|
226
|
-
} : p;
|
|
227
|
-
}
|
|
228
203
|
function _toConsumableArray(r) {
|
|
229
204
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
230
205
|
}
|
|
@@ -334,63 +309,6 @@ function withGeValInterceptor(fn, signal, interceptor) {
|
|
|
334
309
|
}
|
|
335
310
|
return result.data;
|
|
336
311
|
}
|
|
337
|
-
function withSubInterceptor(fn, signal, callback$, interceptor) {
|
|
338
|
-
if (!interceptor) {
|
|
339
|
-
fn();
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
var result = {
|
|
343
|
-
called: false
|
|
344
|
-
};
|
|
345
|
-
interceptor(signal, callback$, function () {
|
|
346
|
-
result = {
|
|
347
|
-
called: true,
|
|
348
|
-
data: undefined
|
|
349
|
-
};
|
|
350
|
-
fn();
|
|
351
|
-
});
|
|
352
|
-
if (!result.called) {
|
|
353
|
-
throw new Error('interceptor must call fn sync');
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
function withUnsubInterceptor(fn, signal, callback$, interceptor) {
|
|
357
|
-
if (!interceptor) {
|
|
358
|
-
fn();
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
var result = {
|
|
362
|
-
called: false
|
|
363
|
-
};
|
|
364
|
-
interceptor(signal, callback$, function () {
|
|
365
|
-
result = {
|
|
366
|
-
called: true,
|
|
367
|
-
data: undefined
|
|
368
|
-
};
|
|
369
|
-
fn();
|
|
370
|
-
});
|
|
371
|
-
if (!result.called) {
|
|
372
|
-
throw new Error('interceptor must call fn sync');
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
function withNotifyInterceptor(fn, callback$, interceptor) {
|
|
376
|
-
if (!interceptor) {
|
|
377
|
-
return fn();
|
|
378
|
-
}
|
|
379
|
-
var result = {
|
|
380
|
-
called: false
|
|
381
|
-
};
|
|
382
|
-
interceptor(callback$, function () {
|
|
383
|
-
result = {
|
|
384
|
-
called: true,
|
|
385
|
-
data: fn()
|
|
386
|
-
};
|
|
387
|
-
return result.data;
|
|
388
|
-
});
|
|
389
|
-
if (!result.called) {
|
|
390
|
-
throw new Error('interceptor must call fn sync');
|
|
391
|
-
}
|
|
392
|
-
return result.data;
|
|
393
|
-
}
|
|
394
312
|
|
|
395
313
|
function canReadAsCompute(atom) {
|
|
396
314
|
return 'read' in atom;
|
|
@@ -588,30 +506,18 @@ function pushDirtyMarkers(signalState, context, mutation) {
|
|
|
588
506
|
}
|
|
589
507
|
}
|
|
590
508
|
function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
591
|
-
var _signalState$mounted$2, _signalState$mounted2, _signalState$mounted$3, _signalState$mounted3
|
|
509
|
+
var _signalState$mounted$2, _signalState$mounted2, _signalState$mounted$3, _signalState$mounted3;
|
|
592
510
|
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 : []);
|
|
593
|
-
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 : []),
|
|
594
|
-
_step3;
|
|
595
|
-
try {
|
|
596
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
597
|
-
var _listener = _step3.value;
|
|
598
|
-
mutation.pendingListeners.add(_listener);
|
|
599
|
-
}
|
|
600
|
-
} catch (err) {
|
|
601
|
-
_iterator3.e(err);
|
|
602
|
-
} finally {
|
|
603
|
-
_iterator3.f();
|
|
604
|
-
}
|
|
605
511
|
var oldValues = new Map();
|
|
606
512
|
var oldErrors = new Map();
|
|
607
513
|
while (queue.length > 0) {
|
|
608
514
|
var nextQueue = [];
|
|
609
|
-
var
|
|
610
|
-
|
|
515
|
+
var _iterator3 = _createForOfIteratorHelper(queue),
|
|
516
|
+
_step3;
|
|
611
517
|
try {
|
|
612
|
-
for (
|
|
518
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
613
519
|
var _context$stateMap$get;
|
|
614
|
-
var computed$ =
|
|
520
|
+
var computed$ = _step3.value;
|
|
615
521
|
var oldState = context.stateMap.get(computed$);
|
|
616
522
|
oldValues.set(computed$, oldState === null || oldState === void 0 ? void 0 : oldState.val);
|
|
617
523
|
oldErrors.set(computed$, oldState === null || oldState === void 0 ? void 0 : oldState.error);
|
|
@@ -624,42 +530,28 @@ function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
|
624
530
|
}
|
|
625
531
|
}
|
|
626
532
|
} catch (err) {
|
|
627
|
-
|
|
533
|
+
_iterator3.e(err);
|
|
628
534
|
} finally {
|
|
629
|
-
|
|
535
|
+
_iterator3.f();
|
|
630
536
|
}
|
|
631
537
|
queue = nextQueue;
|
|
632
538
|
}
|
|
633
539
|
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 : []);
|
|
634
540
|
while (queue.length > 0) {
|
|
635
541
|
var _nextQueue = [];
|
|
636
|
-
var
|
|
637
|
-
|
|
542
|
+
var _iterator4 = _createForOfIteratorHelper(queue),
|
|
543
|
+
_step4;
|
|
638
544
|
try {
|
|
639
|
-
for (
|
|
640
|
-
var _computedState$mounte
|
|
641
|
-
var _computed$ =
|
|
545
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
546
|
+
var _computedState$mounte;
|
|
547
|
+
var _computed$ = _step4.value;
|
|
642
548
|
var computedState = readComputed(_computed$, context, mutation);
|
|
643
549
|
var isSameWithOldValue = !computedState.error && oldValues.has(_computed$) && oldValues.get(_computed$) === computedState.val;
|
|
644
550
|
var isSameError = computedState.error && Boolean(oldErrors.get(_computed$));
|
|
645
551
|
if (isSameWithOldValue || isSameError) {
|
|
646
552
|
continue;
|
|
647
553
|
}
|
|
648
|
-
|
|
649
|
-
var _iterator6 = _createForOfIteratorHelper(computedState.mounted.listeners),
|
|
650
|
-
_step6;
|
|
651
|
-
try {
|
|
652
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
653
|
-
var listener = _step6.value;
|
|
654
|
-
mutation.pendingListeners.add(listener);
|
|
655
|
-
}
|
|
656
|
-
} catch (err) {
|
|
657
|
-
_iterator6.e(err);
|
|
658
|
-
} finally {
|
|
659
|
-
_iterator6.f();
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
var _readDepts = (_computedState$mounte2 = computedState.mounted) === null || _computedState$mounte2 === void 0 ? void 0 : _computedState$mounte2.readDepts;
|
|
554
|
+
var _readDepts = (_computedState$mounte = computedState.mounted) === null || _computedState$mounte === void 0 ? void 0 : _computedState$mounte.readDepts;
|
|
663
555
|
if (_readDepts) {
|
|
664
556
|
for (var _i2 = 0, _Array$from2 = Array.from(_readDepts); _i2 < _Array$from2.length; _i2++) {
|
|
665
557
|
var _dep = _Array$from2[_i2];
|
|
@@ -668,9 +560,9 @@ function pullEvaluate(readComputed, signalState, context, mutation) {
|
|
|
668
560
|
}
|
|
669
561
|
}
|
|
670
562
|
} catch (err) {
|
|
671
|
-
|
|
563
|
+
_iterator4.e(err);
|
|
672
564
|
} finally {
|
|
673
|
-
|
|
565
|
+
_iterator4.f();
|
|
674
566
|
}
|
|
675
567
|
queue = _nextQueue;
|
|
676
568
|
}
|
|
@@ -734,7 +626,6 @@ function set(readComputed, writable$, context, mutation) {
|
|
|
734
626
|
function createMutation(context, _get, _set) {
|
|
735
627
|
var mutation = {
|
|
736
628
|
potentialDirtyIds: new Set(),
|
|
737
|
-
pendingListeners: new Set(),
|
|
738
629
|
visitor: {
|
|
739
630
|
get: function get(signal$) {
|
|
740
631
|
return _get(signal$, context, mutation);
|
|
@@ -781,11 +672,10 @@ function mountComputedDependencies(readSignal, computed$, computedState, context
|
|
|
781
672
|
}
|
|
782
673
|
}
|
|
783
674
|
function initMount(readSignal, signal$, context, mutation) {
|
|
784
|
-
var _context$interceptor, _context$interceptor
|
|
675
|
+
var _context$interceptor, _context$interceptor$;
|
|
785
676
|
(_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$);
|
|
786
677
|
var signalState = readSignal(signal$, context, mutation);
|
|
787
|
-
signalState.mounted =
|
|
788
|
-
listeners: new Set(),
|
|
678
|
+
signalState.mounted = {
|
|
789
679
|
readDepts: new Set()
|
|
790
680
|
};
|
|
791
681
|
if (isComputedState(signalState)) {
|
|
@@ -811,52 +701,11 @@ function doUnmount(signal$, signalState, context, mutation) {
|
|
|
811
701
|
}
|
|
812
702
|
function unmount(signal$, context, mutation) {
|
|
813
703
|
var signalState = context.stateMap.get(signal$);
|
|
814
|
-
if (!(signalState !== null && signalState !== void 0 && signalState.mounted) || signalState.mounted.
|
|
704
|
+
if (!(signalState !== null && signalState !== void 0 && signalState.mounted) || signalState.mounted.readDepts.size) {
|
|
815
705
|
return;
|
|
816
706
|
}
|
|
817
707
|
doUnmount(signal$, signalState, context);
|
|
818
708
|
}
|
|
819
|
-
function subSingleSignal(readSignal, signal$, callback$, context, signal) {
|
|
820
|
-
var _context$interceptor5;
|
|
821
|
-
withSubInterceptor(function () {
|
|
822
|
-
var mounted = mount$1(readSignal, signal$, context);
|
|
823
|
-
mounted.listeners.add(callback$);
|
|
824
|
-
var unsub = function unsub() {
|
|
825
|
-
var _context$interceptor4;
|
|
826
|
-
withUnsubInterceptor(function () {
|
|
827
|
-
mounted.listeners["delete"](callback$);
|
|
828
|
-
if (mounted.readDepts.size === 0 && mounted.listeners.size === 0) {
|
|
829
|
-
unmount(signal$, context);
|
|
830
|
-
}
|
|
831
|
-
}, signal$, callback$, (_context$interceptor4 = context.interceptor) === null || _context$interceptor4 === void 0 ? void 0 : _context$interceptor4.unsub);
|
|
832
|
-
};
|
|
833
|
-
signal.addEventListener('abort', unsub, {
|
|
834
|
-
once: true
|
|
835
|
-
});
|
|
836
|
-
}, signal$, callback$, (_context$interceptor5 = context.interceptor) === null || _context$interceptor5 === void 0 ? void 0 : _context$interceptor5.sub);
|
|
837
|
-
}
|
|
838
|
-
function notify(context, mutation) {
|
|
839
|
-
var pendingListeners = mutation.pendingListeners;
|
|
840
|
-
mutation.pendingListeners = new Set();
|
|
841
|
-
var _iterator = _createForOfIteratorHelper(pendingListeners),
|
|
842
|
-
_step;
|
|
843
|
-
try {
|
|
844
|
-
var _loop = function _loop() {
|
|
845
|
-
var _context$interceptor6;
|
|
846
|
-
var listener = _step.value;
|
|
847
|
-
withNotifyInterceptor(function () {
|
|
848
|
-
return listener.write(mutation.visitor);
|
|
849
|
-
}, listener, (_context$interceptor6 = context.interceptor) === null || _context$interceptor6 === void 0 ? void 0 : _context$interceptor6.notify);
|
|
850
|
-
};
|
|
851
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
852
|
-
_loop();
|
|
853
|
-
}
|
|
854
|
-
} catch (err) {
|
|
855
|
-
_iterator.e(err);
|
|
856
|
-
} finally {
|
|
857
|
-
_iterator.f();
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
709
|
|
|
861
710
|
var _readComputed = function readComputed(computed$, context, mutation) {
|
|
862
711
|
var _context$interceptor;
|
|
@@ -877,26 +726,7 @@ function readSignal(signal$, context, mutation) {
|
|
|
877
726
|
function mount(signal$, context, mutation) {
|
|
878
727
|
return mount$1(readSignal, signal$, context, mutation);
|
|
879
728
|
}
|
|
880
|
-
function
|
|
881
|
-
if (Array.isArray(signals$) && signals$.length === 0) {
|
|
882
|
-
return function () {
|
|
883
|
-
return void 0;
|
|
884
|
-
};
|
|
885
|
-
}
|
|
886
|
-
var controller = new AbortController();
|
|
887
|
-
var signal = options !== null && options !== void 0 && options.signal ? AbortSignal.any([controller.signal, options.signal]) : controller.signal;
|
|
888
|
-
if (!Array.isArray(signals$)) {
|
|
889
|
-
subSingleSignal(readSignal, signals$, callback$, context, signal);
|
|
890
|
-
} else {
|
|
891
|
-
signals$.forEach(function (atom) {
|
|
892
|
-
subSingleSignal(readSignal, atom, callback$, context, signal);
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
return function () {
|
|
896
|
-
controller.abort();
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
var get = function get(signal, context, mutation) {
|
|
729
|
+
var storeGet = function storeGet(signal, context, mutation) {
|
|
900
730
|
var _context$interceptor2;
|
|
901
731
|
return withGetInterceptor(function () {
|
|
902
732
|
var signalState = readSignal(signal, context, mutation);
|
|
@@ -906,60 +736,66 @@ var get = function get(signal, context, mutation) {
|
|
|
906
736
|
return signalState.val;
|
|
907
737
|
}, signal, (_context$interceptor2 = context.interceptor) === null || _context$interceptor2 === void 0 ? void 0 : _context$interceptor2.get);
|
|
908
738
|
};
|
|
909
|
-
var
|
|
739
|
+
var _storeSet = function storeSet(atom, context) {
|
|
910
740
|
var _context$interceptor3;
|
|
911
741
|
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
912
742
|
args[_key - 2] = arguments[_key];
|
|
913
743
|
}
|
|
914
744
|
return withSetInterceptor.apply(void 0, [function () {
|
|
915
|
-
var mutation = createMutation(context,
|
|
916
|
-
|
|
917
|
-
try {
|
|
918
|
-
ret = set.apply(void 0, [_readComputed, atom, context, mutation].concat(args));
|
|
919
|
-
} finally {
|
|
920
|
-
notify(context, mutation);
|
|
921
|
-
}
|
|
922
|
-
return ret;
|
|
745
|
+
var mutation = createMutation(context, storeGet, _storeSet);
|
|
746
|
+
return set.apply(void 0, [_readComputed, atom, context, mutation].concat(args));
|
|
923
747
|
}, atom, (_context$interceptor3 = context.interceptor) === null || _context$interceptor3 === void 0 ? void 0 : _context$interceptor3.set].concat(args));
|
|
924
748
|
};
|
|
925
|
-
var
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
args[_key2 - 1] = arguments[_key2];
|
|
749
|
+
var storeWatch = function storeWatch(watchFn, context, options) {
|
|
750
|
+
var _options$signal;
|
|
751
|
+
var computed$ = computed(function (get, _ref) {
|
|
752
|
+
var signal = _ref.signal;
|
|
753
|
+
var childSignal;
|
|
754
|
+
var obOptions = {
|
|
755
|
+
get signal() {
|
|
756
|
+
if (!childSignal) {
|
|
757
|
+
childSignal = options !== null && options !== void 0 && options.signal ? AbortSignal.any([options.signal, signal]) : signal;
|
|
758
|
+
}
|
|
759
|
+
return childSignal;
|
|
937
760
|
}
|
|
938
|
-
return _set.apply(void 0, [atom, _this.context].concat(args));
|
|
939
|
-
});
|
|
940
|
-
this.options = options;
|
|
941
|
-
this.context = {
|
|
942
|
-
stateMap: this.stateMap,
|
|
943
|
-
interceptor: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.interceptor
|
|
944
761
|
};
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
762
|
+
watchFn(get, obOptions);
|
|
763
|
+
}, {
|
|
764
|
+
debugLabel: options === null || options === void 0 ? void 0 : options.debugLabel
|
|
765
|
+
});
|
|
766
|
+
mount$1(readSignal, computed$, context);
|
|
767
|
+
options === null || options === void 0 || (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener('abort', function () {
|
|
768
|
+
unmount(computed$, context);
|
|
769
|
+
}, {
|
|
770
|
+
once: true
|
|
771
|
+
});
|
|
772
|
+
};
|
|
773
|
+
var StoreImpl = /*#__PURE__*/_createClass(function StoreImpl(_options) {
|
|
774
|
+
var _this = this,
|
|
775
|
+
_this$options;
|
|
776
|
+
_classCallCheck(this, StoreImpl);
|
|
777
|
+
_defineProperty(this, "stateMap", new WeakMap());
|
|
778
|
+
_defineProperty(this, "get", function (atom) {
|
|
779
|
+
return storeGet(atom, _this.context);
|
|
780
|
+
});
|
|
781
|
+
_defineProperty(this, "set", function (atom) {
|
|
782
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
783
|
+
args[_key2 - 1] = arguments[_key2];
|
|
950
784
|
}
|
|
951
|
-
|
|
952
|
-
}
|
|
785
|
+
return _storeSet.apply(void 0, [atom, _this.context].concat(args));
|
|
786
|
+
});
|
|
787
|
+
_defineProperty(this, "watch", function (watchFn, options) {
|
|
788
|
+
storeWatch(watchFn, _this.context, options);
|
|
789
|
+
});
|
|
790
|
+
this.options = _options;
|
|
791
|
+
this.context = {
|
|
792
|
+
stateMap: this.stateMap,
|
|
793
|
+
interceptor: (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.interceptor
|
|
794
|
+
};
|
|
795
|
+
});
|
|
953
796
|
function createStore() {
|
|
954
797
|
return new StoreImpl();
|
|
955
798
|
}
|
|
956
|
-
var defaultStore = undefined;
|
|
957
|
-
function getDefaultStore() {
|
|
958
|
-
if (!defaultStore) {
|
|
959
|
-
defaultStore = createStore();
|
|
960
|
-
}
|
|
961
|
-
return defaultStore;
|
|
962
|
-
}
|
|
963
799
|
|
|
964
800
|
var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
965
801
|
function DebugStoreImpl() {
|
|
@@ -969,34 +805,6 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
969
805
|
args[_key] = arguments[_key];
|
|
970
806
|
}
|
|
971
807
|
_this = _callSuper(this, DebugStoreImpl, [].concat(args));
|
|
972
|
-
_defineProperty(_this, "mountedAtomListenersCount", new Map());
|
|
973
|
-
_defineProperty(_this, "sub", function (atoms, cb, options) {
|
|
974
|
-
var _options$signal;
|
|
975
|
-
var atomList = Array.isArray(atoms) ? atoms : [atoms];
|
|
976
|
-
atomList.forEach(function (atom) {
|
|
977
|
-
var _this$mountedAtomList;
|
|
978
|
-
_this.mountedAtomListenersCount.set(atom, ((_this$mountedAtomList = _this.mountedAtomListenersCount.get(atom)) !== null && _this$mountedAtomList !== void 0 ? _this$mountedAtomList : 0) + 1);
|
|
979
|
-
});
|
|
980
|
-
var unsub = _superPropGet((DebugStoreImpl), "sub", _this)([atoms, cb, options]);
|
|
981
|
-
var decount = function decount() {
|
|
982
|
-
atomList.forEach(function (atom) {
|
|
983
|
-
var _this$mountedAtomList2;
|
|
984
|
-
var count = (_this$mountedAtomList2 = _this.mountedAtomListenersCount.get(atom)) !== null && _this$mountedAtomList2 !== void 0 ? _this$mountedAtomList2 : 0;
|
|
985
|
-
if (count === 0) {
|
|
986
|
-
return;
|
|
987
|
-
}
|
|
988
|
-
_this.mountedAtomListenersCount.set(atom, count - 1);
|
|
989
|
-
if (count === 1) {
|
|
990
|
-
_this.mountedAtomListenersCount["delete"](atom);
|
|
991
|
-
}
|
|
992
|
-
});
|
|
993
|
-
};
|
|
994
|
-
options === null || options === void 0 || (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener('abort', decount);
|
|
995
|
-
return function () {
|
|
996
|
-
unsub();
|
|
997
|
-
decount();
|
|
998
|
-
};
|
|
999
|
-
});
|
|
1000
808
|
_defineProperty(_this, "getReadDependencies", function (atom) {
|
|
1001
809
|
var atomState = _this.context.stateMap.get(atom);
|
|
1002
810
|
if (!atomState) {
|
|
@@ -1021,15 +829,6 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1021
829
|
return _this.getReadDependents(key);
|
|
1022
830
|
})));
|
|
1023
831
|
});
|
|
1024
|
-
_defineProperty(_this, "getSubscribeGraph", function () {
|
|
1025
|
-
var subscribedAtoms = Array.from(_this.mountedAtomListenersCount.keys());
|
|
1026
|
-
return subscribedAtoms.map(function (atom) {
|
|
1027
|
-
var atomState = _this.context.stateMap.get(atom);
|
|
1028
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1029
|
-
var listeners = Array.from(atomState.mounted.listeners);
|
|
1030
|
-
return [atom].concat(listeners);
|
|
1031
|
-
});
|
|
1032
|
-
});
|
|
1033
832
|
_defineProperty(_this, "isMounted", function (atom) {
|
|
1034
833
|
var mountState = _this.stateMap.get(atom);
|
|
1035
834
|
return (mountState === null || mountState === void 0 ? void 0 : mountState.mounted) !== undefined;
|
|
@@ -1131,24 +930,6 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1131
930
|
console.log('ret:', fn());
|
|
1132
931
|
console.groupEnd();
|
|
1133
932
|
});
|
|
1134
|
-
_defineProperty(this, "sub", function (atom$, callback$, fn) {
|
|
1135
|
-
if (!_this.shouldLog(atom$, 'sub')) {
|
|
1136
|
-
fn();
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
console.group('[R][SUB] ' + atom$.toString() + ', callback=' + callback$.toString());
|
|
1140
|
-
fn();
|
|
1141
|
-
console.groupEnd();
|
|
1142
|
-
});
|
|
1143
|
-
_defineProperty(this, "unsub", function (atom$, callback$, fn) {
|
|
1144
|
-
if (!_this.shouldLog(atom$, 'unsub')) {
|
|
1145
|
-
fn();
|
|
1146
|
-
return;
|
|
1147
|
-
}
|
|
1148
|
-
console.group('[R][UNS] ' + atom$.toString() + ', callback=' + callback$.toString());
|
|
1149
|
-
fn();
|
|
1150
|
-
console.groupEnd();
|
|
1151
|
-
});
|
|
1152
933
|
_defineProperty(this, "mount", function (atom$) {
|
|
1153
934
|
if (!_this.shouldLog(atom$, 'mount')) {
|
|
1154
935
|
return;
|
|
@@ -1161,15 +942,6 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1161
942
|
}
|
|
1162
943
|
console.log('[R][UNM] ' + atom$.toString());
|
|
1163
944
|
});
|
|
1164
|
-
_defineProperty(this, "notify", function (callback$, fn) {
|
|
1165
|
-
if (!_this.shouldLog(callback$, 'notify')) {
|
|
1166
|
-
fn();
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
console.group('[R][NTF] ' + callback$.toString());
|
|
1170
|
-
console.log('ret:', fn());
|
|
1171
|
-
console.groupEnd();
|
|
1172
|
-
});
|
|
1173
945
|
this.watches = watches;
|
|
1174
946
|
});
|
|
1175
947
|
function createDebugStore() {
|
|
@@ -1199,6 +971,5 @@ exports.command = command;
|
|
|
1199
971
|
exports.computed = computed;
|
|
1200
972
|
exports.createDebugStore = createDebugStore;
|
|
1201
973
|
exports.createStore = createStore;
|
|
1202
|
-
exports.getDefaultStore = getDefaultStore;
|
|
1203
974
|
exports.state = state;
|
|
1204
975
|
//# sourceMappingURL=index.cjs.map
|