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