ccstate 2.0.0 → 2.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 +405 -201
- package/debug/index.cjs +29 -4
- package/debug/index.d.cts +2 -1
- package/debug/index.d.ts +2 -1
- package/debug/index.js +29 -5
- package/index.cjs +39 -36
- package/index.d.cts +2 -1
- package/index.d.ts +2 -1
- package/index.js +39 -37
- package/package.json +7 -2
- package/react/index.cjs +10 -32
- package/react/index.js +10 -32
- package/vue/index.cjs +71 -0
- package/vue/index.d.cts +53 -0
- package/vue/index.d.ts +53 -0
- package/vue/index.js +66 -0
package/debug/index.cjs
CHANGED
|
@@ -1175,13 +1175,18 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1175
1175
|
_classCallCheck(this, ConsoleInterceptor);
|
|
1176
1176
|
_defineProperty(this, "shouldLog", function (atom, action) {
|
|
1177
1177
|
return _this.watches.some(function (watch) {
|
|
1178
|
+
var atomMatched = false;
|
|
1178
1179
|
if (typeof watch.target === 'string') {
|
|
1179
|
-
|
|
1180
|
+
atomMatched = atom.toString().includes(watch.target);
|
|
1181
|
+
} else if (watch.target instanceof RegExp) {
|
|
1182
|
+
atomMatched = watch.target.test(atom.toString());
|
|
1183
|
+
} else {
|
|
1184
|
+
atomMatched = watch.target === atom;
|
|
1180
1185
|
}
|
|
1181
|
-
if (
|
|
1182
|
-
return
|
|
1186
|
+
if (!atomMatched) {
|
|
1187
|
+
return false;
|
|
1183
1188
|
}
|
|
1184
|
-
return
|
|
1189
|
+
return !watch.actions || watch.actions.has(action);
|
|
1185
1190
|
});
|
|
1186
1191
|
});
|
|
1187
1192
|
_defineProperty(this, "get", function (atom$, fn) {
|
|
@@ -1256,6 +1261,25 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1256
1261
|
});
|
|
1257
1262
|
this.watches = watches;
|
|
1258
1263
|
});
|
|
1264
|
+
function createConsoleDebugStore(watches, defaultActions) {
|
|
1265
|
+
var parsedWatches = watches.map(function (watch) {
|
|
1266
|
+
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1267
|
+
return {
|
|
1268
|
+
target: watch,
|
|
1269
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
if ('target' in watch) {
|
|
1273
|
+
return watch;
|
|
1274
|
+
}
|
|
1275
|
+
return {
|
|
1276
|
+
target: watch,
|
|
1277
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1278
|
+
};
|
|
1279
|
+
});
|
|
1280
|
+
var interceptor = new ConsoleInterceptor(parsedWatches);
|
|
1281
|
+
return createDebugStore(interceptor);
|
|
1282
|
+
}
|
|
1259
1283
|
|
|
1260
1284
|
var StoreEvent = /*#__PURE__*/function (_Event) {
|
|
1261
1285
|
function StoreEvent(type, eventId, targetAtom, state, time, args, result) {
|
|
@@ -1422,6 +1446,7 @@ exports.ConsoleInterceptor = ConsoleInterceptor;
|
|
|
1422
1446
|
exports.EventInterceptor = EventInterceptor;
|
|
1423
1447
|
exports.GLOBAL_CCSTATE_INTERCEPED_KEY = GLOBAL_CCSTATE_INTERCEPED_KEY;
|
|
1424
1448
|
exports.StoreEvent = StoreEvent;
|
|
1449
|
+
exports.createConsoleDebugStore = createConsoleDebugStore;
|
|
1425
1450
|
exports.createDebugStore = createDebugStore;
|
|
1426
1451
|
exports.nestedAtomToString = nestedAtomToString;
|
|
1427
1452
|
exports.setupDevtoolsInterceptor = setupDevtoolsInterceptor;
|
package/debug/index.d.cts
CHANGED
|
@@ -94,6 +94,7 @@ declare class ConsoleInterceptor implements StoreInterceptor {
|
|
|
94
94
|
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
95
95
|
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
96
96
|
}
|
|
97
|
+
declare function createConsoleDebugStore(watches: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
97
98
|
|
|
98
99
|
declare class StoreEvent extends Event {
|
|
99
100
|
readonly eventId: number;
|
|
@@ -130,4 +131,4 @@ interface DevToolsHookMessage {
|
|
|
130
131
|
declare const GLOBAL_CCSTATE_INTERCEPED_KEY = "__CCSTATE_INTERCEPED__";
|
|
131
132
|
declare function setupDevtoolsInterceptor(targetWindow: Window, signal?: AbortSignal): EventInterceptor;
|
|
132
133
|
|
|
133
|
-
export { ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type PackedEventMessage, StoreEvent, type StoreEventType, type StoreInterceptor, createDebugStore, nestedAtomToString, setupDevtoolsInterceptor };
|
|
134
|
+
export { ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type PackedEventMessage, StoreEvent, type StoreEventType, type StoreInterceptor, createConsoleDebugStore, createDebugStore, nestedAtomToString, setupDevtoolsInterceptor };
|
package/debug/index.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ declare class ConsoleInterceptor implements StoreInterceptor {
|
|
|
94
94
|
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
95
95
|
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
96
96
|
}
|
|
97
|
+
declare function createConsoleDebugStore(watches: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
97
98
|
|
|
98
99
|
declare class StoreEvent extends Event {
|
|
99
100
|
readonly eventId: number;
|
|
@@ -130,4 +131,4 @@ interface DevToolsHookMessage {
|
|
|
130
131
|
declare const GLOBAL_CCSTATE_INTERCEPED_KEY = "__CCSTATE_INTERCEPED__";
|
|
131
132
|
declare function setupDevtoolsInterceptor(targetWindow: Window, signal?: AbortSignal): EventInterceptor;
|
|
132
133
|
|
|
133
|
-
export { ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type PackedEventMessage, StoreEvent, type StoreEventType, type StoreInterceptor, createDebugStore, nestedAtomToString, setupDevtoolsInterceptor };
|
|
134
|
+
export { ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type PackedEventMessage, StoreEvent, type StoreEventType, type StoreInterceptor, createConsoleDebugStore, createDebugStore, nestedAtomToString, setupDevtoolsInterceptor };
|
package/debug/index.js
CHANGED
|
@@ -1173,13 +1173,18 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1173
1173
|
_classCallCheck(this, ConsoleInterceptor);
|
|
1174
1174
|
_defineProperty(this, "shouldLog", function (atom, action) {
|
|
1175
1175
|
return _this.watches.some(function (watch) {
|
|
1176
|
+
var atomMatched = false;
|
|
1176
1177
|
if (typeof watch.target === 'string') {
|
|
1177
|
-
|
|
1178
|
+
atomMatched = atom.toString().includes(watch.target);
|
|
1179
|
+
} else if (watch.target instanceof RegExp) {
|
|
1180
|
+
atomMatched = watch.target.test(atom.toString());
|
|
1181
|
+
} else {
|
|
1182
|
+
atomMatched = watch.target === atom;
|
|
1178
1183
|
}
|
|
1179
|
-
if (
|
|
1180
|
-
return
|
|
1184
|
+
if (!atomMatched) {
|
|
1185
|
+
return false;
|
|
1181
1186
|
}
|
|
1182
|
-
return
|
|
1187
|
+
return !watch.actions || watch.actions.has(action);
|
|
1183
1188
|
});
|
|
1184
1189
|
});
|
|
1185
1190
|
_defineProperty(this, "get", function (atom$, fn) {
|
|
@@ -1254,6 +1259,25 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1254
1259
|
});
|
|
1255
1260
|
this.watches = watches;
|
|
1256
1261
|
});
|
|
1262
|
+
function createConsoleDebugStore(watches, defaultActions) {
|
|
1263
|
+
var parsedWatches = watches.map(function (watch) {
|
|
1264
|
+
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1265
|
+
return {
|
|
1266
|
+
target: watch,
|
|
1267
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
if ('target' in watch) {
|
|
1271
|
+
return watch;
|
|
1272
|
+
}
|
|
1273
|
+
return {
|
|
1274
|
+
target: watch,
|
|
1275
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1276
|
+
};
|
|
1277
|
+
});
|
|
1278
|
+
var interceptor = new ConsoleInterceptor(parsedWatches);
|
|
1279
|
+
return createDebugStore(interceptor);
|
|
1280
|
+
}
|
|
1257
1281
|
|
|
1258
1282
|
var StoreEvent = /*#__PURE__*/function (_Event) {
|
|
1259
1283
|
function StoreEvent(type, eventId, targetAtom, state, time, args, result) {
|
|
@@ -1416,4 +1440,4 @@ function setupDevtoolsInterceptor(targetWindow, signal) {
|
|
|
1416
1440
|
return interceptor;
|
|
1417
1441
|
}
|
|
1418
1442
|
|
|
1419
|
-
export { ConsoleInterceptor, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, StoreEvent, createDebugStore, nestedAtomToString, setupDevtoolsInterceptor };
|
|
1443
|
+
export { ConsoleInterceptor, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, StoreEvent, createConsoleDebugStore, createDebugStore, nestedAtomToString, setupDevtoolsInterceptor };
|
package/index.cjs
CHANGED
|
@@ -1221,13 +1221,18 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1221
1221
|
_classCallCheck(this, ConsoleInterceptor);
|
|
1222
1222
|
_defineProperty(this, "shouldLog", function (atom, action) {
|
|
1223
1223
|
return _this.watches.some(function (watch) {
|
|
1224
|
+
var atomMatched = false;
|
|
1224
1225
|
if (typeof watch.target === 'string') {
|
|
1225
|
-
|
|
1226
|
+
atomMatched = atom.toString().includes(watch.target);
|
|
1227
|
+
} else if (watch.target instanceof RegExp) {
|
|
1228
|
+
atomMatched = watch.target.test(atom.toString());
|
|
1229
|
+
} else {
|
|
1230
|
+
atomMatched = watch.target === atom;
|
|
1226
1231
|
}
|
|
1227
|
-
if (
|
|
1228
|
-
return
|
|
1232
|
+
if (!atomMatched) {
|
|
1233
|
+
return false;
|
|
1229
1234
|
}
|
|
1230
|
-
return
|
|
1235
|
+
return !watch.actions || watch.actions.has(action);
|
|
1231
1236
|
});
|
|
1232
1237
|
});
|
|
1233
1238
|
_defineProperty(this, "get", function (atom$, fn) {
|
|
@@ -1302,6 +1307,25 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1302
1307
|
});
|
|
1303
1308
|
this.watches = watches;
|
|
1304
1309
|
});
|
|
1310
|
+
function createConsoleDebugStore(watches, defaultActions) {
|
|
1311
|
+
var parsedWatches = watches.map(function (watch) {
|
|
1312
|
+
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1313
|
+
return {
|
|
1314
|
+
target: watch,
|
|
1315
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
if ('target' in watch) {
|
|
1319
|
+
return watch;
|
|
1320
|
+
}
|
|
1321
|
+
return {
|
|
1322
|
+
target: watch,
|
|
1323
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1324
|
+
};
|
|
1325
|
+
});
|
|
1326
|
+
var interceptor = new ConsoleInterceptor(parsedWatches);
|
|
1327
|
+
return createDebugStore(interceptor);
|
|
1328
|
+
}
|
|
1305
1329
|
|
|
1306
1330
|
var StoreEvent = /*#__PURE__*/function (_Event) {
|
|
1307
1331
|
function StoreEvent(type, eventId, targetAtom, state, time, args, result) {
|
|
@@ -1505,7 +1529,7 @@ function useSet(atom) {
|
|
|
1505
1529
|
};
|
|
1506
1530
|
}
|
|
1507
1531
|
|
|
1508
|
-
function
|
|
1532
|
+
function useLoadableInternal(atom, keepLastResolved) {
|
|
1509
1533
|
var promise = useGet(atom);
|
|
1510
1534
|
var _useState = react.useState({
|
|
1511
1535
|
state: 'loading'
|
|
@@ -1516,39 +1540,11 @@ function useLoadable(atom) {
|
|
|
1516
1540
|
react.useEffect(function () {
|
|
1517
1541
|
var ctrl = new AbortController();
|
|
1518
1542
|
var signal = ctrl.signal;
|
|
1519
|
-
|
|
1520
|
-
state: 'loading'
|
|
1521
|
-
});
|
|
1522
|
-
void promise.then(function (ret) {
|
|
1523
|
-
if (signal.aborted) return;
|
|
1543
|
+
if (!keepLastResolved) {
|
|
1524
1544
|
setPromiseResult({
|
|
1525
|
-
state: '
|
|
1526
|
-
data: ret
|
|
1545
|
+
state: 'loading'
|
|
1527
1546
|
});
|
|
1528
|
-
}
|
|
1529
|
-
if (signal.aborted) return;
|
|
1530
|
-
setPromiseResult({
|
|
1531
|
-
state: 'hasError',
|
|
1532
|
-
error: error
|
|
1533
|
-
});
|
|
1534
|
-
});
|
|
1535
|
-
return function () {
|
|
1536
|
-
ctrl.abort();
|
|
1537
|
-
};
|
|
1538
|
-
}, [promise]);
|
|
1539
|
-
return promiseResult;
|
|
1540
|
-
}
|
|
1541
|
-
function useLastLoadable(atom) {
|
|
1542
|
-
var promise = useGet(atom);
|
|
1543
|
-
var _useState3 = react.useState({
|
|
1544
|
-
state: 'loading'
|
|
1545
|
-
}),
|
|
1546
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
1547
|
-
promiseResult = _useState4[0],
|
|
1548
|
-
setPromiseResult = _useState4[1];
|
|
1549
|
-
react.useEffect(function () {
|
|
1550
|
-
var ctrl = new AbortController();
|
|
1551
|
-
var signal = ctrl.signal;
|
|
1547
|
+
}
|
|
1552
1548
|
void promise.then(function (ret) {
|
|
1553
1549
|
if (signal.aborted) return;
|
|
1554
1550
|
setPromiseResult({
|
|
@@ -1568,6 +1564,12 @@ function useLastLoadable(atom) {
|
|
|
1568
1564
|
}, [promise]);
|
|
1569
1565
|
return promiseResult;
|
|
1570
1566
|
}
|
|
1567
|
+
function useLoadable(atom) {
|
|
1568
|
+
return useLoadableInternal(atom, false);
|
|
1569
|
+
}
|
|
1570
|
+
function useLastLoadable(atom) {
|
|
1571
|
+
return useLoadableInternal(atom, true);
|
|
1572
|
+
}
|
|
1571
1573
|
|
|
1572
1574
|
function useResolved(atom) {
|
|
1573
1575
|
var loadable = useLoadable(atom);
|
|
@@ -1585,6 +1587,7 @@ exports.StoreEvent = StoreEvent;
|
|
|
1585
1587
|
exports.StoreProvider = StoreProvider;
|
|
1586
1588
|
exports.command = command;
|
|
1587
1589
|
exports.computed = computed;
|
|
1590
|
+
exports.createConsoleDebugStore = createConsoleDebugStore;
|
|
1588
1591
|
exports.createDebugStore = createDebugStore;
|
|
1589
1592
|
exports.createStore = createStore;
|
|
1590
1593
|
exports.nestedAtomToString = nestedAtomToString;
|
package/index.d.cts
CHANGED
|
@@ -105,6 +105,7 @@ declare class ConsoleInterceptor implements StoreInterceptor {
|
|
|
105
105
|
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
106
106
|
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
107
107
|
}
|
|
108
|
+
declare function createConsoleDebugStore(watches: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
108
109
|
|
|
109
110
|
declare class StoreEvent extends Event {
|
|
110
111
|
readonly eventId: number;
|
|
@@ -163,4 +164,4 @@ declare function useLastLoadable<T>(atom: State<Promise<T>> | Computed<Promise<T
|
|
|
163
164
|
|
|
164
165
|
declare const StoreProvider: react.Provider<Store | null>;
|
|
165
166
|
|
|
166
|
-
export { type Command, type Computed, ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type Getter, type PackedEventMessage, type Read, type Setter, type State, type Store, StoreEvent, type StoreEventType, type StoreInterceptor, StoreProvider, type Subscribe, type Updater, type Write, command, computed, createDebugStore, createStore, nestedAtomToString, setupDevtoolsInterceptor, state, useGet, useLastLoadable, useLastResolved, useLoadable, useResolved, useSet };
|
|
167
|
+
export { type Command, type Computed, ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type Getter, type PackedEventMessage, type Read, type Setter, type State, type Store, StoreEvent, type StoreEventType, type StoreInterceptor, StoreProvider, type Subscribe, type Updater, type Write, command, computed, createConsoleDebugStore, createDebugStore, createStore, nestedAtomToString, setupDevtoolsInterceptor, state, useGet, useLastLoadable, useLastResolved, useLoadable, useResolved, useSet };
|
package/index.d.ts
CHANGED
|
@@ -105,6 +105,7 @@ declare class ConsoleInterceptor implements StoreInterceptor {
|
|
|
105
105
|
unmount: <T>(atom$: State<T> | Computed<T>) => void;
|
|
106
106
|
notify: <T>(callback$: CallbackFunc<T>, fn: () => T) => void;
|
|
107
107
|
}
|
|
108
|
+
declare function createConsoleDebugStore(watches: (AtomWatch | string | RegExp | State<unknown> | Computed<unknown> | Command<unknown, unknown[]>)[], defaultActions?: StoreEventType[]): DebugStore;
|
|
108
109
|
|
|
109
110
|
declare class StoreEvent extends Event {
|
|
110
111
|
readonly eventId: number;
|
|
@@ -163,4 +164,4 @@ declare function useLastLoadable<T>(atom: State<Promise<T>> | Computed<Promise<T
|
|
|
163
164
|
|
|
164
165
|
declare const StoreProvider: react.Provider<Store | null>;
|
|
165
166
|
|
|
166
|
-
export { type Command, type Computed, ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type Getter, type PackedEventMessage, type Read, type Setter, type State, type Store, StoreEvent, type StoreEventType, type StoreInterceptor, StoreProvider, type Subscribe, type Updater, type Write, command, computed, createDebugStore, createStore, nestedAtomToString, setupDevtoolsInterceptor, state, useGet, useLastLoadable, useLastResolved, useLoadable, useResolved, useSet };
|
|
167
|
+
export { type Command, type Computed, ConsoleInterceptor, type DebugStore, type DevToolsHookMessage, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, type Getter, type PackedEventMessage, type Read, type Setter, type State, type Store, StoreEvent, type StoreEventType, type StoreInterceptor, StoreProvider, type Subscribe, type Updater, type Write, command, computed, createConsoleDebugStore, createDebugStore, createStore, nestedAtomToString, setupDevtoolsInterceptor, state, useGet, useLastLoadable, useLastResolved, useLoadable, useResolved, useSet };
|
package/index.js
CHANGED
|
@@ -1219,13 +1219,18 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1219
1219
|
_classCallCheck(this, ConsoleInterceptor);
|
|
1220
1220
|
_defineProperty(this, "shouldLog", function (atom, action) {
|
|
1221
1221
|
return _this.watches.some(function (watch) {
|
|
1222
|
+
var atomMatched = false;
|
|
1222
1223
|
if (typeof watch.target === 'string') {
|
|
1223
|
-
|
|
1224
|
+
atomMatched = atom.toString().includes(watch.target);
|
|
1225
|
+
} else if (watch.target instanceof RegExp) {
|
|
1226
|
+
atomMatched = watch.target.test(atom.toString());
|
|
1227
|
+
} else {
|
|
1228
|
+
atomMatched = watch.target === atom;
|
|
1224
1229
|
}
|
|
1225
|
-
if (
|
|
1226
|
-
return
|
|
1230
|
+
if (!atomMatched) {
|
|
1231
|
+
return false;
|
|
1227
1232
|
}
|
|
1228
|
-
return
|
|
1233
|
+
return !watch.actions || watch.actions.has(action);
|
|
1229
1234
|
});
|
|
1230
1235
|
});
|
|
1231
1236
|
_defineProperty(this, "get", function (atom$, fn) {
|
|
@@ -1300,6 +1305,25 @@ var ConsoleInterceptor = /*#__PURE__*/_createClass(function ConsoleInterceptor(w
|
|
|
1300
1305
|
});
|
|
1301
1306
|
this.watches = watches;
|
|
1302
1307
|
});
|
|
1308
|
+
function createConsoleDebugStore(watches, defaultActions) {
|
|
1309
|
+
var parsedWatches = watches.map(function (watch) {
|
|
1310
|
+
if (typeof watch === 'string' || watch instanceof RegExp) {
|
|
1311
|
+
return {
|
|
1312
|
+
target: watch,
|
|
1313
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
if ('target' in watch) {
|
|
1317
|
+
return watch;
|
|
1318
|
+
}
|
|
1319
|
+
return {
|
|
1320
|
+
target: watch,
|
|
1321
|
+
actions: defaultActions ? new Set(defaultActions) : undefined
|
|
1322
|
+
};
|
|
1323
|
+
});
|
|
1324
|
+
var interceptor = new ConsoleInterceptor(parsedWatches);
|
|
1325
|
+
return createDebugStore(interceptor);
|
|
1326
|
+
}
|
|
1303
1327
|
|
|
1304
1328
|
var StoreEvent = /*#__PURE__*/function (_Event) {
|
|
1305
1329
|
function StoreEvent(type, eventId, targetAtom, state, time, args, result) {
|
|
@@ -1503,7 +1527,7 @@ function useSet(atom) {
|
|
|
1503
1527
|
};
|
|
1504
1528
|
}
|
|
1505
1529
|
|
|
1506
|
-
function
|
|
1530
|
+
function useLoadableInternal(atom, keepLastResolved) {
|
|
1507
1531
|
var promise = useGet(atom);
|
|
1508
1532
|
var _useState = useState({
|
|
1509
1533
|
state: 'loading'
|
|
@@ -1514,39 +1538,11 @@ function useLoadable(atom) {
|
|
|
1514
1538
|
useEffect(function () {
|
|
1515
1539
|
var ctrl = new AbortController();
|
|
1516
1540
|
var signal = ctrl.signal;
|
|
1517
|
-
|
|
1518
|
-
state: 'loading'
|
|
1519
|
-
});
|
|
1520
|
-
void promise.then(function (ret) {
|
|
1521
|
-
if (signal.aborted) return;
|
|
1541
|
+
if (!keepLastResolved) {
|
|
1522
1542
|
setPromiseResult({
|
|
1523
|
-
state: '
|
|
1524
|
-
data: ret
|
|
1543
|
+
state: 'loading'
|
|
1525
1544
|
});
|
|
1526
|
-
}
|
|
1527
|
-
if (signal.aborted) return;
|
|
1528
|
-
setPromiseResult({
|
|
1529
|
-
state: 'hasError',
|
|
1530
|
-
error: error
|
|
1531
|
-
});
|
|
1532
|
-
});
|
|
1533
|
-
return function () {
|
|
1534
|
-
ctrl.abort();
|
|
1535
|
-
};
|
|
1536
|
-
}, [promise]);
|
|
1537
|
-
return promiseResult;
|
|
1538
|
-
}
|
|
1539
|
-
function useLastLoadable(atom) {
|
|
1540
|
-
var promise = useGet(atom);
|
|
1541
|
-
var _useState3 = useState({
|
|
1542
|
-
state: 'loading'
|
|
1543
|
-
}),
|
|
1544
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
1545
|
-
promiseResult = _useState4[0],
|
|
1546
|
-
setPromiseResult = _useState4[1];
|
|
1547
|
-
useEffect(function () {
|
|
1548
|
-
var ctrl = new AbortController();
|
|
1549
|
-
var signal = ctrl.signal;
|
|
1545
|
+
}
|
|
1550
1546
|
void promise.then(function (ret) {
|
|
1551
1547
|
if (signal.aborted) return;
|
|
1552
1548
|
setPromiseResult({
|
|
@@ -1566,6 +1562,12 @@ function useLastLoadable(atom) {
|
|
|
1566
1562
|
}, [promise]);
|
|
1567
1563
|
return promiseResult;
|
|
1568
1564
|
}
|
|
1565
|
+
function useLoadable(atom) {
|
|
1566
|
+
return useLoadableInternal(atom, false);
|
|
1567
|
+
}
|
|
1568
|
+
function useLastLoadable(atom) {
|
|
1569
|
+
return useLoadableInternal(atom, true);
|
|
1570
|
+
}
|
|
1569
1571
|
|
|
1570
1572
|
function useResolved(atom) {
|
|
1571
1573
|
var loadable = useLoadable(atom);
|
|
@@ -1576,4 +1578,4 @@ function useLastResolved(atom) {
|
|
|
1576
1578
|
return loadable.state === 'hasData' ? loadable.data : undefined;
|
|
1577
1579
|
}
|
|
1578
1580
|
|
|
1579
|
-
export { ConsoleInterceptor, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, StoreEvent, StoreProvider, command, computed, createDebugStore, createStore, nestedAtomToString, setupDevtoolsInterceptor, state, useGet, useLastLoadable, useLastResolved, useLoadable, useResolved, useSet };
|
|
1581
|
+
export { ConsoleInterceptor, EventInterceptor, GLOBAL_CCSTATE_INTERCEPED_KEY, StoreEvent, StoreProvider, command, computed, createConsoleDebugStore, createDebugStore, createStore, nestedAtomToString, setupDevtoolsInterceptor, state, useGet, useLastLoadable, useLastResolved, useLoadable, useResolved, useSet };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccstate",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "CCState Core",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"type": "module",
|
|
12
12
|
"main": "./index.cjs",
|
|
13
|
+
"module": "./index.js",
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
15
16
|
"import": "./index.js",
|
|
@@ -22,7 +23,8 @@
|
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
24
25
|
"@types/react": ">=17.0.0",
|
|
25
|
-
"react": ">=17.0.0"
|
|
26
|
+
"react": ">=17.0.0",
|
|
27
|
+
"vue": ">=3.2.0"
|
|
26
28
|
},
|
|
27
29
|
"peerDependenciesMeta": {
|
|
28
30
|
"@types/react": {
|
|
@@ -30,6 +32,9 @@
|
|
|
30
32
|
},
|
|
31
33
|
"react": {
|
|
32
34
|
"optional": true
|
|
35
|
+
},
|
|
36
|
+
"vue": {
|
|
37
|
+
"optional": true
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
}
|
package/react/index.cjs
CHANGED
|
@@ -105,7 +105,7 @@ function useSet(atom) {
|
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
function
|
|
108
|
+
function useLoadableInternal(atom, keepLastResolved) {
|
|
109
109
|
var promise = useGet(atom);
|
|
110
110
|
var _useState = react.useState({
|
|
111
111
|
state: 'loading'
|
|
@@ -116,39 +116,11 @@ function useLoadable(atom) {
|
|
|
116
116
|
react.useEffect(function () {
|
|
117
117
|
var ctrl = new AbortController();
|
|
118
118
|
var signal = ctrl.signal;
|
|
119
|
-
|
|
120
|
-
state: 'loading'
|
|
121
|
-
});
|
|
122
|
-
void promise.then(function (ret) {
|
|
123
|
-
if (signal.aborted) return;
|
|
124
|
-
setPromiseResult({
|
|
125
|
-
state: 'hasData',
|
|
126
|
-
data: ret
|
|
127
|
-
});
|
|
128
|
-
})["catch"](function (error) {
|
|
129
|
-
if (signal.aborted) return;
|
|
119
|
+
if (!keepLastResolved) {
|
|
130
120
|
setPromiseResult({
|
|
131
|
-
state: '
|
|
132
|
-
error: error
|
|
121
|
+
state: 'loading'
|
|
133
122
|
});
|
|
134
|
-
}
|
|
135
|
-
return function () {
|
|
136
|
-
ctrl.abort();
|
|
137
|
-
};
|
|
138
|
-
}, [promise]);
|
|
139
|
-
return promiseResult;
|
|
140
|
-
}
|
|
141
|
-
function useLastLoadable(atom) {
|
|
142
|
-
var promise = useGet(atom);
|
|
143
|
-
var _useState3 = react.useState({
|
|
144
|
-
state: 'loading'
|
|
145
|
-
}),
|
|
146
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
147
|
-
promiseResult = _useState4[0],
|
|
148
|
-
setPromiseResult = _useState4[1];
|
|
149
|
-
react.useEffect(function () {
|
|
150
|
-
var ctrl = new AbortController();
|
|
151
|
-
var signal = ctrl.signal;
|
|
123
|
+
}
|
|
152
124
|
void promise.then(function (ret) {
|
|
153
125
|
if (signal.aborted) return;
|
|
154
126
|
setPromiseResult({
|
|
@@ -168,6 +140,12 @@ function useLastLoadable(atom) {
|
|
|
168
140
|
}, [promise]);
|
|
169
141
|
return promiseResult;
|
|
170
142
|
}
|
|
143
|
+
function useLoadable(atom) {
|
|
144
|
+
return useLoadableInternal(atom, false);
|
|
145
|
+
}
|
|
146
|
+
function useLastLoadable(atom) {
|
|
147
|
+
return useLoadableInternal(atom, true);
|
|
148
|
+
}
|
|
171
149
|
|
|
172
150
|
function useResolved(atom) {
|
|
173
151
|
var loadable = useLoadable(atom);
|
package/react/index.js
CHANGED
|
@@ -103,7 +103,7 @@ function useSet(atom) {
|
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function
|
|
106
|
+
function useLoadableInternal(atom, keepLastResolved) {
|
|
107
107
|
var promise = useGet(atom);
|
|
108
108
|
var _useState = useState({
|
|
109
109
|
state: 'loading'
|
|
@@ -114,39 +114,11 @@ function useLoadable(atom) {
|
|
|
114
114
|
useEffect(function () {
|
|
115
115
|
var ctrl = new AbortController();
|
|
116
116
|
var signal = ctrl.signal;
|
|
117
|
-
|
|
118
|
-
state: 'loading'
|
|
119
|
-
});
|
|
120
|
-
void promise.then(function (ret) {
|
|
121
|
-
if (signal.aborted) return;
|
|
122
|
-
setPromiseResult({
|
|
123
|
-
state: 'hasData',
|
|
124
|
-
data: ret
|
|
125
|
-
});
|
|
126
|
-
})["catch"](function (error) {
|
|
127
|
-
if (signal.aborted) return;
|
|
117
|
+
if (!keepLastResolved) {
|
|
128
118
|
setPromiseResult({
|
|
129
|
-
state: '
|
|
130
|
-
error: error
|
|
119
|
+
state: 'loading'
|
|
131
120
|
});
|
|
132
|
-
}
|
|
133
|
-
return function () {
|
|
134
|
-
ctrl.abort();
|
|
135
|
-
};
|
|
136
|
-
}, [promise]);
|
|
137
|
-
return promiseResult;
|
|
138
|
-
}
|
|
139
|
-
function useLastLoadable(atom) {
|
|
140
|
-
var promise = useGet(atom);
|
|
141
|
-
var _useState3 = useState({
|
|
142
|
-
state: 'loading'
|
|
143
|
-
}),
|
|
144
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
145
|
-
promiseResult = _useState4[0],
|
|
146
|
-
setPromiseResult = _useState4[1];
|
|
147
|
-
useEffect(function () {
|
|
148
|
-
var ctrl = new AbortController();
|
|
149
|
-
var signal = ctrl.signal;
|
|
121
|
+
}
|
|
150
122
|
void promise.then(function (ret) {
|
|
151
123
|
if (signal.aborted) return;
|
|
152
124
|
setPromiseResult({
|
|
@@ -166,6 +138,12 @@ function useLastLoadable(atom) {
|
|
|
166
138
|
}, [promise]);
|
|
167
139
|
return promiseResult;
|
|
168
140
|
}
|
|
141
|
+
function useLoadable(atom) {
|
|
142
|
+
return useLoadableInternal(atom, false);
|
|
143
|
+
}
|
|
144
|
+
function useLastLoadable(atom) {
|
|
145
|
+
return useLoadableInternal(atom, true);
|
|
146
|
+
}
|
|
169
147
|
|
|
170
148
|
function useResolved(atom) {
|
|
171
149
|
var loadable = useLoadable(atom);
|
package/vue/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vue = require('vue');
|
|
4
|
+
|
|
5
|
+
var StoreKey = Symbol('ccstate-vue-store');
|
|
6
|
+
var provideStore = function provideStore(store) {
|
|
7
|
+
vue.provide(StoreKey, store);
|
|
8
|
+
};
|
|
9
|
+
var useStore = function useStore() {
|
|
10
|
+
var store = vue.inject(StoreKey);
|
|
11
|
+
if (store === undefined) {
|
|
12
|
+
throw new Error('Store context not found - did you forget to wrap your app with StoreProvider?');
|
|
13
|
+
}
|
|
14
|
+
return store;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var globalId = 0;
|
|
18
|
+
var generateToString = function generateToString(prefix, debugLabel) {
|
|
19
|
+
var id = globalId++;
|
|
20
|
+
var label = "".concat(prefix).concat(String(id)).concat('');
|
|
21
|
+
return function () {
|
|
22
|
+
return label;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
function command(write, options) {
|
|
26
|
+
var ret = {
|
|
27
|
+
write: write,
|
|
28
|
+
toString: generateToString('F')
|
|
29
|
+
};
|
|
30
|
+
return ret;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function useGet(atom) {
|
|
34
|
+
var store = useStore();
|
|
35
|
+
var initialValue = store.get(atom);
|
|
36
|
+
var vueState = vue.shallowRef(initialValue);
|
|
37
|
+
var controller = new AbortController();
|
|
38
|
+
store.sub(atom, command(function () {
|
|
39
|
+
var nextValue = store.get(atom);
|
|
40
|
+
vueState.value = nextValue;
|
|
41
|
+
}), {
|
|
42
|
+
signal: controller.signal
|
|
43
|
+
});
|
|
44
|
+
if (vue.getCurrentInstance()) {
|
|
45
|
+
vue.onScopeDispose(function () {
|
|
46
|
+
controller.abort();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return vue.shallowReadonly(vueState);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function useSet(atom) {
|
|
53
|
+
var store = useStore();
|
|
54
|
+
if ('write' in atom) {
|
|
55
|
+
return function () {
|
|
56
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
57
|
+
args[_key] = arguments[_key];
|
|
58
|
+
}
|
|
59
|
+
var ret = store.set.apply(store, [atom].concat(args));
|
|
60
|
+
return ret;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return function (value) {
|
|
64
|
+
store.set(atom, value);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
exports.provideStore = provideStore;
|
|
69
|
+
exports.useGet = useGet;
|
|
70
|
+
exports.useSet = useSet;
|
|
71
|
+
exports.useStore = useStore;
|