ccstate 2.2.0 → 3.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 +9 -11
- package/debug/index.cjs +5 -226
- package/debug/index.d.cts +4 -80
- package/debug/index.d.ts +4 -80
- package/debug/index.js +6 -220
- package/index.cjs +5 -327
- package/index.d.cts +3 -103
- package/index.d.ts +3 -103
- package/index.js +6 -314
- package/package.json +1 -17
- package/react/index.cjs +0 -165
- package/react/index.d.cts +0 -67
- package/react/index.d.ts +0 -67
- package/react/index.js +0 -157
- package/vue/index.cjs +0 -71
- package/vue/index.d.cts +0 -53
- package/vue/index.d.ts +0 -53
- package/vue/index.js +0 -66
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ Use `useGet` and `useSet` hooks in React to get/set data, and use `useResolved`
|
|
|
62
62
|
|
|
63
63
|
```jsx
|
|
64
64
|
// App.js
|
|
65
|
-
import { useGet, useSet, useResolved } from 'ccstate';
|
|
65
|
+
import { useGet, useSet, useResolved } from 'ccstate-react';
|
|
66
66
|
import { userId$, user$ } from './data';
|
|
67
67
|
|
|
68
68
|
export default function App() {
|
|
@@ -91,8 +91,8 @@ Use `createStore` and `StoreProvider` to provide a CCState store to React, all s
|
|
|
91
91
|
|
|
92
92
|
```tsx
|
|
93
93
|
// main.jsx
|
|
94
|
-
import { createStore
|
|
95
|
-
import {
|
|
94
|
+
import { createStore } from 'ccstate';
|
|
95
|
+
import { StoreProvider } from 'ccstate-react';
|
|
96
96
|
import { createRoot } from 'react-dom/client';
|
|
97
97
|
|
|
98
98
|
import App from './App';
|
|
@@ -102,11 +102,9 @@ const root = createRoot(rootElement);
|
|
|
102
102
|
|
|
103
103
|
const store = createStore();
|
|
104
104
|
root.render(
|
|
105
|
-
<
|
|
106
|
-
<
|
|
107
|
-
|
|
108
|
-
</StoreProvider>
|
|
109
|
-
</StrictMode>,
|
|
105
|
+
<StoreProvider value={store}>
|
|
106
|
+
<App />
|
|
107
|
+
</StoreProvider>,
|
|
110
108
|
);
|
|
111
109
|
```
|
|
112
110
|
|
|
@@ -314,12 +312,12 @@ Here are some tips to help you better debug during testing.
|
|
|
314
312
|
Use `ConsoleInterceptor` to log most store behaviors to the console during testing:
|
|
315
313
|
|
|
316
314
|
```typescript
|
|
317
|
-
import {
|
|
315
|
+
import { createDebugStore, state, computed, command } from 'ccstate';
|
|
318
316
|
|
|
319
317
|
const base$ = state(1, { debugLabel: 'base$' });
|
|
320
318
|
const derived$ = computed((get) => get(base$) * 2);
|
|
321
319
|
|
|
322
|
-
const store =
|
|
320
|
+
const store = createDebugStore([base$, 'derived'], ['set', 'sub']); // log sub & set actions
|
|
323
321
|
store.set(base$, 1); // console: SET [V0:base$] 1
|
|
324
322
|
store.sub(
|
|
325
323
|
derived$,
|
|
@@ -728,7 +726,7 @@ Click show to make double enter the display state, and you can see the `set` `sh
|
|
|
728
726
|
ret: – 14
|
|
729
727
|
```
|
|
730
728
|
|
|
731
|
-
The abbreviation `CPT` represents `Computed` evaluation, not just a simple read operation. You can also try modifying the parameters of `
|
|
729
|
+
The abbreviation `CPT` represents `Computed` evaluation, not just a simple read operation. You can also try modifying the parameters of `createDebugStore` in the code to include `get` in the logs, and you'll find that not every `get` triggers a `Computed` evaluation.
|
|
732
730
|
|
|
733
731
|
Click increment to see the `set` trigger the `Computed` evaluation.
|
|
734
732
|
|
package/debug/index.cjs
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function nestedAtomToString(atoms) {
|
|
4
|
-
return atoms.map(function (atom) {
|
|
5
|
-
var _atom$debugLabel;
|
|
6
|
-
if (Array.isArray(atom)) {
|
|
7
|
-
return nestedAtomToString(atom);
|
|
8
|
-
}
|
|
9
|
-
return (_atom$debugLabel = atom.debugLabel) !== null && _atom$debugLabel !== void 0 ? _atom$debugLabel : 'anonymous';
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
3
|
function _arrayLikeToArray(r, a) {
|
|
14
4
|
(null == a || a > r.length) && (a = r.length);
|
|
15
5
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
@@ -31,13 +21,6 @@ function _callSuper(t, o, e) {
|
|
|
31
21
|
function _classCallCheck(a, n) {
|
|
32
22
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
33
23
|
}
|
|
34
|
-
function _construct(t, e, r) {
|
|
35
|
-
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
36
|
-
var o = [null];
|
|
37
|
-
o.push.apply(o, e);
|
|
38
|
-
var p = new (t.bind.apply(t, o))();
|
|
39
|
-
return r && _setPrototypeOf(p, r.prototype), p;
|
|
40
|
-
}
|
|
41
24
|
function _defineProperties(e, r) {
|
|
42
25
|
for (var t = 0; t < r.length; t++) {
|
|
43
26
|
var o = r[t];
|
|
@@ -131,13 +114,6 @@ function _inherits(t, e) {
|
|
|
131
114
|
writable: !1
|
|
132
115
|
}), e && _setPrototypeOf(t, e);
|
|
133
116
|
}
|
|
134
|
-
function _isNativeFunction(t) {
|
|
135
|
-
try {
|
|
136
|
-
return -1 !== Function.toString.call(t).indexOf("[native code]");
|
|
137
|
-
} catch (n) {
|
|
138
|
-
return "function" == typeof t;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
117
|
function _isNativeReflectConstruct() {
|
|
142
118
|
try {
|
|
143
119
|
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
@@ -523,15 +499,6 @@ function _toPropertyKey(t) {
|
|
|
523
499
|
var i = _toPrimitive(t, "string");
|
|
524
500
|
return "symbol" == typeof i ? i : i + "";
|
|
525
501
|
}
|
|
526
|
-
function _typeof(o) {
|
|
527
|
-
"@babel/helpers - typeof";
|
|
528
|
-
|
|
529
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
530
|
-
return typeof o;
|
|
531
|
-
} : function (o) {
|
|
532
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
533
|
-
}, _typeof(o);
|
|
534
|
-
}
|
|
535
502
|
function _unsupportedIterableToArray(r, a) {
|
|
536
503
|
if (r) {
|
|
537
504
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -539,28 +506,6 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
539
506
|
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
540
507
|
}
|
|
541
508
|
}
|
|
542
|
-
function _wrapNativeSuper(t) {
|
|
543
|
-
var r = "function" == typeof Map ? new Map() : void 0;
|
|
544
|
-
return _wrapNativeSuper = function (t) {
|
|
545
|
-
if (null === t || !_isNativeFunction(t)) return t;
|
|
546
|
-
if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
|
|
547
|
-
if (void 0 !== r) {
|
|
548
|
-
if (r.has(t)) return r.get(t);
|
|
549
|
-
r.set(t, Wrapper);
|
|
550
|
-
}
|
|
551
|
-
function Wrapper() {
|
|
552
|
-
return _construct(t, arguments, _getPrototypeOf(this).constructor);
|
|
553
|
-
}
|
|
554
|
-
return Wrapper.prototype = Object.create(t.prototype, {
|
|
555
|
-
constructor: {
|
|
556
|
-
value: Wrapper,
|
|
557
|
-
enumerable: !1,
|
|
558
|
-
writable: !0,
|
|
559
|
-
configurable: !0
|
|
560
|
-
}
|
|
561
|
-
}), _setPrototypeOf(Wrapper, t);
|
|
562
|
-
}, _wrapNativeSuper(t);
|
|
563
|
-
}
|
|
564
509
|
|
|
565
510
|
function canReadAsCompute(atom) {
|
|
566
511
|
return 'read' in atom;
|
|
@@ -1160,7 +1105,7 @@ var DebugStoreImpl = /*#__PURE__*/function (_StoreImpl) {
|
|
|
1160
1105
|
_inherits(DebugStoreImpl, _StoreImpl);
|
|
1161
1106
|
return _createClass(DebugStoreImpl);
|
|
1162
1107
|
}(StoreImpl);
|
|
1163
|
-
function
|
|
1108
|
+
function createDebugStoreInternal(interceptor) {
|
|
1164
1109
|
var atomManager = new AtomManager({
|
|
1165
1110
|
interceptor: interceptor
|
|
1166
1111
|
});
|
|
@@ -1261,7 +1206,9 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1261
1206
|
});
|
|
1262
1207
|
this.watches = watches;
|
|
1263
1208
|
});
|
|
1264
|
-
function
|
|
1209
|
+
function createDebugStore() {
|
|
1210
|
+
var watches = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1211
|
+
var defaultActions = arguments.length > 1 ? arguments[1] : undefined;
|
|
1265
1212
|
var parsedWatches = watches.map(function (watch) {
|
|
1266
1213
|
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1267
1214
|
return {
|
|
@@ -1278,175 +1225,7 @@ function createConsoleDebugStore(watches, defaultActions) {
|
|
|
1278
1225
|
};
|
|
1279
1226
|
});
|
|
1280
1227
|
var interceptor = new ConsoleInterceptor(parsedWatches);
|
|
1281
|
-
return
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
var StoreEvent = /*#__PURE__*/function (_Event) {
|
|
1285
|
-
function StoreEvent(type, eventId, targetAtom, state, time, args, result) {
|
|
1286
|
-
var _this;
|
|
1287
|
-
_classCallCheck(this, StoreEvent);
|
|
1288
|
-
_this = _callSuper(this, StoreEvent, [type]);
|
|
1289
|
-
_this.eventId = eventId;
|
|
1290
|
-
_this.targetAtom = targetAtom;
|
|
1291
|
-
_this.state = state;
|
|
1292
|
-
_this.time = time;
|
|
1293
|
-
_this.args = args;
|
|
1294
|
-
_this.result = result;
|
|
1295
|
-
return _this;
|
|
1296
|
-
}
|
|
1297
|
-
_inherits(StoreEvent, _Event);
|
|
1298
|
-
return _createClass(StoreEvent);
|
|
1299
|
-
}(/*#__PURE__*/_wrapNativeSuper(Event));
|
|
1300
|
-
|
|
1301
|
-
var EventInterceptor = /*#__PURE__*/function () {
|
|
1302
|
-
function EventInterceptor() {
|
|
1303
|
-
var _this = this;
|
|
1304
|
-
_classCallCheck(this, EventInterceptor);
|
|
1305
|
-
_defineProperty(this, "traceId", 0);
|
|
1306
|
-
_defineProperty(this, "events", new EventTarget());
|
|
1307
|
-
_defineProperty(this, "get", function (atom$, fn) {
|
|
1308
|
-
return _this.wrapWithTrace(fn, function (eventId, time) {
|
|
1309
|
-
_this.createEvent('get', eventId, atom$.toString(), time, 'begin', [], undefined);
|
|
1310
|
-
}, function (eventId, time, result) {
|
|
1311
|
-
_this.createEvent('get', eventId, atom$.toString(), time, 'success', [], result);
|
|
1312
|
-
}, function (eventId, time, error) {
|
|
1313
|
-
_this.createEvent('get', eventId, atom$.toString(), time, 'error', [], error);
|
|
1314
|
-
});
|
|
1315
|
-
});
|
|
1316
|
-
_defineProperty(this, "computed", function (atom$, fn) {
|
|
1317
|
-
return _this.wrapWithTrace(fn, function (eventId, time) {
|
|
1318
|
-
_this.createEvent('computed', eventId, atom$.toString(), time, 'begin', [], undefined);
|
|
1319
|
-
}, function (eventId, time, result) {
|
|
1320
|
-
_this.createEvent('computed', eventId, atom$.toString(), time, 'success', [], result);
|
|
1321
|
-
}, function (eventId, time, error) {
|
|
1322
|
-
_this.createEvent('computed', eventId, atom$.toString(), time, 'error', [], error);
|
|
1323
|
-
});
|
|
1324
|
-
});
|
|
1325
|
-
_defineProperty(this, "set", function (atom$, fn) {
|
|
1326
|
-
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
1327
|
-
args[_key - 2] = arguments[_key];
|
|
1328
|
-
}
|
|
1329
|
-
return _this.wrapWithTrace(fn, function (eventId, time) {
|
|
1330
|
-
_this.createEvent('set', eventId, atom$.toString(), time, 'begin', args, undefined);
|
|
1331
|
-
}, function (eventId, time, result) {
|
|
1332
|
-
_this.createEvent('set', eventId, atom$.toString(), time, 'success', args, result);
|
|
1333
|
-
}, function (eventId, time, error) {
|
|
1334
|
-
_this.createEvent('set', eventId, atom$.toString(), time, 'error', args, error);
|
|
1335
|
-
});
|
|
1336
|
-
});
|
|
1337
|
-
_defineProperty(this, "sub", function (atom$, callback$, fn) {
|
|
1338
|
-
var eventId = _this.traceId++;
|
|
1339
|
-
_this.createEvent('sub', eventId, atom$.toString(), performance.now(), 'begin', [callback$.toString()], undefined);
|
|
1340
|
-
fn();
|
|
1341
|
-
_this.createEvent('sub', eventId, atom$.toString(), performance.now(), 'success', [callback$.toString()], undefined);
|
|
1342
|
-
});
|
|
1343
|
-
_defineProperty(this, "unsub", function (atom$, callback$, fn) {
|
|
1344
|
-
var eventId = _this.traceId++;
|
|
1345
|
-
_this.createEvent('unsub', eventId, atom$.toString(), performance.now(), 'begin', [callback$.toString()], undefined);
|
|
1346
|
-
fn();
|
|
1347
|
-
_this.createEvent('unsub', eventId, atom$.toString(), performance.now(), 'success', [callback$.toString()], undefined);
|
|
1348
|
-
});
|
|
1349
|
-
_defineProperty(this, "mount", function (atom$) {
|
|
1350
|
-
var eventId = _this.traceId++;
|
|
1351
|
-
_this.createEvent('mount', eventId, atom$.toString(), performance.now(), 'begin', [], undefined);
|
|
1352
|
-
});
|
|
1353
|
-
_defineProperty(this, "unmount", function (atom$) {
|
|
1354
|
-
var eventId = _this.traceId++;
|
|
1355
|
-
_this.createEvent('unmount', eventId, atom$.toString(), performance.now(), 'begin', [], undefined);
|
|
1356
|
-
});
|
|
1357
|
-
_defineProperty(this, "notify", function (callback$, fn) {
|
|
1358
|
-
var eventId = _this.traceId++;
|
|
1359
|
-
_this.createEvent('notify', eventId, callback$.toString(), performance.now(), 'begin', [], undefined);
|
|
1360
|
-
var ret = fn();
|
|
1361
|
-
_this.createEvent('notify', eventId, callback$.toString(), performance.now(), 'success', [], ret);
|
|
1362
|
-
});
|
|
1363
|
-
}
|
|
1364
|
-
return _createClass(EventInterceptor, [{
|
|
1365
|
-
key: "createEvent",
|
|
1366
|
-
value: function createEvent(type, eventId, atom, time, state, args, result) {
|
|
1367
|
-
var event = new StoreEvent(type, eventId, atom, state, time, args, result);
|
|
1368
|
-
this.events.dispatchEvent(event);
|
|
1369
|
-
return event;
|
|
1370
|
-
}
|
|
1371
|
-
}, {
|
|
1372
|
-
key: "wrapWithTrace",
|
|
1373
|
-
value: function wrapWithTrace(fn, createBeginEvent, createSuccessEvent, createErrorEvent) {
|
|
1374
|
-
var eventId = this.traceId++;
|
|
1375
|
-
createBeginEvent(eventId, performance.now());
|
|
1376
|
-
try {
|
|
1377
|
-
var result = fn();
|
|
1378
|
-
createSuccessEvent(eventId, performance.now(), result);
|
|
1379
|
-
return result;
|
|
1380
|
-
} catch (e) {
|
|
1381
|
-
createErrorEvent(eventId, performance.now(), e);
|
|
1382
|
-
throw e;
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
}, {
|
|
1386
|
-
key: "addEventListener",
|
|
1387
|
-
value: function addEventListener(type, listener, options) {
|
|
1388
|
-
this.events.addEventListener(type, listener, options);
|
|
1389
|
-
}
|
|
1390
|
-
}, {
|
|
1391
|
-
key: "removeEventListener",
|
|
1392
|
-
value: function removeEventListener(type, listener, options) {
|
|
1393
|
-
this.events.removeEventListener(type, listener, options);
|
|
1394
|
-
}
|
|
1395
|
-
}]);
|
|
1396
|
-
}();
|
|
1397
|
-
|
|
1398
|
-
var GLOBAL_CCSTATE_INTERCEPED_KEY = '__CCSTATE_INTERCEPED__';
|
|
1399
|
-
function setupDevtoolsInterceptor(targetWindow, signal) {
|
|
1400
|
-
var interceptor = new EventInterceptor();
|
|
1401
|
-
var watchedAtoms = new Set();
|
|
1402
|
-
targetWindow.addEventListener('message', function (_ref) {
|
|
1403
|
-
var data = _ref.data;
|
|
1404
|
-
if (!data || _typeof(data) !== 'object' || !('source' in data) || data.source !== 'ccstate-devtools') {
|
|
1405
|
-
return;
|
|
1406
|
-
}
|
|
1407
|
-
var payload = data.payload;
|
|
1408
|
-
watchedAtoms.add(payload.args[0]);
|
|
1409
|
-
}, {
|
|
1410
|
-
signal: signal
|
|
1411
|
-
});
|
|
1412
|
-
function handleStoreEvent(event) {
|
|
1413
|
-
var debugLabel = event.targetAtom.substring(event.targetAtom.indexOf(':') + 1);
|
|
1414
|
-
if (watchedAtoms.has(debugLabel)) {
|
|
1415
|
-
console.group("[CCState] ".concat(event.type, " ").concat(event.targetAtom, " ").concat(event.state));
|
|
1416
|
-
console.log('args', event.args);
|
|
1417
|
-
console.log('result', event.result);
|
|
1418
|
-
console.groupEnd();
|
|
1419
|
-
}
|
|
1420
|
-
var message = {
|
|
1421
|
-
source: 'ccstate-store',
|
|
1422
|
-
payload: {
|
|
1423
|
-
type: event.type,
|
|
1424
|
-
eventId: event.eventId,
|
|
1425
|
-
targetAtom: event.targetAtom,
|
|
1426
|
-
time: event.time,
|
|
1427
|
-
state: event.state
|
|
1428
|
-
}
|
|
1429
|
-
};
|
|
1430
|
-
targetWindow.postMessage(message);
|
|
1431
|
-
}
|
|
1432
|
-
interceptor.addEventListener('get', handleStoreEvent);
|
|
1433
|
-
interceptor.addEventListener('computed', handleStoreEvent);
|
|
1434
|
-
interceptor.addEventListener('set', handleStoreEvent);
|
|
1435
|
-
interceptor.addEventListener('sub', handleStoreEvent);
|
|
1436
|
-
interceptor.addEventListener('unsub', handleStoreEvent);
|
|
1437
|
-
interceptor.addEventListener('mount', handleStoreEvent);
|
|
1438
|
-
interceptor.addEventListener('unmount', handleStoreEvent);
|
|
1439
|
-
interceptor.addEventListener('notify', handleStoreEvent);
|
|
1440
|
-
targetWindow[GLOBAL_CCSTATE_INTERCEPED_KEY] = true;
|
|
1441
|
-
console.warn('[CCSTATE] Interceptor injected, DO NOT USE THIS IN PRODUCTION');
|
|
1442
|
-
return interceptor;
|
|
1228
|
+
return createDebugStoreInternal(interceptor);
|
|
1443
1229
|
}
|
|
1444
1230
|
|
|
1445
|
-
exports.ConsoleInterceptor = ConsoleInterceptor;
|
|
1446
|
-
exports.EventInterceptor = EventInterceptor;
|
|
1447
|
-
exports.GLOBAL_CCSTATE_INTERCEPED_KEY = GLOBAL_CCSTATE_INTERCEPED_KEY;
|
|
1448
|
-
exports.StoreEvent = StoreEvent;
|
|
1449
|
-
exports.createConsoleDebugStore = createConsoleDebugStore;
|
|
1450
1231
|
exports.createDebugStore = createDebugStore;
|
|
1451
|
-
exports.nestedAtomToString = nestedAtomToString;
|
|
1452
|
-
exports.setupDevtoolsInterceptor = setupDevtoolsInterceptor;
|
package/debug/index.d.cts
CHANGED
|
@@ -29,11 +29,6 @@ interface Command<T, Args extends unknown[]> {
|
|
|
29
29
|
}
|
|
30
30
|
type ReadableAtom<T> = State<T> | Computed<T>;
|
|
31
31
|
|
|
32
|
-
type NestedAtom = (State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | NestedAtom)[];
|
|
33
|
-
type NestedString = (string | NestedString)[];
|
|
34
|
-
|
|
35
|
-
declare function nestedAtomToString(atoms: NestedAtom): NestedString;
|
|
36
|
-
|
|
37
32
|
interface Store {
|
|
38
33
|
get: Getter;
|
|
39
34
|
set: Setter;
|
|
@@ -44,28 +39,9 @@ interface SubscribeOptions {
|
|
|
44
39
|
}
|
|
45
40
|
type CallbackFunc<T> = Command<T, []>;
|
|
46
41
|
type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callback: CallbackFunc<unknown>, options?: SubscribeOptions) => () => void;
|
|
47
|
-
type
|
|
48
|
-
interface InterceptorSet {
|
|
49
|
-
<T, Args extends unknown[]>(func$: Command<T, Args>, fn: () => T, ...args: Args): void;
|
|
50
|
-
<T>(value$: State<T>, fn: () => void, val: T | Updater<T>): void;
|
|
51
|
-
}
|
|
52
|
-
type InterceptorSub = <T>(atom$: ReadableAtom<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
53
|
-
type InterceptorUnsub = <T>(atom$: ReadableAtom<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
54
|
-
type InterceptorMount = <T>(atom$: ReadableAtom<T>) => void;
|
|
55
|
-
type InterceptorUnmount = <T>(atom$: ReadableAtom<T>) => void;
|
|
56
|
-
type InterceptorNotify = <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
57
|
-
type InterceptorComputed = <T>(atom$: Computed<T>, fn: () => T) => void;
|
|
58
|
-
interface StoreInterceptor {
|
|
59
|
-
get?: InterceptorGet;
|
|
60
|
-
set?: InterceptorSet;
|
|
61
|
-
sub?: InterceptorSub;
|
|
62
|
-
unsub?: InterceptorUnsub;
|
|
63
|
-
mount?: InterceptorMount;
|
|
64
|
-
unmount?: InterceptorUnmount;
|
|
65
|
-
notify?: InterceptorNotify;
|
|
66
|
-
computed?: InterceptorComputed;
|
|
67
|
-
}
|
|
42
|
+
type StoreEventType = 'set' | 'get' | 'sub' | 'unsub' | 'mount' | 'unmount' | 'notify' | 'computed';
|
|
68
43
|
|
|
44
|
+
type NestedAtom = (State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | NestedAtom)[];
|
|
69
45
|
interface DebugStore extends Store {
|
|
70
46
|
getReadDependencies: (atom: Computed<unknown>) => NestedAtom;
|
|
71
47
|
getReadDependents: (atom: State<unknown> | Computed<unknown>) => NestedAtom;
|
|
@@ -73,62 +49,10 @@ interface DebugStore extends Store {
|
|
|
73
49
|
getSubscribeGraph: () => NestedAtom;
|
|
74
50
|
}
|
|
75
51
|
|
|
76
|
-
declare function createDebugStore(interceptor?: StoreInterceptor): DebugStore;
|
|
77
|
-
|
|
78
|
-
type StoreEventType = 'set' | 'get' | 'sub' | 'unsub' | 'mount' | 'unmount' | 'notify' | 'computed';
|
|
79
|
-
|
|
80
52
|
interface AtomWatch {
|
|
81
53
|
target: State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | string | RegExp;
|
|
82
54
|
actions?: Set<StoreEventType>;
|
|
83
55
|
}
|
|
84
|
-
declare
|
|
85
|
-
private readonly watches;
|
|
86
|
-
constructor(watches: AtomWatch[]);
|
|
87
|
-
private shouldLog;
|
|
88
|
-
get: <T>(atom$: State<T> | Computed<T>, fn: () => T) => void;
|
|
89
|
-
computed: <T>(atom$: Computed<T>, fn: () => T) => void;
|
|
90
|
-
set: <T, Args extends unknown[]>(atom$: State<T> | Command<T, Args>, fn: () => T, ...args: Args | [T | Updater<T>]) => void;
|
|
91
|
-
sub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
92
|
-
unsub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
93
|
-
mount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
94
|
-
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
95
|
-
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
96
|
-
}
|
|
97
|
-
declare function createConsoleDebugStore(watches: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
98
|
-
|
|
99
|
-
declare class StoreEvent extends Event {
|
|
100
|
-
readonly eventId: number;
|
|
101
|
-
readonly targetAtom: string;
|
|
102
|
-
readonly state: 'begin' | 'success' | 'error';
|
|
103
|
-
readonly time: DOMHighResTimeStamp;
|
|
104
|
-
readonly args: unknown[];
|
|
105
|
-
readonly result: unknown;
|
|
106
|
-
constructor(type: StoreEventType, eventId: number, targetAtom: string, state: 'begin' | 'success' | 'error', time: DOMHighResTimeStamp, args: unknown[], result: unknown);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare class EventInterceptor implements StoreInterceptor {
|
|
110
|
-
private traceId;
|
|
111
|
-
private events;
|
|
112
|
-
private createEvent;
|
|
113
|
-
private wrapWithTrace;
|
|
114
|
-
addEventListener(type: StoreEventType, listener: (event: StoreEvent) => void, options?: AddEventListenerOptions | boolean): void;
|
|
115
|
-
removeEventListener(type: StoreEventType, listener: (event: StoreEvent) => void, options?: EventListenerOptions | boolean): void;
|
|
116
|
-
get: <T>(atom$: State<T> | Computed<T>, fn: () => T) => T;
|
|
117
|
-
computed: <T>(atom$: Computed<T>, fn: () => T) => T;
|
|
118
|
-
set: <T, Args extends unknown[]>(atom$: State<T> | Command<T, Args>, fn: () => T, ...args: Args | [T | Updater<T>]) => T;
|
|
119
|
-
sub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
120
|
-
unsub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
121
|
-
mount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
122
|
-
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
123
|
-
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
type PackedEventMessage = Pick<StoreEvent, 'type' | 'eventId' | 'targetAtom' | 'time' | 'state'>;
|
|
127
|
-
interface DevToolsHookMessage {
|
|
128
|
-
source: 'ccstate-store';
|
|
129
|
-
payload: PackedEventMessage;
|
|
130
|
-
}
|
|
131
|
-
declare const GLOBAL_CCSTATE_INTERCEPED_KEY = "__CCSTATE_INTERCEPED__";
|
|
132
|
-
declare function setupDevtoolsInterceptor(targetWindow: Window, signal?: AbortSignal): EventInterceptor;
|
|
56
|
+
declare function createDebugStore(watches?: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
133
57
|
|
|
134
|
-
export {
|
|
58
|
+
export { type DebugStore, createDebugStore };
|
package/debug/index.d.ts
CHANGED
|
@@ -29,11 +29,6 @@ interface Command<T, Args extends unknown[]> {
|
|
|
29
29
|
}
|
|
30
30
|
type ReadableAtom<T> = State<T> | Computed<T>;
|
|
31
31
|
|
|
32
|
-
type NestedAtom = (State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | NestedAtom)[];
|
|
33
|
-
type NestedString = (string | NestedString)[];
|
|
34
|
-
|
|
35
|
-
declare function nestedAtomToString(atoms: NestedAtom): NestedString;
|
|
36
|
-
|
|
37
32
|
interface Store {
|
|
38
33
|
get: Getter;
|
|
39
34
|
set: Setter;
|
|
@@ -44,28 +39,9 @@ interface SubscribeOptions {
|
|
|
44
39
|
}
|
|
45
40
|
type CallbackFunc<T> = Command<T, []>;
|
|
46
41
|
type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callback: CallbackFunc<unknown>, options?: SubscribeOptions) => () => void;
|
|
47
|
-
type
|
|
48
|
-
interface InterceptorSet {
|
|
49
|
-
<T, Args extends unknown[]>(func$: Command<T, Args>, fn: () => T, ...args: Args): void;
|
|
50
|
-
<T>(value$: State<T>, fn: () => void, val: T | Updater<T>): void;
|
|
51
|
-
}
|
|
52
|
-
type InterceptorSub = <T>(atom$: ReadableAtom<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
53
|
-
type InterceptorUnsub = <T>(atom$: ReadableAtom<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
54
|
-
type InterceptorMount = <T>(atom$: ReadableAtom<T>) => void;
|
|
55
|
-
type InterceptorUnmount = <T>(atom$: ReadableAtom<T>) => void;
|
|
56
|
-
type InterceptorNotify = <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
57
|
-
type InterceptorComputed = <T>(atom$: Computed<T>, fn: () => T) => void;
|
|
58
|
-
interface StoreInterceptor {
|
|
59
|
-
get?: InterceptorGet;
|
|
60
|
-
set?: InterceptorSet;
|
|
61
|
-
sub?: InterceptorSub;
|
|
62
|
-
unsub?: InterceptorUnsub;
|
|
63
|
-
mount?: InterceptorMount;
|
|
64
|
-
unmount?: InterceptorUnmount;
|
|
65
|
-
notify?: InterceptorNotify;
|
|
66
|
-
computed?: InterceptorComputed;
|
|
67
|
-
}
|
|
42
|
+
type StoreEventType = 'set' | 'get' | 'sub' | 'unsub' | 'mount' | 'unmount' | 'notify' | 'computed';
|
|
68
43
|
|
|
44
|
+
type NestedAtom = (State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | NestedAtom)[];
|
|
69
45
|
interface DebugStore extends Store {
|
|
70
46
|
getReadDependencies: (atom: Computed<unknown>) => NestedAtom;
|
|
71
47
|
getReadDependents: (atom: State<unknown> | Computed<unknown>) => NestedAtom;
|
|
@@ -73,62 +49,10 @@ interface DebugStore extends Store {
|
|
|
73
49
|
getSubscribeGraph: () => NestedAtom;
|
|
74
50
|
}
|
|
75
51
|
|
|
76
|
-
declare function createDebugStore(interceptor?: StoreInterceptor): DebugStore;
|
|
77
|
-
|
|
78
|
-
type StoreEventType = 'set' | 'get' | 'sub' | 'unsub' | 'mount' | 'unmount' | 'notify' | 'computed';
|
|
79
|
-
|
|
80
52
|
interface AtomWatch {
|
|
81
53
|
target: State<unknown> | Computed<unknown> | Command<unknown, unknown[]> | string | RegExp;
|
|
82
54
|
actions?: Set<StoreEventType>;
|
|
83
55
|
}
|
|
84
|
-
declare
|
|
85
|
-
private readonly watches;
|
|
86
|
-
constructor(watches: AtomWatch[]);
|
|
87
|
-
private shouldLog;
|
|
88
|
-
get: <T>(atom$: State<T> | Computed<T>, fn: () => T) => void;
|
|
89
|
-
computed: <T>(atom$: Computed<T>, fn: () => T) => void;
|
|
90
|
-
set: <T, Args extends unknown[]>(atom$: State<T> | Command<T, Args>, fn: () => T, ...args: Args | [T | Updater<T>]) => void;
|
|
91
|
-
sub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
92
|
-
unsub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
93
|
-
mount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
94
|
-
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
95
|
-
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
96
|
-
}
|
|
97
|
-
declare function createConsoleDebugStore(watches: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
98
|
-
|
|
99
|
-
declare class StoreEvent extends Event {
|
|
100
|
-
readonly eventId: number;
|
|
101
|
-
readonly targetAtom: string;
|
|
102
|
-
readonly state: 'begin' | 'success' | 'error';
|
|
103
|
-
readonly time: DOMHighResTimeStamp;
|
|
104
|
-
readonly args: unknown[];
|
|
105
|
-
readonly result: unknown;
|
|
106
|
-
constructor(type: StoreEventType, eventId: number, targetAtom: string, state: 'begin' | 'success' | 'error', time: DOMHighResTimeStamp, args: unknown[], result: unknown);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
declare class EventInterceptor implements StoreInterceptor {
|
|
110
|
-
private traceId;
|
|
111
|
-
private events;
|
|
112
|
-
private createEvent;
|
|
113
|
-
private wrapWithTrace;
|
|
114
|
-
addEventListener(type: StoreEventType, listener: (event: StoreEvent) => void, options?: AddEventListenerOptions | boolean): void;
|
|
115
|
-
removeEventListener(type: StoreEventType, listener: (event: StoreEvent) => void, options?: EventListenerOptions | boolean): void;
|
|
116
|
-
get: <T>(atom$: State<T> | Computed<T>, fn: () => T) => T;
|
|
117
|
-
computed: <T>(atom$: Computed<T>, fn: () => T) => T;
|
|
118
|
-
set: <T, Args extends unknown[]>(atom$: State<T> | Command<T, Args>, fn: () => T, ...args: Args | [T | Updater<T>]) => T;
|
|
119
|
-
sub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
120
|
-
unsub: <T>(atom$: State<T> | Computed<T>, callback$: CallbackFunc<T>, fn: () => void) => void;
|
|
121
|
-
mount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
122
|
-
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
123
|
-
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
type PackedEventMessage = Pick<StoreEvent, 'type' | 'eventId' | 'targetAtom' | 'time' | 'state'>;
|
|
127
|
-
interface DevToolsHookMessage {
|
|
128
|
-
source: 'ccstate-store';
|
|
129
|
-
payload: PackedEventMessage;
|
|
130
|
-
}
|
|
131
|
-
declare const GLOBAL_CCSTATE_INTERCEPED_KEY = "__CCSTATE_INTERCEPED__";
|
|
132
|
-
declare function setupDevtoolsInterceptor(targetWindow: Window, signal?: AbortSignal): EventInterceptor;
|
|
56
|
+
declare function createDebugStore(watches?: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
133
57
|
|
|
134
|
-
export {
|
|
58
|
+
export { type DebugStore, createDebugStore };
|